Skip to content

Commit

Permalink
Merge pull request #69 from RezkyRizaldi/v14
Browse files Browse the repository at this point in the history
V1.35.4
  • Loading branch information
RezkyRizaldi authored Nov 30, 2022
2 parents 878536e + 8fb4092 commit f9fe01f
Show file tree
Hide file tree
Showing 23 changed files with 2,241 additions and 3,165 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "borobot",
"version": "1.35.3",
"version": "1.35.4",
"description": "A simple Discord Bot build with Discord.js",
"displayName": "Borobot",
"bugs": {
Expand Down Expand Up @@ -85,4 +85,4 @@
"*.ts": "eslint --cache --fix",
"*.{ts,css,md}": "prettier --write"
}
}
}
73 changes: 17 additions & 56 deletions src/commands/misc/calc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
const {
bold,
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
inlineCode,
SlashCommandBuilder,
} = require('discord.js');
const { bold, inlineCode, SlashCommandBuilder } = require('discord.js');
const mexp = require('math-expression-evaluator');
const { Pagination } = require('pagination.djs');

const { math } = require('../../constants');
const { generateEmbed, generatePagination } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -38,76 +31,44 @@ module.exports = {
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
const { client, guild, options } = interaction;

/** @type {{ paginations: import('discord.js').Collection<String, import('pagination.djs').Pagination> }} */
const { paginations } = client;
const { options } = interaction;

await interaction.deferReply();

switch (options.getSubcommand()) {
case 'list': {
return {
list: async () => {
const symbols = Object.values(math);

const responses = symbols.map(
({ description, example, result, symbol }, index) =>
`${bold(`${index + 1}.`)} ${inlineCode(symbol)} ${description}${
({ description, example, result, symbol }, i) =>
`${bold(`${i + 1}.`)} ${inlineCode(symbol)} ${description}${
example ? ` ${inlineCode(`eg. ${example}`)}` : ''
}${result ? ` returns ${inlineCode(result)}` : ''}`,
);

const pagination = new Pagination(interaction, { limit: 10 })
.setColor(guild?.members.me?.displayHexColor ?? null)
.setTimestamp(Date.now())
.setFooter({
text: `${client.user.username} | Page {pageNumber} of {totalPages}`,
iconURL: client.user.displayAvatarURL({ dynamic: true }),
})
await generatePagination({ interaction, limit: 10 })
.setAuthor({
name: `➗ Supported Math Symbol Lists (${symbols.length.toLocaleString()})`,
})
.setDescriptions(responses);

pagination.buttons = {
...pagination.buttons,
extra: new ButtonBuilder()
.setCustomId('jump')
.setEmoji('↕️')
.setDisabled(false)
.setStyle(ButtonStyle.Secondary),
};

paginations.set(pagination.interaction.id, pagination);

return pagination.render();
}

case 'run': {
.setDescriptions(responses)
.render();
},
run: async () => {
const operation = options.getString('operation', true);

const embed = new EmbedBuilder()
.setColor(guild?.members.me?.displayHexColor ?? null)
.setTimestamp(Date.now())
.setFooter({
text: client.user.username,
iconURL: client.user.displayAvatarURL({ dynamic: true }),
})
const embed = generateEmbed({ interaction })
.setAuthor({ name: '🧮 Calculation Result' })
.setFields([
{
name: '🔢 Operation',
value: operation,
inline: true,
},
{ name: '🔢 Operation', value: operation, inline: true },
{
name: '🔢 Result',
value: `${mexp.eval(operation)}`,
inline: true,
},
]);

return interaction.editReply({ embeds: [embed] });
}
}
await interaction.editReply({ embeds: [embed] });
},
}[options.getSubcommand()]();
},
};
139 changes: 61 additions & 78 deletions src/commands/misc/gacha.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const AnimeImages = require('anime-images-api');
const axios = require('axios');
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');
const { SlashCommandBuilder } = require('discord.js');
const nekoClient = require('nekos.life');

const { waifuChoices } = require('../../constants');
const { generateAttachmentFromBuffer } = require('../../utils');
const { generateAttachmentFromBuffer, generateEmbed } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -28,34 +28,25 @@ module.exports = {
.addChoices(...waifuChoices),
),
),

type: 'Chat Input',

/**
*
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
/** @type {{ client: import('discord.js').Client<true>, member: ?import('discord.js').GuildMember, options: Omit<import('discord.js').CommandInteractionOptionResolver<import('discord.js').CacheType>, 'getMessage' | 'getFocused'> }} */
const { client, member, options } = interaction;
/** @type {{ member: ?import('discord.js').GuildMember, options: Omit<import('discord.js').CommandInteractionOptionResolver<import('discord.js').CacheType>, 'getMessage' | 'getFocused'> }} */
const { member, options } = interaction;
const embed = generateEmbed({ interaction, type: 'member' });
const images = new AnimeImages();
const neko = new nekoClient();

await interaction.deferReply();

if (!member) throw "Member doesn't exist.";

const embed = new EmbedBuilder()
.setColor(member.displayHexColor)
.setTimestamp(Date.now())
.setFooter({
text: client.user.username,
iconURL: client.user.displayAvatarURL({ dynamic: true }),
});

const images = new AnimeImages();
const neko = new nekoClient();

switch (options.getSubcommand()) {
case 'loli': {
return {
loli: async () => {
/** @type {{ data: ArrayBuffer }} */
const { data: buffer } = await axios.get(
`https://api.lolhuman.xyz/api/random/loli?apikey=${process.env.LOLHUMAN_API_KEY}`,
Expand All @@ -71,14 +62,13 @@ module.exports = {
embed
.setAuthor({
name: `${member.user.username} Got a Loli`,
iconURL: member.displayAvatarURL({ dynamic: true }),
iconURL: member.displayAvatarURL(),
})
.setImage(`attachment://${img.name}`);

return interaction.editReply({ embeds: [embed], files: [img] });
}

case 'milf': {
await interaction.editReply({ embeds: [embed], files: [img] });
},
milf: async () => {
/** @type {{ data: ArrayBuffer }} */
const { data: buffer } = await axios.get(
`https://api.lolhuman.xyz/api/random/nsfw/milf?apikey=${process.env.LOLHUMAN_API_KEY}`,
Expand All @@ -94,66 +84,59 @@ module.exports = {
embed
.setAuthor({
name: `${member.user.username} Got a Milf`,
iconURL: member.displayAvatarURL({ dynamic: true }),
iconURL: member.displayAvatarURL(),
})
.setImage(`attachment://${img.name}`);

return interaction.editReply({ embeds: [embed], files: [img] });
}

case 'waifu':
{
const type = options.getString('type', true);

switch (type) {
case 'image': {
/** @type {{ data: { url: String } }} */
const {
data: { url },
} = await axios.get('https://api.waifu.pics/sfw/waifu');

embed
.setAuthor({
name: `${member.user.username} Got a Waifu`,
iconURL: member.displayAvatarURL({ dynamic: true }),
})
.setImage(url);

return interaction.editReply({ embeds: [embed] });
}

case 'pfp': {
const { url } = await neko.avatar();
await interaction.editReply({ embeds: [embed], files: [img] });
},
waifu: () =>
({
image: async () => {
/** @type {{ data: { url: String } }} */
const {
data: { url },
} = await axios.get('https://api.waifu.pics/sfw/waifu');

embed
.setAuthor({
name: `${member.user.username} Got a Waifu`,
iconURL: member.displayAvatarURL(),
})
.setImage(url);

await interaction.editReply({ embeds: [embed] });
},
pfp: async () => {
const { url } = await neko.avatar();

/** @type {{ image: String }} */
const { image } = await images.sfw.waifu();
const imgArr = [url, image];
const pfp = imgArr[Math.floor(Math.random() * imgArr.length)];

embed
.setAuthor({
name: `${member.user.username} Got a Waifu`,
iconURL: member.displayAvatarURL(),
})
.setImage(pfp);

/** @type {{ image: String }} */
const { image } = await images.sfw.waifu();
const imgArr = [url, image];
const pfp = imgArr[Math.floor(Math.random() * imgArr.length)];
await interaction.editReply({ embeds: [embed] });
},
wallpaper: async () => {
const { url } = await neko.wallpaper();

embed.setAuthor({
embed
.setAuthor({
name: `${member.user.username} Got a Waifu`,
iconURL: member.displayAvatarURL({ dynamic: true }),
});
embed.setImage(pfp);

return interaction.editReply({ embeds: [embed] });
}

case 'wallpaper': {
const { url } = await neko.wallpaper();

embed
.setAuthor({
name: `${member.user.username} Got a Waifu`,
iconURL: member.displayAvatarURL({ dynamic: true }),
})
.setImage(url);

return interaction.editReply({ embeds: [embed] });
}
}
}
break;
}
iconURL: member.displayAvatarURL(),
})
.setImage(url);

await interaction.editReply({ embeds: [embed] });
},
}[options.getString('type', true)]()),
}[options.getSubcommand()]();
},
};
Loading

0 comments on commit f9fe01f

Please sign in to comment.