Skip to content

Commit f390b54

Browse files
committed
freakperations meetings are a go...
1 parent 31775e4 commit f390b54

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/hooks/calendar.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const TEST_DATE = undefined;
4444
// Google maps API URL
4545
const today = new Date(TEST_DATE ?? new Date().toLocaleDateString());
4646
const nextWeek = new Date(today);
47+
let operationsDate: Date | undefined = undefined; // to pass into the hook
4748
nextWeek.setDate(today.getDate() + 8);
4849
console.log("Today: ", today, "\nNext Week: ", nextWeek);
4950

@@ -106,6 +107,7 @@ function removeHTMLTags(str: string) {
106107

107108
// date obj to string
108109
function dateToString(date: Date) {
110+
date = new Date(date.toLocaleDateString());
109111
const day = date.getDate();
110112
const month = date.getMonth() + 1;
111113
const year = date.getFullYear();
@@ -275,12 +277,29 @@ async function getValidEvents(data: GoogleCalendarDataProps[]) {
275277
allEvents.map((obj: GoogleCalendarDataProps) => {
276278
// gets the event date based on two fields from the API
277279
// also sets this to local time zone
278-
const eventDate = new Date(
280+
let eventDate = new Date(
279281
new Date(
280282
obj.start.dateTime ?? obj.start.date ?? "TBA"
281283
).toLocaleDateString()
282284
);
283285

286+
// the ops meeting event caused so many issues.
287+
// we decided to hardcode it, and so,
288+
// this sets the ops meeting's date to the monday within
289+
// the next 7 days (or today if today's the meeting).
290+
if(obj.summary.includes("Operations Meeting")) {
291+
if (today.getDay() == 1) {
292+
eventDate = today;
293+
operationsDate = eventDate;
294+
} else {
295+
const daysOfWeek = today.getDay() + 1;
296+
const daysUntilMonday = (8 - daysOfWeek) % 7;
297+
eventDate = new Date(today);
298+
eventDate.setDate(today.getDate() + daysUntilMonday);
299+
operationsDate = eventDate;
300+
}
301+
}
302+
284303
console.log(today, tomorrow, nextWeek);
285304
if (isSameDay(today, eventDate, `${obj.summary} TODAY`)) {
286305
validEvents.push({
@@ -320,10 +339,14 @@ async function hookLogic(client: Client, webhook: WebhookClient) {
320339
if (events.length === 0) {
321340
return;
322341
} else if (events.length >= 1) {
323-
const messageDay = new Date(today);
324-
messageDay.setDate(today.getDate() + 1);
342+
let messageDate = today;
343+
if (TEST_DATE) {
344+
messageDate = new Date(TEST_DATE);
345+
messageDate.setDate(messageDate.getDate() + 1);
346+
} // for some reason its one day behind when using a test date.
347+
325348
webhook.send(
326-
`Hey <@&${config.CALENDAR_ROLE_ID}>, it's ${dateToString(messageDay)}, here are some reminders about our upcoming events!\n`
349+
`Hey <@&${config.CALENDAR_ROLE_ID}>, it's ${dateToString(messageDate)}, here are some reminders about our upcoming events!\n`
327350
);
328351
}
329352

@@ -374,7 +397,9 @@ async function hookLogic(client: Client, webhook: WebhookClient) {
374397
if (date.date) {
375398
fields.splice(1, 0, {
376399
name: "Date",
377-
value: `${date.date}`,
400+
value: `${
401+
operationsDate ? dateToString(operationsDate) : date.date
402+
}`, // if date is an ops meeting, set it to that specific date
378403
inline: false,
379404
});
380405
}
@@ -417,7 +442,7 @@ export async function execute(client: Client) {
417442

418443
try {
419444
// Check events on a schedule
420-
cron.schedule("0 8 * * *", async () => hookLogic(client, preWebhook));
445+
cron.schedule("15 10 * * *", async () => hookLogic(client, preWebhook));
421446
cron.schedule("0 12 * * *", async () => hookLogic(client, webhook));
422447
// Catch any errors
423448
} catch (err: unknown) {

0 commit comments

Comments
 (0)