From 0fb0901053f5fd37449f9661f5e1c6ba024d9ed4 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 16 Apr 2021 07:18:19 -0400 Subject: [PATCH] Add DiscordBotList Stats --- .env.example | 1 + Xiao.js | 6 +++++- structures/Client.js | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index d3674e4b..23280dce 100644 --- a/.env.example +++ b/.env.example @@ -15,6 +15,7 @@ APRIL_FOOLS= # Bot list tokens BOTS_GG_TOKEN= +DISCORDBOTLIST_TOKEN= # Redis info REDIS_HOST= diff --git a/Xiao.js b/Xiao.js index c4a5a513..381e6d17 100644 --- a/Xiao.js +++ b/Xiao.js @@ -184,7 +184,11 @@ client.on('ready', async () => { // Post bot list stats await client.postBotsGGStats(); - setInterval(() => client.postBotsGGStats(), 1.8e+6); + await client.postDiscordBotListStats(); + setInterval(() => { + client.postBotsGGStats(); + client.postDiscordBotListStats(); + }, 1.8e+6); }); client.on('message', async msg => { diff --git a/structures/Client.js b/structures/Client.js index 41160748..797506a3 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -20,7 +20,8 @@ const { XIAO_WEBHOOK_TOKEN, REPORT_CHANNEL_ID, JOIN_LEAVE_CHANNEL_ID, - BOTS_GG_TOKEN + BOTS_GG_TOKEN, + DISCORDBOTLIST_TOKEN } = process.env; module.exports = class XiaoClient extends CommandoClient { @@ -64,9 +65,13 @@ module.exports = class XiaoClient extends CommandoClient { async postBotsGGStats() { try { const { body } = await request - .post(`https://discord.bots.gg/api/bots/${this.user.id}/stats`) - .set({ Authorization: BOTS_GG_TOKEN }) - .send({ guildCount: this.guilds.size }); + .post(`https://discordbotlist.com/api/v1/bots/${this.user.id}/stats`) + .set({ Authorization: DISCORDBOTLIST_TOKEN }) + .send({ + guilds: this.guilds.size, + users: this.users.size, + voice_connections: this.dispatchers.size + }); this.logger.info('[BOTS.GG] Posted stats.'); return body; } catch (err) { @@ -75,6 +80,19 @@ module.exports = class XiaoClient extends CommandoClient { } } + async postDiscordBotListStats() { + try { + const { body } = await request + .post(`https://discord.bots.gg/api/bots/${this.user.id}/stats`) + .set({ Authorization: BOTS_GG_TOKEN }) + .send({ guildCount: this.guilds.size }); + this.logger.info('[DISCORDBOTLIST] Posted stats.'); + } catch (err) { + this.logger.error(`[DISCORDBOTLIST] Failed to post stats:\n${err.stack}`); + return err; + } + } + importBlacklist() { const read = fs.readFileSync(path.join(__dirname, '..', 'blacklist.json'), { encoding: 'utf8' }); const file = JSON.parse(read);