Skip to content

Commit

Permalink
discord: make sure to destroy client (#10)
Browse files Browse the repository at this point in the history
* make sure to destroy client

* fix double date conversion

* fix timezone

---------

Co-authored-by: Pete Stenger <[email protected]>
  • Loading branch information
devksingh4 and reteps authored Sep 2, 2024
1 parent 071fc6d commit 53cbef0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/functions/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const updateDiscord = async (

// Handle creation or update
const { title, description, start, end, location, host } = event;
const date = moment(start).tz("America/Chicago").format("YYYY-MM-DD");
const calendarURL = `https://www.acm.illinois.edu/calendar?id=${id}&date=${date}`;
const dateStart = moment(start).format("YYYY-MM-DD");
const calendarURL = `https://www.acm.illinois.edu/calendar?id=${id}&date=${dateStart}`;
const fullDescription = `${calendarURL}\n${description}`;
const fullTitle = title.toLowerCase().includes(host.toLowerCase())
? title
Expand All @@ -81,8 +81,8 @@ export const updateDiscord = async (
privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly,
name: fullTitle,
description: fullDescription,
scheduledStartTime: moment(start).tz("America/Chicago").toDate(),
scheduledEndTime: end && moment(end).tz("America/Chicago").toDate(),
scheduledStartTime: moment(start).toDate(),
scheduledEndTime: end && moment(end).toDate(),
entityMetadata: {
location,
},
Expand All @@ -93,18 +93,17 @@ export const updateDiscord = async (
logger.warn(`Refusing to edit non-bot event "${title}"`);
} else {
await guild.scheduledEvents.edit(existingMetadata.id, options);
return options;
}
} else {
if (options.scheduledStartTime < new Date()) {
logger.warn(`Refusing to create past event "${title}"`);
} else {
await guild.scheduledEvents.create(options);
return options;
}
}

await client.destroy();
return options;
});

const token = secretApiConfig["discord_bot_token"];
Expand Down

0 comments on commit 53cbef0

Please sign in to comment.