Skip to content
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
67 changes: 67 additions & 0 deletions src/crons/attendance-creation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { type Client, ThreadAutoArchiveDuration } from "discord.js";
import { schedule } from "node-cron";

import {
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
HACK_NIGHT_ATTENDANCE_ROLE_ID,
} from "../utils/consts";

export default async function startTask(client: Client) {
const task = schedule("0 20 * * 5", handler(client));
return task.start();
}

function handler(client: Client) {
return async () => {
const channel = client.channels.cache.get(
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
);

if (!channel) {
console.error("Could not find channel");
return;
}

if (!channel.isSendable()) {
console.error("Cannot send messages channel");
return;
}

const message = await channel.send({
content: `<@&${HACK_NIGHT_ATTENDANCE_ROLE_ID}>: Put attendance for the night here! Please rename the thread to tonight's version number.`,
});

if (!message) {
console.error("Could not create Hack Night attendance thread");
return;
}

await message.pin();

const dateObj = new Date();
const date = `${`${1 + dateObj.getMonth()}`.padStart(2, "0")}/${`${dateObj.getDate()}`.padStart(2, "0")}`;

await message.startThread({
name: `Hack Night Attendance - ${date}`,
autoArchiveDuration: ThreadAutoArchiveDuration.OneDay,
});

const pinnedMessage = await channel.messages.fetch({ limit: 1 });

if (!pinnedMessage) {
console.error("Could not fetch last message");
return;
}

const systemMessage = pinnedMessage.first();

if (!systemMessage) {
console.error("Could not find last message");
return;
}

await systemMessage.delete();

console.log("Created Hack Night attendance thread");
};
}
75 changes: 75 additions & 0 deletions src/crons/attendance-reminder-friday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ChannelType, type Client } from "discord.js";
import { schedule } from "node-cron";

import {
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
HACK_NIGHT_ATTENDANCE_ROLE_ID,
} from "../utils/consts";

// Every 15 Minutes starting at 9pm
export default async function startTask(client: Client) {
const task = schedule("*/15 21-23 * * 5", handler(client));
return task.start();
}

function handler(client: Client) {
return async () => {
const channel = client.channels.cache.get(
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
);

if (!channel) {
console.error("Could not find channel");
return;
}

if (!channel.isSendable()) {
console.error("Cannot send messages to channel");
return;
}

if (channel.type !== ChannelType.GuildText) {
console.error("Cannot create threads in channel");
return;
}

const threads = await channel.threads.fetchActive();

if (!threads) {
console.error("Could not fetch active threads");
return;
}

const hackNightAttendanceThread = threads.threads
.filter((t) => {
return t.name.startsWith("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches all threads, is this intentional? If so probably can remove this filter haha

})
.sorted((a, b) => {
if (!a.createdTimestamp || !b.createdTimestamp) return 0;
return b.createdTimestamp - a.createdTimestamp;
})
.first();

if (!hackNightAttendanceThread) {
console.error("Could not find latest thread");
return;
}

const lastMessage = channel.lastMessage;

if (lastMessage) {
const timeSent = lastMessage.createdAt;

// If most recent message was sent more than 1.5 hours ago
if (
new Date().getTime() - timeSent.getTime() >
1.5 * 60 * 60 * 1000
) {
}
}
Comment on lines +60 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code this does nothing


hackNightAttendanceThread.send({
content: `<@&${HACK_NIGHT_ATTENDANCE_ROLE_ID}>: Last attendance taken (or attendance reminder) was more than an hour and a half ago!`,
});
};
Comment on lines +71 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be awaited methinks

}
75 changes: 75 additions & 0 deletions src/crons/attendance-reminder-saturday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ChannelType, type Client } from "discord.js";
import { schedule } from "node-cron";

import {
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
HACK_NIGHT_ATTENDANCE_ROLE_ID,
} from "../utils/consts";

// Every 15 Minutes until 2am
export default async function startTask(client: Client) {
const task = schedule("*/15 0-2 * * 6", handler(client));
return task.start();
}

function handler(client: Client) {
return async () => {
const channel = client.channels.cache.get(
HACK_NIGHT_ATTENDANCE_CHANNEL_ID,
);

if (!channel) {
console.error("Could not find channel");
return;
}

if (!channel.isSendable()) {
console.error("Cannot send messages to channel");
return;
}

if (channel.type !== ChannelType.GuildText) {
console.error("Cannot create threads in channel");
return;
}

const threads = await channel.threads.fetchActive();

if (!threads) {
console.error("Could not fetch active threads");
return;
}

const hackNightAttendanceThread = threads.threads
.filter((t) => {
return t.name.startsWith("");
})
Comment on lines +44 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous

.sorted((a, b) => {
if (!a.createdTimestamp || !b.createdTimestamp) return 0;
return b.createdTimestamp - a.createdTimestamp;
})
.first();

if (!hackNightAttendanceThread) {
console.error("Could not find latest thread");
return;
}

const lastMessage = channel.lastMessage;

if (lastMessage) {
const timeSent = lastMessage.createdAt;

// If most recent message was sent more than 1.5 hours ago
if (
new Date().getTime() - timeSent.getTime() >
1.5 * 60 * 60 * 1000
) {
}
}
Comment on lines +60 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous


hackNightAttendanceThread.send({
content: `<@&${HACK_NIGHT_ATTENDANCE_ROLE_ID}>: Last attendance taken was more than an hour and a half ago!`,
});
};
Comment on lines +71 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous

}
11 changes: 10 additions & 1 deletion src/crons/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import hackNightPhotosCleanup from "./hack-night-photo-cleanup";
import hackNightPhotos from "./hack-night-photos";
import hackNightAttendanceInit from "./attendance-creation";
import hackNightAttendanceReminderFriday from "./attendance-reminder-friday";
import hackNightAttendanceReminderSaturday from "./attendance-reminder-saturday";

export const tasks = [hackNightPhotos, hackNightPhotosCleanup];
export const tasks = [
hackNightPhotos,
hackNightPhotosCleanup,
hackNightAttendanceInit,
hackNightAttendanceReminderFriday,
hackNightAttendanceReminderSaturday,
];
10 changes: 6 additions & 4 deletions src/utils/consts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export const LOUNGE_CHANNEL_ID = "809628073896443904";
export const HACK_NIGHT_CHANNEL_ID = "1020777328172859412";
export const ADMINS = ["636701123620634653"];
export const HACK_NIGHT_ATTENDANCE_CHANNEL_ID = "1287861645628149760";
export const HACK_NIGHT_ATTENDANCE_ROLE_ID = "1183270835469963354";
export const ORGANIZER_ROLE_ID = "1012751663322382438";
export const BISHOP_ROLE_ID = "1199891815780847647";
export const HACK_NIGHT_PHOTOGRAPHY_AWARD_ROLE_ID = "1340775295233560606";
export const EVERGREEN_CREATE_ISSUE_STRING = "evergreen it";
export const INTERNAL_CATEGORIES = [
"809620177347411998",
"1290013838955249734",
"1082077318329143336",
"938975633885782037",
"809620177347411998",
"1290013838955249734",
"1082077318329143336",
"938975633885782037",
];
export const WACKY_ROLE_ID = "1419119560627458129";