aboutsummaryrefslogtreecommitdiff
path: root/events
diff options
context:
space:
mode:
authorUnknown <jtsshieh@outlook.com>2018-02-24 14:59:35 -0500
committerUnknown <jtsshieh@outlook.com>2018-02-24 14:59:35 -0500
commitc484753ee15dbe2a5ce9c6297f22fabb52ce3b7e (patch)
tree93fd74f30abbd3c8206321b9d9c20b2571ed84ca /events
parent3d36bcf0591f2694c3a2472a157ecca0de8d35fc (diff)
downloadPokeBot-c484753ee15dbe2a5ce9c6297f22fabb52ce3b7e.tar.gz
PokeBot-c484753ee15dbe2a5ce9c6297f22fabb52ce3b7e.tar.bz2
PokeBot-c484753ee15dbe2a5ce9c6297f22fabb52ce3b7e.zip
New Command system
Diffstat (limited to 'events')
-rw-r--r--events/message.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/events/message.js b/events/message.js
index baf4983..7efd7ca 100644
--- a/events/message.js
+++ b/events/message.js
@@ -12,33 +12,42 @@ module.exports = (bot, msg) => {
}
};
-
function parseCommand(bot, msg) {
+ let category;
+
+ const prefix = 'p:';
if (msg.author.bot) return;
- if (!msg.content.startsWith('p:')) return;
- const args = msg.content.slice(2).trim().split(/ +/g);
+ if (!msg.content.startsWith(prefix)) return;
+ const args = msg.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift();
-
let cmd;
- if (bot.commands.has(command)) {
- cmd = bot.commands.get(command);
- } else if (bot.aliases.has(command)) {
- cmd = bot.commands.get(bot.aliases.get(command));
+ Array.from(bot.categories.keys()).forEach(i => {
+ const cmds = bot.categories.get(i);
+ if (cmds.includes(command)) category = i;
+ });
+ if (!category) return;
+
+ if (bot.commands.get(category).has(command)) {
+ cmd = bot.commands.get(category).get(command);
+ } else if (bot.aliases.get(category).has(command)) {
+ cmd = bot.commands.get(category).get(bot.aliases.get(command));
}
if (cmd) {
if (cmd.conf.guildOnly == true) {
if (!msg.channel.guild) {
- return msg.channel.createMessage('This command can only be ran in a guild.');
+ return msg.reply('This command can only be ran in a guild.');
}
}
try {
+ console.log(`${msg.author.tag} ran the command '${cmd.help.name}' in the guild '${msg.member.guild.name}'`);
cmd.run(bot, msg, args);
}
catch (e) {
- console.error('Error while running command' + e.stack);
+ console.error(e.stack);
+ msg.channel.send('There was an error trying to process your command. Don\'t worry because this issue is being looked into');
}
}
}