diff options
Diffstat (limited to 'bot.js')
| -rw-r--r-- | bot.js | 150 |
1 files changed, 75 insertions, 75 deletions
@@ -4,12 +4,11 @@ const config = require('./config.json'); const fs = require('fs'); const readline = require('readline'); const DBL = require('dblapi.js'); -if (typeof config.dbltoken == 'undefined') { - console.log("Skipping DBL..."); +if (typeof config.dbltoken === 'undefined') { + console.log('Skipping DBL...'); } else { - bot.dbl = new DBL(config.dbltoken, bot); - console.log("DBL has been found..."); - + bot.dbl = new DBL(config.dbltoken, bot); + console.log('DBL has been found...'); } @@ -28,21 +27,21 @@ bot.plugins = { settings : require('./plugins/settings.js'), whitelist: require('./plugins/whitelist.js'), gyms : require('./plugins/gyms.js')}; -cmdLoader(); + bot.Raven = require('raven'); bot.Raven.config(config.sentry).install(); bot.gyms = new Discord.Collection(); -async function cmdLoader() { - const categories = await fs.readdirSync('./commands'); +function cmdLoader() { + const categories = fs.readdirSync('./commands'); console.log(`Loading ${categories.length} categories(s) into memory\n`); categories.forEach(x => { loadGroup(x); }); } -async function loadGroup(name) { - const files = await fs.readdirSync(`./commands/${name}`); +function loadGroup(name) { + const files = fs.readdirSync(`./commands/${name}`); console.log(`Loading the category '${name}' into memory with a total of ${files.length} command(s)`); @@ -59,7 +58,7 @@ async function loadGroup(name) { console.log(`The category ${name} has been loaded.\n`); } -async function loadCmd(category, cmd) { +function loadCmd(category, cmd) { try { console.log(`Loading the Command ${cmd.split('.')[0]}`); const command = require(`./commands/${category}/${cmd}`); @@ -68,8 +67,7 @@ async function loadCmd(category, cmd) { console.log(`Loading the alias ${alias} for the command ${command.help.name}`); bot.aliases.get(category).set(alias, command.help.name); }); - } - catch (err) { + } catch (err) { console.log(`An error has occured trying to load the command '${cmd.split('.')[0]}'`); console.log(err.stack); bot.Raven.captureException(err); @@ -78,7 +76,9 @@ async function loadCmd(category, cmd) { fs.readdir('./events', (err, files) => { - if (err) console.error(err); + if (err) { + console.error(err); + } console.log(`Attempting to load a total of ${files.length} events into the memory.`); files.forEach(file => { try { @@ -87,8 +87,7 @@ fs.readdir('./events', (err, files) => { console.log(`Attempting to load the event "${eventName}".`); bot.on(eventName, event.bind(null, bot)); delete require.cache[require.resolve(`./events/${file}`)]; - } - catch (err) { + } catch (err) { console.log('An error has occured trying to load a event. Here is the error.'); console.log(err.stack); bot.Raven.captureException(err); @@ -101,69 +100,69 @@ fs.readdir('./events', (err, files) => { rl.on('line', function(cmd) { const args = cmd.split(' '); switch (args[0]) { - case 'guilds': - if (bot.guilds.size === 0) { - console.log(('[!] No guilds found.')); - } else { - console.log('[i] Here\'s the servers that PokeBot is connected to:'); - for (const [id, guild] of bot.guilds) { - console.log(` Guild Name: ${guild.name} - ID: ${guild.id}`); - } + case 'guilds': + if (bot.guilds.size === 0) { + console.log(('[!] No guilds found.')); + } else { + console.log('[i] Here\'s the servers that PokeBot is connected to:'); + for (const guild of bot.guilds) { + console.log(` Guild Name: ${guild[1].name} - ID: ${guild[1].id}`); } - break; - case 'channels': - if (!args[1]) { - console.log('[!] Please insert the guild\'s ID.'); - } else { - var guild = bot.guilds.get(args[1]); - console.log('[i] Here\'s the channels that this guild have:'); - for ([id, channel, guild] of guild && bot.channels) { - console.log(` Channel: #${channel.name} - ID: ${channel.id}`); - } + } + break; + case 'channels': + if (!args[1]) { + console.log('[!] Please insert the guild\'s ID.'); + } else { + const guild = bot.guilds.get(args[1]); + console.log('[i] Here\'s the channels that this guild have:'); + for (const channel of guild && bot.channels) { + console.log(` Channel: #${channel[1].name} - ID: ${channel[1].id}`); } - break; - case 'leave': - if (!args[1]) { - console.log('[!] Please insert the guild\'s ID.'); - } else { - var guild = bot.guilds.get(args[1]); - guild.leave(); + } + break; + case 'leave': + if (!args[1]) { + console.log('[!] Please insert the guild\'s ID.'); + } else { + bot.guilds.get(args[1]).leave(); + } + break; + case 'broadcast': + if (!args[1]) { + console.log('[!] Please insert the guild\'s ID.'); + } else { + const broadcast = args.join(' ').slice(48); + let guild = null; + guild = bot.guilds.get(args[1]); + let channel = null; + channel = guild.channels.get(args[2]); + if (channel != null) { + channel.send(broadcast); } - break; - case 'broadcast': - if (!args[1]) { - console.log('[!] Please insert the guild\'s ID.'); - } else { - const broadcast = args.join(' ').slice(48); - var guild = null; - guild = bot.guilds.get(args[1]); - var channel = null; - channel = guild.channels.get(args[2]); - if (channel != null) { - channel.send(broadcast); - } - if (channel = null) { - console.log ('Usage: broadcast [guildID] [channelID]'); - } + if (channel == null) { + console.log('Usage: broadcast [guildID] [channelID]'); } - break; - case 'exit': - console.log('[i] PokeBot will now exit!'); - bot.user.setStatus('invisible'); - process.exit(0); - break; - case 'help': - var msg = ('PokeBot Console Help\n\n'); - msg += ('guilds - Shows all guilds that PokeBot\'s on.\n'); - msg += ('channels - Shows all the channels that the guilds have.\n'); - msg += ('leave - Leaves a guild.\n'); - msg += ('broadcast - Broadcasts a message to a server.\n'); - msg += ('help - Shows this command.\n'); - msg += ('exit - Exits PokeBot.\n'); - console.log(msg); - break; - default: - console.log('Unknown Command type \'help\' to list the commands...'); + } + break; + case 'exit': + console.log('[i] PokeBot will now exit!'); + bot.user.setStatus('invisible'); + process.exit(0); + break; + case 'help': { + let msg = ('PokeBot Console Help\n\n'); + msg += ('guilds - Shows all guilds that PokeBot\'s on.\n'); + msg += ('channels - Shows all the channels that the guilds have.\n'); + msg += ('leave - Leaves a guild.\n'); + msg += ('broadcast - Broadcasts a message to a server.\n'); + msg += ('help - Shows this command.\n'); + msg += ('exit - Exits PokeBot.\n'); + console.log(msg); + break; + } + default: + console.log('Unknown Command type \'help\' to list the commands...'); } rl.prompt(); }); @@ -172,6 +171,7 @@ process.on('unhandledRejection', (err) => { console.error(err.stack); bot.Raven.captureException(err); }); +cmdLoader(); bot.login(config.token).then(() => { rl.prompt(); }); |
