feat: new stats api

This commit is contained in:
Isaac 2021-08-17 00:09:41 +01:00
parent 9363c74ae3
commit 565ca30ebe
No known key found for this signature in database
GPG Key ID: 87B9B6BD04EB7534

View File

@ -123,6 +123,8 @@ class Bot extends Client {
}); });
(async () => { (async () => {
this.version = version;
/** The global bot configuration */ /** The global bot configuration */
this.config = require('../user/config'); this.config = require('../user/config');
@ -189,17 +191,22 @@ class Bot extends Client {
* You can see the source here: https://github.com/discord-tickets/stats * You can see the source here: https://github.com/discord-tickets/stats
*/ */
if (this.config.super_secret_setting) { // you can disable it if you really want if (this.config.super_secret_setting) { // you can disable it if you really want
const tickets = await this.db.models.Ticket.count(); const data = {
await fetch(`https://stats.discordtickets.app/client?id=${this.user.id}&tickets=${tickets}`, { method: 'post' }).catch(e => { client: this.user.id,
this.log.warn('Failed to post tickets count to stats server (you can disable sending stats by setting "super_secret_setting" to false)'); guilds: this.guilds.cache.size,
this.log.debug(e); members: await this.guilds.cache.reduce(async (acc, guild) => await acc + (await guild.fetch()).approximateMemberCount, 0),
}); tickets: await this.db.models.Ticket.count(),
this.guilds.cache.forEach(async g => { version: this.version
const members = (await g.fetch()).approximateMemberCount; };
await fetch(`https://stats.discordtickets.app/guild?id=${g.id}&members=${members}`, { method: 'post' }).catch(e => { this.log.debug('Sending statistics', data);
// don't spam a warning for each server await fetch('https://stats.discordtickets.app/v2', {
this.log.debug(e); body: JSON.stringify(data),
}); headers: { 'Content-Type': 'application/json' },
method: 'POST'
})
.catch(error => {
this.log.warn('Failed to send statistics');
this.log.debug(error);
}); });
} }
} }