forked from asdbee/ModMail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandHandler.js
43 lines (39 loc) · 1.42 KB
/
commandHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const Eris = require('eris');
const fs = require('fs');
const config = require('./config.js');
const mail = require('./modmail.js').get;
function getModMail(id) {
const getMail = require('./database/template.js');
return getMail.findById(id);
}
module.exports = (bot) => {
bot.commands = new Eris.Collection();
bot.on('ready', () => {
const commandFiles = fs.readdirSync(__dirname + '/commands').filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(__dirname + `/commands/${file}`);
bot.commands.set(command.name, command);
command.shortHands.forEach((s) => {
if (s === '') return
bot.commands.set(s, command)
});
}
});
bot.on('messageCreate', (msg) => {
if (msg.author.bot) return;
if (msg.guildID === undefined) return;
if (!bot.guilds.get(config.mainGuild).members.get(msg.author.id)) return;
if (!msg.content.startsWith(config.prefix)) return;
mail.getChannel(msg.channel.id).then((checkMail) => {
const args = msg.content.slice(config.prefix.length).trim().split(' ');
const cmd = args[0].toLowerCase();
if (!bot.commands.has(cmd)) return;
try {
bot.commands.get(cmd).execute(bot, msg, args, checkMail);
} catch (error) {
bot.createMessage(msg.channel.id, '`X` There was an error executing that command.');
console.log(error.stack);
}
});
});
};