From ce4d0aac614cb01c9dc4a9e24db141431f2b3d60 Mon Sep 17 00:00:00 2001 From: siumairice Date: Tue, 15 Aug 2023 03:04:08 -0400 Subject: [PATCH] add coin decay cron job --- src/components/cron.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/cron.ts b/src/components/cron.ts index 4b8e5ca5..1dab478b 100644 --- a/src/components/cron.ts +++ b/src/components/cron.ts @@ -19,6 +19,7 @@ import { import { updateMemberRole, getRoleName, loadRoleMembers } from '../utils/roles'; import { CodeyUserError } from '../codeyUserError'; import { logger } from '../logger/default'; +import { openDB } from './db'; const NOTIF_CHANNEL_ID: string = vars.NOTIF_CHANNEL_ID; const OFFICE_STATUS_CHANNEL_ID: string = vars.OFFICE_STATUS_CHANNEL_ID; @@ -38,6 +39,7 @@ export const initCrons = async (client: Client): Promise => { createCoffeeChatCron(client).start(); createOfficeStatusCron(client).start(); assignCodeyRoleForLeaderboard(client).start(); + createCoinDecayCron().start(); }; interface officeStatus { @@ -165,3 +167,10 @@ export const assignCodeyRoleForLeaderboard = (client: Client): CronJob => } }); }); + +// Decays the Codey Coin Balances on January 1, May 1, and September 1 +export const createCoinDecayCron = (): CronJob => + new CronJob('0 0 1 1,5,9 *', async function () { + const db = await openDB(); + await db.run('UPDATE user_coin SET balance = ROUND(balance / 3)'); + });