aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/feature/updateStats.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-07-11 18:44:09 +0200
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-07-11 18:44:09 +0200
commitd2a020837267bf024f508b402f596f8e242672ed (patch)
tree7e371015fa1451bda993e44aa591b3cc24c3209d /src/tasks/feature/updateStats.ts
parent7d1dede862339c439830a0306e2b7f3a273f967f (diff)
downloadtanzanite-d2a020837267bf024f508b402f596f8e242672ed.tar.gz
tanzanite-d2a020837267bf024f508b402f596f8e242672ed.tar.bz2
tanzanite-d2a020837267bf024f508b402f596f8e242672ed.zip
create task categories
Diffstat (limited to 'src/tasks/feature/updateStats.ts')
-rw-r--r--src/tasks/feature/updateStats.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tasks/feature/updateStats.ts b/src/tasks/feature/updateStats.ts
new file mode 100644
index 0000000..0d0e661
--- /dev/null
+++ b/src/tasks/feature/updateStats.ts
@@ -0,0 +1,26 @@
+import { BushTask, Stat, Time } from '#lib';
+import { Client } from 'discord.js';
+
+export default class UpdateStatsTask extends BushTask {
+ public constructor() {
+ super('updateStats', {
+ delay: 10 * Time.Minute,
+ runOnStart: true
+ });
+ }
+
+ public async exec() {
+ const row =
+ (await Stat.findByPk(this.client.config.environment)) ??
+ (await Stat.create({ environment: this.client.config.environment }));
+ row.commandsUsed = this.client.stats.commandsUsed;
+ row.slashCommandsUsed = this.client.stats.slashCommandsUsed;
+ await row.save();
+ }
+
+ public static async init(client: Client): 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 };
+ }
+}