You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
4 years ago
|
const Collection = require("@discordjs/collection");
|
||
|
|
||
|
module.exports = class {
|
||
|
constructor(client) {
|
||
|
this.client = client;
|
||
|
}
|
||
|
|
||
|
async emit(message) {
|
||
|
if (message.authorID === this.client.user.id) return;
|
||
|
message.markSeen();
|
||
|
|
||
|
let prefixes = this.client.config.defaultPrefix;
|
||
|
if (message.content.indexOf(prefixes) !== 0) return;
|
||
|
let args = message.content.slice(prefixes.length).trim().split(/ +/g);
|
||
|
let command = args.shift().toLowerCase();
|
||
|
let cmd =
|
||
|
this.client.commands.get(command) ||
|
||
|
this.client.commands.get(this.client.aliases.get(command));
|
||
|
if (!cmd) return;
|
||
|
|
||
|
this.client.logger.log(`${message.author.username} (${message.authorID}) ran command ${cmd.help.name}`, "cmd")
|
||
|
|
||
|
if (!cmd.conf.enabled) {
|
||
|
return message.chat.sendMessage("Sorry this command is disabled.");
|
||
|
}
|
||
|
if (cmd.conf.dmOnly && message.chat.isGroup) {
|
||
|
return message.chat.sendMessage("Sorry this command is usable only in a private conversation.");
|
||
|
}
|
||
|
|
||
|
if (!this.client.cooldowns.has(cmd.help.name)) {
|
||
|
this.client.cooldowns.set(cmd.help.name, new Collection());
|
||
|
};
|
||
|
|
||
|
let timeNow = Date.now();
|
||
|
let tStamps = this.client.cooldowns.get(cmd.help.name);
|
||
|
let cdAmount = (cmd.help.cooldown || 3) * 1000;
|
||
|
|
||
|
if (tStamps.has(message.authorID)) {
|
||
|
let cdExpirationTime = tStamps.get(message.authorID) + cdAmount;
|
||
|
if (timeNow < cdExpirationTime) {
|
||
|
let timeLeft = (cdExpirationTime - timeNow) / 1000;
|
||
|
return message.chat.sendMessage(`Please wait ${timeLeft.toFixed(0)} seconds to use the command ${cmd.help.name} again`);
|
||
|
};
|
||
|
};
|
||
|
|
||
|
tStamps.set(message.authorID, timeNow);
|
||
|
setTimeout(() => tStamps.delete(message.authorID), cdAmount);
|
||
|
|
||
|
cmd.run(message, args);
|
||
|
}
|
||
|
}
|