forked from Supositware/Haha-Yes
show how many execution in parallel are currently running in help
This commit is contained in:
parent
591652f33f
commit
50e49db47c
4 changed files with 23 additions and 9 deletions
|
@ -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`);
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
|
|
@ -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 };
|
||||
}
|
Loading…
Reference in a new issue