add dynamic cooldowns

master
Kit Kasune 3 years ago
parent 663e0a69f4
commit 1feb3f21f3
  1. 3
      bot.js
  2. 2
      commands/utility/remind.js
  3. 1
      events/messageCreate.js
  4. 17
      util/cooldownhandler.js

@ -43,7 +43,8 @@ client.misc = {
charsNum: 0 charsNum: 0
}, },
loggers: {}, loggers: {},
rl: readline.createInterface({input: process.stdin, output: process.stdout}) rl: readline.createInterface({input: process.stdin, output: process.stdout}),
cooldown: new Discord.Collection()
}; };
//const config = require('./config.js'); //const config = require('./config.js');

@ -11,12 +11,14 @@ module.exports = {
syntax: '`remind <x days|x hours|x minutes>`', syntax: '`remind <x days|x hours|x minutes>`',
extra: null extra: null
}, },
cooldown: {time: 5000, silent: false, message: "Slow down pal, I don't exactly have a world-star memory. Cool down on the reminders! (This command has a cooldown of 5s and you exceeded it)"},
help: new Discord.MessageEmbed() help: new Discord.MessageEmbed()
.setTitle("Help -> Reminders") .setTitle("Help -> Reminders")
.setDescription("Have me remind you about something later on.") .setDescription("Have me remind you about something later on.")
.addField("Syntax", "`remind <x days|x hours|x minutes>`"), .addField("Syntax", "`remind <x days|x hours|x minutes>`"),
async execute(message, msg, args, cmd, prefix, mention, client) { async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}remind <time> <days|hours|minutes> <reminder>\``);} if (!args.length) {return message.channel.send(`Syntax: \`${prefix}remind <time> <days|hours|minutes> <reminder>\``);}
if (!['linux'].includes(process.platform)) {return message.channel.send("I'm unable to issue reminders at the moment :( Check back later.");}
if (isNaN(args[0])) {return message.channel.send("You didn't provide a number for how long I should wait to remind you.");} if (isNaN(args[0])) {return message.channel.send("You didn't provide a number for how long I should wait to remind you.");}
if (args[0].length > 8) {return message.channel.send("Whoah there, pal. That's a lot of time! A little too much, perhaps?");} if (args[0].length > 8) {return message.channel.send("Whoah there, pal. That's a lot of time! A little too much, perhaps?");}
let time = Number(args[0]); let time = Number(args[0]);

@ -102,6 +102,7 @@ module.exports = async (client, message) => {
if (!command) {let trigger; for (trigger of client.responses.triggers) {if (await trigger[1](message, msg, args, cmd, prefix, mention, client)) {await client.responses.commands.get(trigger[0]).execute(message, msg, args, cmd, prefix, mention, client); break;}} return;} if (!command) {let trigger; for (trigger of client.responses.triggers) {if (await trigger[1](message, msg, args, cmd, prefix, mention, client)) {await client.responses.commands.get(trigger[0]).execute(message, msg, args, cmd, prefix, mention, client); break;}} return;}
if (message.guild && !message.channel.permissionsFor(client.user.id).has('SEND_MESSAGES')) {return message.author.send(`You tried to run the \`${command.name}\` command, but I don't seem to be able to send messages in <#${message.channel.id}>, so I can't do that!`).catch(() => {});}; if (message.guild && !message.channel.permissionsFor(client.user.id).has('SEND_MESSAGES')) {return message.author.send(`You tried to run the \`${command.name}\` command, but I don't seem to be able to send messages in <#${message.channel.id}>, so I can't do that!`).catch(() => {});};
message.channel.sendTyping().catch(() => {}); message.channel.sendTyping().catch(() => {});
if (!require('../util/cooldownhandler')(client, message, command)) {return;}
await wait(500); await wait(500);
if (command.meta && command.meta.guildOnly && !message.guild) {return message.channel.send("You must be in a server to use this command!").catch(() => {});} if (command.meta && command.meta.guildOnly && !message.guild) {return message.channel.send("You must be in a server to use this command!").catch(() => {});}
require('../util/oncommand')(message, msg, args, cmd, prefix, mention, client); require('../util/oncommand')(message, msg, args, cmd, prefix, mention, client);

@ -0,0 +1,17 @@
module.exports = (client, message, cmd) => {
if (!cmd.cooldown) {return true;}
if (client.misc.cooldown.has(message.author.id) && client.misc.cooldown.get(message.author.id).includes(cmd.name)) {
if (typeof cmd.cooldown !== 'number' && !cmd.cooldown.silent) {
message.channel.send(cmd.cooldown.message || "This command has a cooldown, and it looks like you exceeded it. Slow down a little bit!");
}
return false;
} else {
setTimeout(() => {
client.misc.cooldown.get(message.author.id).splice(client.misc.cooldown.get(message.author.id).indexOf(cmd.name), 1);
if (!client.misc.cooldown.get(message.author.id).length) {client.misc.cooldown.delete(message.author.id);}
}, typeof cmd.cooldown === 'number' ? cmd.cooldown : cmd.cooldown.time);
if (!client.misc.cooldown.has(message.author.id)) {client.misc.cooldown.set(message.author.id, []);}
client.misc.cooldown.get(message.author.id).push(cmd.name);
return true;
}
};
Loading…
Cancel
Save