aboutsummaryrefslogtreecommitdiff
path: root/events/message.js
blob: 4154536082ec7ecb184ac4ef1d0e53ee111cb163 (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** **************************************
 *
 *   Message/CommandHandler: Plugin for PokeBot that processes and parses command.
 *   Copyright (C) 2018 TheEdge, jtsshieh, Alee
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * *************************************/

module.exports = (bot, msg) => {
  parseCommand(bot, msg);

  if (msg.mentions != null && msg.mentions.users != null) {
    if (msg.mentions.users.has('417096530596724737')) {
      if (msg.content.toLowerCase().includes('hello') || (msg.content.toLowerCase().includes('hi'))) {
        msg.reply('Hi there.');
      } else if (msg.content.toLowerCase().includes('shut') && msg.content.toLowerCase().includes('up')) {
        msg.reply('Excuse me?');
      } else if (msg.content.toLowerCase().includes('astralmod')) {
        msg.reply('HEY! I hate AstralMod so don\'t talk about it >:((((');
      } else if (msg.content.toLowerCase().includes('ok') && (msg.content.toLowerCase().includes('google'))) {
        msg.reply('Sorry, but I\'m not Google...');
      }
    }
  }
};

function parseCommand(bot, msg) {
  let category;

  const prefix = 'p:';
  if (msg.author.bot) return;

  if (!msg.content.startsWith(prefix)) return;
  const args = msg.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift();
  let cmd;

  Array.from(bot.categories.keys()).forEach(i => {
    const cmds = bot.categories.get(i);
    if (cmds.includes(command)) category = i;
    if (bot.aliases.get(i).has(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(category).get(command));
  }

  if (cmd) {
    if (cmd.conf.guildOnly == true) {
      if (!msg.channel.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(e.stack);
      bot.Raven.captureException(e);
      msg.channel.send('There was an error trying to process your command. Don\'t worry because this issue is being looked into');
    }
  }
}