diff options
Diffstat (limited to 'src/tasks/updateStats.ts')
-rw-r--r-- | src/tasks/updateStats.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tasks/updateStats.ts b/src/tasks/updateStats.ts new file mode 100644 index 0000000..7b0690f --- /dev/null +++ b/src/tasks/updateStats.ts @@ -0,0 +1,22 @@ +import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; +import { Stat } from '../lib/models/Stat'; + +export default class UpdateStatsTask extends BushTask { + public constructor() { + super('updateStats', { + delay: 600_000, // 10 minutes + runOnStart: true + }); + } + public override async exec(): Promise<void> { + const row = + (await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment })); + row.commandsUsed = client.stats.commandsUsed; + await row.save(); + } + + public static async init(): Promise<bigint> { + return ((await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }))) + .commandsUsed; + } +} |