From 4cc332820fa06c25bc4c2fea5ba1b138462eaf23 Mon Sep 17 00:00:00 2001 From: Sammy Date: Sat, 17 Jun 2023 13:03:48 +0200 Subject: [PATCH] prevent poll close if event is less than 24h old --- server/commands/closepoll.ts | 8 ++++++++ server/structures/client.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/commands/closepoll.ts b/server/commands/closepoll.ts index 1de84bb..88c5f90 100644 --- a/server/commands/closepoll.ts +++ b/server/commands/closepoll.ts @@ -164,6 +164,14 @@ export async function checkForPollsToClose(guild: Guild): Promise { return } + const createDate: Date = toDate(updatedEvent.createdTimestamp) + const closePollMinDate: Date = addDays(createDate, 1) + + if(isAfter(closePollMinDate, Date.now())) { + logger.info("Event is less than 24h old. Not closing poll!", { guildId: guild.id, requestId }) + return + } + const eventDate: Date = toDate(updatedEvent.scheduledStartTimestamp) const closePollDate: Date = addDays(eventDate, -2) diff --git a/server/structures/client.ts b/server/structures/client.ts index 6d74663..fae18b3 100644 --- a/server/structures/client.ts +++ b/server/structures/client.ts @@ -75,7 +75,7 @@ export class ExtendedClient extends Client { this.cacheUsers(guilds) await this.cacheAnnouncementServer(guilds) this.startAnnouncementRoleBackgroundTask(guilds) - this.startPollCloceBackgroundTasks() + this.startPollCloseBackgroundTasks() }) } catch (error) { logger.info(`Error refreshing slash commands: ${error}`) @@ -173,7 +173,7 @@ export class ExtendedClient extends Client { task.stop() } - private async startPollCloceBackgroundTasks() { + private async startPollCloseBackgroundTasks() { for(const guild of this.guilds.cache) { this.pollCloseBackgroundTasks.set(guild[1].id, schedule("0 * * * * *", () => checkForPollsToClose(guild[1]))) }