From 499517d08284c264cec012eb93608c290a5424e3 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 4 Mar 2021 10:18:48 +0000 Subject: [PATCH] update things again --- src/index.js | 18 +++++++++++++----- src/listeners/error.js | 7 +++++++ src/listeners/guildCreate.js | 1 - src/listeners/ready.js | 22 ++++++---------------- 4 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 src/listeners/error.js diff --git a/src/index.js b/src/index.js index f5ddaec..4a594c6 100644 --- a/src/index.js +++ b/src/index.js @@ -127,21 +127,29 @@ class Bot extends Client { })(); } - async postGuildData(guild) { + async postStats() { /** * OH NO, TELEMETRY!? - * Relax, you can see the source here: https://github.com/discord-tickets/stats + * Relax, it just counts how many people are using DiscordTickets. + * 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 const fetch = require('node-fetch'); - let members = (await guild.fetch()).approximateMemberCount; - fetch(`https://telemetry.discordtickets.app/guild?id=${guild.id}&members=${members}`, { + let tickets = await this.db.models.Ticket.count(); + fetch(`https://stats.discordtickets.app/client?id=${this.user.id}&tickets=${tickets}`, { method: 'post', }).catch(e => { // fail quietly, it doesn't really matter if it didn't work - this.log.debug('Warning: failed to post to telemetry.discordtickets.app/guild'); this.log.debug(e); }); + this.guilds.cache.forEach(async g => { + let members = (await g.fetch()).approximateMemberCount; + fetch(`https://stats.discordtickets.app/guild?id=${g.id}&members=${members}`, { + method: 'post', + }).catch(e => { + this.log.debug(e); + }); + }); } } diff --git a/src/listeners/error.js b/src/listeners/error.js new file mode 100644 index 0000000..d8aa5e0 --- /dev/null +++ b/src/listeners/error.js @@ -0,0 +1,7 @@ +module.exports = { + event: 'error', + execute: (client, error) => { + client.log.warn('The client encountered an error'); + client.log.error(error); + } +}; \ No newline at end of file diff --git a/src/listeners/guildCreate.js b/src/listeners/guildCreate.js index 677699a..375722a 100644 --- a/src/listeners/guildCreate.js +++ b/src/listeners/guildCreate.js @@ -3,6 +3,5 @@ module.exports = { execute: async (client, guild) => { client.log.info(`Added to ${guild.name}`); await guild.createSettings(); - await client.postGuildData(guild); } }; \ No newline at end of file diff --git a/src/listeners/ready.js b/src/listeners/ready.js index aa7fde1..e1881e1 100644 --- a/src/listeners/ready.js +++ b/src/listeners/ready.js @@ -1,7 +1,7 @@ module.exports = { event: 'ready', once: true, - execute: (client) => { + execute: async (client) => { client.log.success(`Connected to Discord as "${client.user.tag}"`); @@ -18,21 +18,11 @@ module.exports = { }, client.config.presence.duration * 1000); } - /** - * OH NO, TELEMETRY!? - * Relax, it just counts how many people are using DiscordTickets. - * You can see the source here: https://github.com/discord-tickets/stats - */ - if (client.config.super_secret_setting) { // you can disable it if you really want - const fetch = require('node-fetch'); - fetch(`https://telemetry.discordtickets.app/client?id=${client.user.id}`, { - method: 'post', - }).catch(e => { - // fail quietly, it doesn't really matter if it didn't work - client.log.debug('Warning: failed to post to telemetry.discordtickets.app/client'); - client.log.debug(e); - }); - client.guilds.cache.forEach(async g => await client.postGuildData(g)); + if(client.config.super_secret_setting) { + setInterval(async () => { + await client.postStats(); + }, 3600000); + await client.postStats(); } }