Don't send stats if code isn't set

This commit is contained in:
Dragon Fire
2021-04-16 08:20:58 -04:00
parent 294d4576b6
commit 9e95123684
3 changed files with 21 additions and 0 deletions
+1
View File
@@ -14,6 +14,7 @@ JOIN_LEAVE_CHANNEL_ID=
APRIL_FOOLS= APRIL_FOOLS=
# Bot list tokens # Bot list tokens
TOP_GG_TOKEN=
BOTS_GG_TOKEN= BOTS_GG_TOKEN=
DISCORDBOTLIST_TOKEN= DISCORDBOTLIST_TOKEN=
+2
View File
@@ -183,9 +183,11 @@ client.on('ready', async () => {
} }
// Post bot list stats // Post bot list stats
await client.postTopGGStats();
await client.postBotsGGStats(); await client.postBotsGGStats();
await client.postDiscordBotListStats(); await client.postDiscordBotListStats();
setInterval(() => { setInterval(() => {
client.postTopGGStats();
client.postBotsGGStats(); client.postBotsGGStats();
client.postDiscordBotListStats(); client.postDiscordBotListStats();
}, 1.8e+6); }, 1.8e+6);
+18
View File
@@ -20,6 +20,7 @@ const {
XIAO_WEBHOOK_TOKEN, XIAO_WEBHOOK_TOKEN,
REPORT_CHANNEL_ID, REPORT_CHANNEL_ID,
JOIN_LEAVE_CHANNEL_ID, JOIN_LEAVE_CHANNEL_ID,
TOP_GG_TOKEN,
BOTS_GG_TOKEN, BOTS_GG_TOKEN,
DISCORDBOTLIST_TOKEN DISCORDBOTLIST_TOKEN
} = process.env; } = process.env;
@@ -62,7 +63,23 @@ module.exports = class XiaoClient extends CommandoClient {
return this.fonts; return this.fonts;
} }
async postTopGGStats() {
if (!TOP_GG_TOKEN) return null;
try {
const { body } = await request
.post(`https://top.gg/api/bots/${this.user.id}/stats`)
.set({ Authorization: TOP_GG_TOKEN })
.send({ server_count: this.guilds.cache.size });
this.logger.info('[TOP.GG] Posted stats.');
return body;
} catch (err) {
this.logger.error(`[TOP.GG] Failed to post stats:\n${err.stack}`);
return err;
}
}
async postBotsGGStats() { async postBotsGGStats() {
if (!BOTS_GG_TOKEN) return null;
try { try {
const { body } = await request const { body } = await request
.post(`https://discord.bots.gg/api/bots/${this.user.id}/stats`) .post(`https://discord.bots.gg/api/bots/${this.user.id}/stats`)
@@ -77,6 +94,7 @@ module.exports = class XiaoClient extends CommandoClient {
} }
async postDiscordBotListStats() { async postDiscordBotListStats() {
if (!DISCORDBOTLIST_TOKEN) return null;
try { try {
const { body } = await request const { body } = await request
.post(`https://discordbotlist.com/api/v1/bots/${this.user.id}/stats`) .post(`https://discordbotlist.com/api/v1/bots/${this.user.id}/stats`)