aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/updateStats.ts
blob: 0e50c23c43ff1de1c38123cbb3c78a18868b7189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { BushTask, Stat, Time } from '#lib';

export default class UpdateStatsTask extends BushTask {
	public constructor() {
		super('updateStats', {
			delay: 10 * Time.Minute,
			runOnStart: true
		});
	}

	public async exec() {
		const row =
			(await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }));
		row.commandsUsed = client.stats.commandsUsed;
		row.slashCommandsUsed = client.stats.slashCommandsUsed;
		await row.save();
	}

	public static async init(): Promise<{ commandsUsed: bigint; slashCommandsUsed: bigint }> {
		const temp =
			(await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }));
		return { commandsUsed: temp.commandsUsed, slashCommandsUsed: temp.slashCommandsUsed };
	}
}