Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ DISCORD_BOT_TOKEN="discord-bot-token"
DISCORD_CLIENT_ID="discord-client-id"
DISCORD_CLIENT_SECRET="discord-client-secret"
DISCORD_WEATHER_API_KEY="discord-weather-api-key"
DISCORD_WEBHOOK_ANIMAL=""
DISCORD_WEBHOOK_ANIMAL="discord-webhook-animal"
DISCORD_WEBHOOK_BIRTHDAY="discord-webhook-birthday"
DISCORD_WEBHOOK_LEETCODE="discord-webhook-leetcode"
DISCORD_WEBHOOK_REMINDERS="discord-webhook-reminders"
DISCORD_WEBHOOK_REMINDERS_HACK="discord-webhook-reminders-hack"
Expand Down
54 changes: 54 additions & 0 deletions apps/cron/src/crons/birthday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { WebhookClient } from "discord.js";
import { and, eq, exists, or, sql } from "drizzle-orm";

Check failure on line 2 in apps/cron/src/crons/birthday.ts

View workflow job for this annotation

GitHub Actions / lint

'or' is defined but never used. Allowed unused vars must match /^_/u

import { db } from "@forge/db/client";
import { Permissions, User } from "@forge/db/schemas/auth";
import { DuesPayment, Member } from "@forge/db/schemas/knight-hacks";

Check failure on line 6 in apps/cron/src/crons/birthday.ts

View workflow job for this annotation

GitHub Actions / lint

'DuesPayment' is defined but never used. Allowed unused vars must match /^_/u
import { logger } from "@forge/utils";

import { env } from "../env";
import { CronBuilder } from "../structs/CronBuilder";

const BIRTHDAY_WEBHOOK = new WebhookClient({
url: env.DISCORD_WEBHOOK_BIRTHDAY,
});

export const birthday = new CronBuilder({
name: "birthday",
color: 7,
}).addCron(
"0 12 * * *", // every day at 12 (noon!)
async () => {
const today = new Date();
const month = today.getMonth() + 1;
const day = today.getDate();

const members = await db
.select({
firstName: Member.firstName,
lastName: Member.lastName,
guildProfileVisible: Member.guildProfileVisible,
discordId: User.discordUserId,
})
.from(Member)
.leftJoin(User, eq(User.id, Member.userId))
.where(
and(
exists(
db
.select()
.from(Permissions)
.where(eq(Permissions.userId, Member.userId)),
),
eq(Member.guildProfileVisible, true),
eq(sql`EXTRACT(MONTH FROM ${Member.dob})`, month),
eq(sql`EXTRACT(DAY FROM ${Member.dob})`, day),
),
);

for (const u of members) {
logger.log(`${u.firstName} ${u.lastName}'s birthday today!`);
await BIRTHDAY_WEBHOOK.send(`Happy Birthday, <@${u.discordId}>`);
}
},
);
2 changes: 2 additions & 0 deletions apps/cron/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export const env = createEnv({
DISCORD_BOT_TOKEN: z.string(),
DISCORD_WEBHOOK_ANIMAL: z.string(),
DISCORD_WEBHOOK_LEETCODE: z.string(),
DISCORD_WEBHOOK_BIRTHDAY: z.string(),
DISCORD_WEBHOOK_REMINDERS: z.string(),
DISCORD_WEBHOOK_REMINDERS_PRE: z.string(),
DISCORD_WEBHOOK_REMINDERS_HACK: z.string(),
},
runtimeEnvStrict: {
DISCORD_BOT_TOKEN: process.env.DISCORD_BOT_TOKEN,
DISCORD_WEBHOOK_ANIMAL: process.env.DISCORD_WEBHOOK_ANIMAL,
DISCORD_WEBHOOK_BIRTHDAY: process.env.DISCORD_WEBHOOK_BIRTHDAY,
DISCORD_WEBHOOK_LEETCODE: process.env.DISCORD_WEBHOOK_LEETCODE,
DISCORD_WEBHOOK_REMINDERS: process.env.DISCORD_WEBHOOK_REMINDERS,
DISCORD_WEBHOOK_REMINDERS_PRE: process.env.DISCORD_WEBHOOK_REMINDERS_PRE,
Expand Down
3 changes: 3 additions & 0 deletions apps/cron/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { alumniAssign } from "./crons/alumni-assign";
import { capybara, cat, duck, goat } from "./crons/animals";
import { backupFilteredDb } from "./crons/backup-filtered-db";
import { birthday } from "./crons/birthday";
import { leetcode } from "./crons/leetcode";
import { preReminders, reminders } from "./crons/reminder";
import { roleSync } from "./crons/role-sync";
Expand All @@ -22,4 +23,6 @@ reminders.schedule();
// Silencing for now, needs to be manually re-enabled for hacks @WHOEVER_IS_DEV_LEAD_RN
// hackReminders.schedule();

birthday.schedule();

roleSync.schedule();
Loading