Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +39,7 @@ export const initCrons = async (client: Client): Promise<void> => {
createCoffeeChatCron(client).start();
createOfficeStatusCron(client).start();
assignCodeyRoleForLeaderboard(client).start();
createCoinDecayCron().start();
};

interface officeStatus {
Expand Down Expand Up @@ -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)');
});