Skip to content

Commit

Permalink
Merge pull request #80 from RezkyRizaldi/v14
Browse files Browse the repository at this point in the history
V2.0.0 beta
  • Loading branch information
RezkyRizaldi authored Mar 5, 2023
2 parents ee46e84 + d3f1e30 commit 181eadc
Show file tree
Hide file tree
Showing 69 changed files with 5,356 additions and 1,820 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ MESSAGE_PIN_WEBHOOK_ID=
MESSAGE_PIN_WEBHOOK_TOKEN=
MESSAGE_UNPIN_WEBHOOK_ID=
MESSAGE_UNPIN_WEBHOOK_TOKEN=
MONGODB_URI=
NEWSAPI_API_KEY=
OPENAI_API_KEY=
ROLE_CREATE_WEBHOOK_ID=
Expand Down
16 changes: 14 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@
"events"
],
"@/handlers/*": [
"functions/handlers/*"
"handlers/*"
],
"@/handlers": [
"functions/handlers"
"handlers"
],
"@/lang/*": [
"lang/*"
],
"@/lang": [
"lang"
],
"@/schemas/*": [
"schemas/*"
],
"@/schemas": [
"schemas"
],
"@/utils/*": [
"utils/*"
Expand Down
59 changes: 35 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "borobot",
"version": "1.38.0",
"version": "1.39.0",
"description": "A simple Discord Bot build with Discord.js",
"displayName": "Borobot",
"bugs": {
Expand Down Expand Up @@ -42,36 +42,43 @@
"@discordjs/rest": "^1.5.0",
"@discordjs/voice": "^0.14.0",
"@distube/soundcloud": "^1.3.0",
"@distube/spotify": "^1.4.5",
"@distube/spotify": "^1.5.1",
"@distube/yt-dlp": "^1.1.3",
"@distube/ytdl-core": "^4.11.7",
"@napi-rs/canvas": "^0.1.30",
"@vitalets/google-translate-api": "^9.0.0",
"@napi-rs/canvas": "^0.1.37",
"@vitalets/google-translate-api": "^9.1.0",
"anime-images-api": "^2.0.0",
"axios": "^1.2.1",
"canvas": "^2.10.2",
"ascii-table": "^0.0.9",
"axios": "^1.3.4",
"canvas": "^2.11.0",
"chalk": "^4.1.2",
"change-case": "^4.1.2",
"color-convert": "^2.0.1",
"convert": "^4.9.0",
"convert": "^4.10.0",
"ctk-anime-scraper": "^3.5.0",
"currency-converter-lt": "^2.0.0-beta.0",
"discord-api-types": "^0.37.24",
"discord-image-generation": "^1.4.15",
"discord-api-types": "^0.37.35",
"discord-image-generation": "^1.4.25",
"discord-together": "^1.3.31",
"discord.js": "^14.7.1",
"distube": "^4.0.4",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"ffmpeg-static": "^5.1.0",
"file-type": "^18.0.0",
"file-type": "^18.2.1",
"glob": "^9.2.1",
"holodex.js": "^2.0.5",
"libsodium-wrappers": "^0.7.10",
"math-expression-evaluator": "^2.0.0",
"minecraft-data": "^3.20.0",
"http-proxy-agent": "^5.0.0",
"i18next": "^22.4.10",
"i18next-fs-backend": "^2.1.1",
"libsodium-wrappers": "^0.7.11",
"math-expression-evaluator": "^2.0.2",
"minecraft-data": "^3.30.0",
"moment": "^2.29.4",
"mongoose": "^7.0.0",
"nekos.life": "^3.0.0",
"newsapi": "^2.4.1",
"openai": "^3.1.0",
"openai": "^3.2.1",
"ordinal": "^1.0.3",
"pagination.djs": "^4.0.9",
"pluralize": "^8.0.0",
Expand All @@ -80,23 +87,23 @@
"string-progressbar": "^1.0.4",
"tesseract.js": "^4.0.2",
"weather-js": "^2.0.0",
"yt-search": "^2.10.3",
"yt-search": "^2.10.4",
"ytdl-core": "^4.11.2"
},
"optionalDependencies": {
"bufferutil": "^4.0.7",
"erlpack": "^0.1.4",
"utf-8-validate": "^6.0.0",
"zlib-sync": "^0.1.7"
"utf-8-validate": "^6.0.3",
"zlib-sync": "^0.1.8"
},
"devDependencies": {
"eslint": "^8.30.0",
"eslint": "^8.35.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"husky": "^8.0.3",
"lint-staged": "^13.1.2",
"module-alias": "^2.2.2",
"nodemon": "^2.0.20",
"prettier": "^2.8.1"
"nodemon": "^2.0.21",
"prettier": "^2.8.4"
},
"lint-staged": {
"*.ts": "eslint --cache --fix",
Expand All @@ -113,8 +120,12 @@
"@/constants": "./src/constants",
"@/events/*": "./src/events/*",
"@/events": "./src/events",
"@/handlers/*": "./src/functions/handlers/*",
"@/handlers": "./src/functions/handlers",
"@/handlers/*": "./src/handlers/*",
"@/handlers": "./src/handlers",
"@/lang/*": "./src/lang/*",
"@/lang": "./src/lang",
"@/schemas/*": "./src/schemas/*",
"@/schemas": "./src/schemas",
"@/utils/*": "./src/utils/*",
"@/utils": "./src/utils"
}
Expand Down
58 changes: 45 additions & 13 deletions src/commands/misc/calc.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
const { bold, inlineCode, SlashCommandBuilder } = require('discord.js');
const mexp = require('math-expression-evaluator');
const { changeLanguage, t } = require('i18next');
const Mexp = require('math-expression-evaluator');

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

module.exports = {
data: new SlashCommandBuilder()
.setName('calc')
.setDescription('🧮 Calculator command.')
.setDescriptionLocalizations({
'es-ES': t('command.calc.description', { lng: 'es-ES' }),
})
.addSubcommand((subcommand) =>
subcommand
.setName('list')
.setDescription('➗ View supported math symbols.'),
.setDescription('➗ Displays supported math symbols.')
.setDescriptionLocalizations({
'es-ES': t('command.calc.subcommand.list.description', {
lng: 'es-ES',
}),
}),
)
.addSubcommand((subcommand) =>
subcommand
.setName('run')
.setDescription('🧮 calculate a math operation.')
.setDescription('🧮 Calculate a math operation.')
.setDescriptionLocalizations({
'es-ES': t('command.calc.subcommand.run.description', {
lng: 'es-ES',
}),
})
.addStringOption((option) =>
option
.setName('operation')
.setDescription('🔢 The operation to calculate.')
.setDescription('🔢 The operation to be calculated.')
.setDescriptionLocalizations({
'es-ES': t(
'command.calc.subcommand.run.option.operation.description',
{ lng: 'es-ES' },
),
})
.setRequired(true),
),
),
Expand All @@ -31,37 +51,49 @@ module.exports = {
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
const { options } = interaction;
const { locale, options } = interaction;

await interaction.deferReply();

await changeLanguage(locale);

return {
list: async () => {
const symbols = Object.values(math);
const symbols = Object.entries(math).map(([k, v]) => ({
...v,
description: t(`global.constant.math.${k}`),
}));

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

await generatePagination({ interaction, limit: 10 })
.setAuthor({
name: `➗ Supported Math Symbol Lists (${symbols.length.toLocaleString()})`,
name: t('command.calc.pagination', {
total: count(symbols),
}),
})
.setDescriptions(responses)
.render();
},
run: async () => {
const operation = options.getString('operation', true);
const mexp = new Mexp();

const embed = generateEmbed({ interaction })
.setAuthor({ name: '🧮 Calculation Result' })
.setAuthor({ name: t('command.calc.embed.author') })
.setFields([
{ name: '🔢 Operation', value: operation, inline: true },
{
name: '🔢 Result',
name: t('command.calc.embed.field.operation'),
value: operation,
inline: true,
},
{
name: t('command.calc.embed.field.result'),
value: `${mexp.eval(operation)}`,
inline: true,
},
Expand Down
54 changes: 39 additions & 15 deletions src/commands/misc/convert.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const { convert } = require('convert');
const CC = require('currency-converter-lt');
const { bold, codeBlock, SlashCommandBuilder } = require('discord.js');
const {
bold,
codeBlock,
SlashCommandBuilder,
hyperlink,
} = require('discord.js');
const { changeLanguage, t } = require('i18next');

const { units } = require('@/constants');
const { generateEmbed, generatePagination } = require('@/utils');
const { count, generateEmbed, generatePagination } = require('@/utils');

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -86,11 +92,14 @@ module.exports = {
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
const { options } = interaction;
const embed = generateEmbed({ interaction });
const { locale, options } = interaction;

await interaction.deferReply();

await changeLanguage(locale);

const embed = generateEmbed({ interaction });

return {
currency: () => {
const currencyConverter = new CC();
Expand All @@ -107,7 +116,9 @@ module.exports = {

await generatePagination({ interaction, limit: 10 })
.setAuthor({
name: `💲 Currency Lists (${currencies.length.toLocaleString()})`,
name: t('command.convert.subcommandGroup.currency.pagination', {
total: count(currencies),
}),
})
.setDescriptions(responses)
.render();
Expand All @@ -124,20 +135,24 @@ module.exports = {
);

if (!fromCurrency || !toCurrency) {
throw 'Please provide a valid unit.';
throw t('global.error.currency', {
link: hyperlink(
t('misc.currency'),
`https://${locale
.split('-')
.shift()}.wikipedia.org/wiki/ISO_4217`,
),
});
}

const result = await currencyConverter
.from(fromCurrency)
.to(toCurrency)
.amount(amount)
.setDecimalComma(true)
.setupRatesCache({ isRatesCaching: true })
.convert();
.convert(amount);

embed
.setAuthor({
name: '💲 Currency Conversion Result',
name: t('command.convert.subcommandGroup.currency.embed'),
})
.setDescription(
codeBlock(
Expand All @@ -154,11 +169,13 @@ module.exports = {
list: async () => {
const responses = units
.sort((a, b) => a.localeCompare(b))
.map((unit, i) => `${bold(`${i + 1}.`)} - ${unit}`);
.map((unit, i) => `${bold(`${i + 1}.`)} ${unit}`);

await generatePagination({ interaction, limit: 10 })
.setAuthor({
name: `📄 SI Unit Lists (${units.length.toLocaleString()})`,
name: t('command.convert.subcommandGroup.unit.pagination', {
total: count(units),
}),
})
.setDescriptions(responses)
.render();
Expand All @@ -175,15 +192,22 @@ module.exports = {
);

if (!fromUnit || !toUnit) {
throw 'Please provide a valid unit.';
throw t('global.error.unit', {
link: hyperlink(
t('misc.unit'),
`https://${locale
.split('-')
.shift()}.wikipedia.org/wiki/International_System_of_Units`,
),
});
}

/** @type {Number} */
const result = convert(amount, fromUnit).to(toUnit);

embed
.setAuthor({
name: '♾️ Unit Conversion Result',
name: t('command.convert.subcommandGroup.unit.embed'),
})
.setDescription(
codeBlock(`${amount} ${fromUnit} = ${result} ${toUnit}`),
Expand Down
Loading

0 comments on commit 181eadc

Please sign in to comment.