prevent poll close if event is less than 24h old
Build a docker image for node-jellyfin-role-bot / build-docker-image (push) Successful in 1m15s Details

This commit is contained in:
Sammy 2023-06-17 13:03:48 +02:00
parent 07849d331a
commit 4cc332820f
2 changed files with 10 additions and 2 deletions

View File

@ -164,6 +164,14 @@ export async function checkForPollsToClose(guild: Guild): Promise<void> {
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)

View File

@ -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])))
}