From b93ce2f771cfae601794739f9c2355f3d9ced577 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 24 Feb 2018 14:24:42 -0500 Subject: all events in seperate files --- events/message.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ events/ready.js | 23 +++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 events/message.js create mode 100644 events/ready.js (limited to 'events') diff --git a/events/message.js b/events/message.js new file mode 100644 index 0000000..baf4983 --- /dev/null +++ b/events/message.js @@ -0,0 +1,44 @@ +module.exports = (bot, msg) => { + parseCommand(bot, msg); + + if (msg.mentions != null && msg.mentions.users != null) { + if (msg.mentions.users.has('416637860146446346')) { + 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?'); + } + } + } +}; + + +function parseCommand(bot, msg) { + if (msg.author.bot) return; + if (!msg.content.startsWith('p:')) return; + + const args = msg.content.slice(2).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)); + } + + if (cmd) { + if (cmd.conf.guildOnly == true) { + if (!msg.channel.guild) { + return msg.channel.createMessage('This command can only be ran in a guild.'); + } + } + try { + cmd.run(bot, msg, args); + } + catch (e) { + console.error('Error while running command' + e.stack); + } + } +} diff --git a/events/ready.js b/events/ready.js new file mode 100644 index 0000000..67ef6ec --- /dev/null +++ b/events/ready.js @@ -0,0 +1,23 @@ +function setGame(bot) { + const games = [ + 'Pokemon', + 'Catching things', + 'Finding pokemon', + 'Type p:help for help', + 'Fighting AstralMod', + ]; + + bot.user.setPresence({ + status: 'online', + afk: false, + game: { + type: 0, + name: games[Math.floor(Math.random() * games.length)], + }, + }); +} +module.exports = (bot) => { + console.log('PokeBot has finished loading.'); + setGame(bot); + bot.setInterval(setGame(bot), 200000); +}; -- cgit v1.2.3