From 0aaa6166af6ff17f9b643997fccb44de1b57b1e5 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 6 Aug 2022 21:07:39 -0400 Subject: track the number of guilds the bot is in so I can make a graph --- src/tasks/stats/guildCount.ts | 24 ++++++++++++++++++++++++ src/tasks/stats/memberCount.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/tasks/stats/guildCount.ts create mode 100644 src/tasks/stats/memberCount.ts (limited to 'src/tasks/stats') diff --git a/src/tasks/stats/guildCount.ts b/src/tasks/stats/guildCount.ts new file mode 100644 index 0000000..262f00c --- /dev/null +++ b/src/tasks/stats/guildCount.ts @@ -0,0 +1,24 @@ +import { BushTask, Time } from '#lib'; +import { GuildCount } from '../../lib/models/shared/GuildCount.js'; + +export default class GuildCountTask extends BushTask { + public constructor() { + super('guildCount', { + delay: 15 * Time.Minute, + runOnStart: true + }); + } + + public override async exec() { + if (!this.client.config.isProduction) return; + + try { + await GuildCount.create({ + environment: this.client.config.environment, + guildCount: this.client.guilds.cache.size + }); + } catch (err) { + void this.client.console.error('guildCount', err); + } + } +} diff --git a/src/tasks/stats/memberCount.ts b/src/tasks/stats/memberCount.ts new file mode 100644 index 0000000..9c31c5b --- /dev/null +++ b/src/tasks/stats/memberCount.ts @@ -0,0 +1,28 @@ +import { BushTask, MemberCount, Time } from '#lib'; +import assert from 'assert/strict'; + +export default class MemberCountTask extends BushTask { + public constructor() { + super('memberCount', { + delay: Time.Minute, + runOnStart: true + }); + } + + public override async exec() { + if (!this.client.config.isProduction) return; + + const res = await Promise.allSettled( + this.client.guilds.cache + .filter((g) => g.memberCount >= 100) + .map((g) => MemberCount.create({ guildId: g.id, memberCount: g.memberCount })) + ); + + res + .filter((r) => r.status === 'rejected') + .forEach((r) => { + assert(r.status === 'rejected'); + void this.client.console.error('memberCount', r.status); + }); + } +} -- cgit