From f8b0d3603031263ba27b6fa3e132b243707d0d3b Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 28 Apr 2018 21:13:30 +0000 Subject: [PATCH] Bot list stuff --- Xiao.js | 6 ++++++ package.json | 2 +- util/BotList.js | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 util/BotList.js diff --git a/Xiao.js b/Xiao.js index 0ef7679c..7c5bf69f 100644 --- a/Xiao.js +++ b/Xiao.js @@ -9,6 +9,7 @@ const client = new XiaoClient({ unknownCommandResponse: false, disabledEvents: ['TYPING_START'] }); +const { discordBots } = require('./util/BotList'); const SequelizeProvider = require('./providers/Sequelize'); const activities = require('./assets/json/activity'); @@ -56,6 +57,7 @@ client.on('ready', () => { const activity = activities[Math.floor(Math.random() * activities.length)]; client.user.setActivity(activity.text, { type: activity.type }); }, 60000); + discordBots(client); }); client.on('disconnect', event => { @@ -63,6 +65,10 @@ client.on('disconnect', event => { process.exit(0); }); +client.on('guildCreate', () => discordBots(client)); + +client.on('guildDelete', () => discordBots(client)); + client.on('commandRun', command => console.log(`[COMMAND] Ran command ${command.groupID}:${command.memberName}.`)); client.on('error', err => console.error('[ERROR]', err)); diff --git a/package.json b/package.json index a1c9d1be..c186ea72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "75.0.0", + "version": "75.0.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/BotList.js b/util/BotList.js new file mode 100644 index 00000000..b942e839 --- /dev/null +++ b/util/BotList.js @@ -0,0 +1,20 @@ +const snekfetch = require('snekfetch'); +const { DISCORD_BOTS_TOKEN } = process.env; + +class BotListUtil { + static async discordBots(client) { + try { + const { body } = await snekfetch + .post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`) + .set({ Authorization: DISCORD_BOTS_TOKEN }) + .send({ server_count: client.guilds.size }); + console.log('[DISCORD BOTS] Posted to Discord Bots.'); + return body; + } catch (err) { + console.error('[DISCORD BOTS] Failed to post to Discord Bots.', err); + return err; + } + } +} + +module.exports = BotListUtil;