diff --git a/commands/utility/help.js b/commands/utility/help.js index 3f4a629..62574c6 100644 --- a/commands/utility/help.js +++ b/commands/utility/help.js @@ -1,5 +1,6 @@ import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder, PermissionsBitField } from 'discord.js'; import fs from 'node:fs'; +import ratelimiter from '../../utils/ratelimiter.js'; const { ownerId, prefix } = process.env; const prefixs = prefix.split(','); @@ -113,6 +114,13 @@ export default { embed.addFields({ name: 'Bot permission', value: `\`${perm.join('` `')}\``, inline: true }); } + if (command.parallelLimit) { + const paralellimit = ratelimiter.checkParallel(interaction.user, command.data.name, command); + + embed.addFields({ name: 'Current number of executions', value: `\`${paralellimit.current}\``, inline: false }); + embed.addFields({ name: 'Maximum number of executions', value: `\`${command.parallelLimit}\``, inline: true }); + } + if (fs.existsSync(`./asset/img/command/${command.category}/${command.data.name}.png`)) { const file = new AttachmentBuilder(`./asset/img/command/${command.category}/${command.data.name}.png`); embed.setImage(`attachment://${command.data.name}.png`); diff --git a/events/client/interactionCreate.js b/events/client/interactionCreate.js index 9485744..9e9abf9 100644 --- a/events/client/interactionCreate.js +++ b/events/client/interactionCreate.js @@ -71,8 +71,8 @@ export default { if (command.parallelLimit) { console.log('Command has a parallel limit'); const doParallelLimit = ratelimiter.checkParallel(interaction.user, commandName, command); - console.log(doParallelLimit); - if (doParallelLimit) { + console.log(doParallelLimit.limited); + if (doParallelLimit.limited) { return await interaction.reply({ content: doParallelLimit, ephemeral: true }); } diff --git a/events/client/messageCreate.js b/events/client/messageCreate.js index bf8bfb3..d6e5e7b 100644 --- a/events/client/messageCreate.js +++ b/events/client/messageCreate.js @@ -334,8 +334,8 @@ export default { if (command.parallelLimit) { console.log('Command has a parallel limit'); const doParallelLimit = ratelimiter.checkParallel(message.author, commandName, command); - console.log(doParallelLimit); - if (doParallelLimit) { + console.log(doParallelLimit.limited); + if (doParallelLimit.limited) { return await message.reply({ content: doParallelLimit, ephemeral: true }); } @@ -426,7 +426,7 @@ export default { } if (!isOptOut && argsLength > 0) { - console.log(`[${timestamp.toISOString()}]\x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`); + console.log(`[${timestamp.toISOString()}] \x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`); } await command.execute(message, args, client) diff --git a/utils/ratelimiter.js b/utils/ratelimiter.js index 0f47bbe..e421062 100644 --- a/utils/ratelimiter.js +++ b/utils/ratelimiter.js @@ -1,6 +1,6 @@ const ratelimit = {}; const parallelLimit = {}; -const { ownerId } = process.env; +const { ownerId, NODE_ENV } = process.env; import db from '../models/index.js'; @@ -85,13 +85,19 @@ function removeParallel(commandName) { function checkParallel(user, commandName, command) { // Don't apply the rate limit to bot owner - if (user.id === ownerId) return false; + if (NODE_ENV !== 'development') { + if (user.id === ownerId) { + return false; + } + } + + if (!parallelLimit[commandName]) parallelLimit[commandName] = 0; // console.log(`[CHECK] command limit: ${command.parallelLimit}`); // console.log(`[CHECK] current parallel executions: ${parallelLimit[commandName]}`); if (parallelLimit[commandName] >= command.parallelLimit) { - return 'There are currently too many parallel execution of this command, please wait before retrying.'; + return { limited: true, current: parallelLimit[commandName], max: command.parallelLimit, msg: `There are currently too many parallel execution of this command, please wait before retrying. (${parallelLimit[commandName]}/${command.parallelLimit})` }; } - return false; + return { limited: false, current: parallelLimit[commandName], max: command.parallelLimit }; } \ No newline at end of file