Skip to content

Add Alerting Infrastructure and Hack Knight Alerts #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/alerts/attendance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type Client, Colors, EmbedBuilder } from "discord.js";
import {
ATTENDANCE_CHANNEL_ID,
KNIGHT_ROLE_ID,
PROJECT_HACK_NIGHT_CHANNEL_ID,
} from "../utils/consts";

export default {
name: "attendance",
description: "Hourly attendance checks during Hack Night",
channel: PROJECT_HACK_NIGHT_CHANNEL_ID,
embed: (client: Client) =>
new EmbedBuilder()
.setColor(Colors.DarkOrange)
.setTitle("⏰ REMINDER: Hack Night Attendance Check")
.setDescription(
`<@${KNIGHT_ROLE_ID}> please do an attendance run and post the results in <#${ATTENDANCE_CHANNEL_ID}>!\n\nConfirm this has been done by reacting with a ✅ to this message.`,
),
crons: [
"0 21-23 * * 5", // At minute 0 past every hour from 21 through 23 on Friday.
"0 0-2 * * 6", // At minute 0 past every hour from 0 through 2 on Saturday.
],
};
22 changes: 22 additions & 0 deletions src/alerts/hack_night_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { type Client, Colors, EmbedBuilder } from "discord.js";
import {
ATTENDANCE_CHANNEL_ID,
KNIGHT_ROLE_ID,
PROJECT_HACK_NIGHT_CHANNEL_ID,
} from "../utils/consts";

export default {
name: "hack_night_setup",
description: "Setting up for Hack Night",
channel: PROJECT_HACK_NIGHT_CHANNEL_ID,
embed: (client: Client) =>
new EmbedBuilder()
.setColor(Colors.DarkOrange)
.setTitle("⏰ REMINDER: Set Up Hack Night")
.setDescription(
`<@${KNIGHT_ROLE_ID}> it's time to setup Hack Night! Make sure somebody is responsible for bringing the Hack Cart to Bechtel and setting up all the devices.\n\nRefer to https://puhack.horse/hn-setup for the checklist of things to do!\n\nConfirm this has been done by reacting with a ✅ to this message.`,
),
crons: [
"45 19 * * 5", // At 19:45 on Friday.
],
};
4 changes: 4 additions & 0 deletions src/alerts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import attendance from "./attendance";
import hack_night_setup from "./hack_night_setup";

export { attendance, hack_night_setup };
34 changes: 34 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
} from "discord.js";
import cron from "node-cron";

import * as alerts from "./alerts";
import { commands } from "./commands";
import { messageCreate } from "./events";

// TODO(rayhanadev): convert these into alerts
import { checkBirthdays } from "./utils/birthdays";
import {
createHackNightImagesThread,
Expand Down Expand Up @@ -76,6 +78,36 @@ client.on(Events.InteractionCreate, async (interaction) => {
}
});

const alertCronHandlers: cron.ScheduledTask[] = [];

for (const alert of Object.values(alerts)) {
console.log(`Setting up alert: \`${alert.name}\` - ${alert.description}`);
for (const schedule of alert.crons) {
console.log(` - ${schedule}`);
const handler = cron.schedule(schedule, async () => {
const channel = await client.channels.fetch(alert.channel);
if (!channel?.isTextBased() || !channel.isSendable()) {
console.error(
`Channel ${alert.channel} is not a text channel, skipping alert`,
);
return;
}

const message = await alert.embed(client);
if (!message) {
console.error(`Failed to create alert: ${alert.name}`);
return;
}

await channel.send({
embeds: [message],
});
});

alertCronHandlers.push(handler);
}
}

const checkBirthdaysTask = cron.schedule("1 0 * * *", checkBirthdays(client));
const createHackNightImagesThreadTask = cron.schedule(
"0 20 * * 5",
Expand All @@ -97,6 +129,8 @@ client.on(Events.ClientReady, (event) => {
checkBirthdaysTask.start();
createHackNightImagesThreadTask.start();
cleanupHackNightImagesThreadTask.start();

alertCronHandlers.forEach((handler) => handler.start());
});

client.on(messageCreate.eventType, async (message) => {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/consts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export const ADMINS = ["636701123620634653"];

export const LOUNGE_CHANNEL_ID = "809628073896443904";
export const HACK_NIGHT_CHANNEL_ID = "1020777328172859412";
export const ADMINS = ["636701123620634653"];
export const PROJECT_HACK_NIGHT_CHANNEL_ID = "1015596235685646357";
export const ATTENDANCE_CHANNEL_ID = "1287861645628149760";

export const ORGANIZER_ROLE_ID = "1012751663322382438";
export const KNIGHT_ROLE_ID = "1183270835469963354";
export const BISHOP_ROLE_ID = "1199891815780847647";
export const HACK_NIGHT_PHOTOGRAPHY_AWARD_ROLE_ID = "1340775295233560606";

export const EVERGREEN_CREATE_ISSUE_STRING = "evergreen it";