Add automatic creation of vote message with random movies #16
|
@ -5,6 +5,8 @@ import { jellyfinHandler } from "../..";
|
|||
import { closePoll } from "../commands/closepoll";
|
||||
import { config } from "../configuration";
|
||||
import { logger } from "../logger";
|
||||
import toDate from "date-fns/fp/toDate";
|
||||
import { addDays, isAfter, isBefore } from "date-fns";
|
||||
|
||||
|
||||
export const name = 'guildScheduledEventCreate'
|
||||
|
@ -73,10 +75,14 @@ async function checkForPollsToClose(event: GuildScheduledEvent): Promise<void> {
|
|||
logger.error("Event does not have a scheduled start time. Cancelling", { guildId: event.guildId, requestId })
|
||||
return
|
||||
kenobi marked this conversation as resolved
|
||||
}
|
||||
if ((updatedEvent.scheduledStartTimestamp - Date.now()) <= (1000 * 60 * 60 * 24 * 2)) {
|
||||
|
||||
const eventDate: Date = toDate(updatedEvent.scheduledStartTimestamp)
|
||||
const closePollDate: Date = addDays(eventDate, -2)
|
||||
|
||||
if (isAfter(Date.now(), closePollDate)) {
|
||||
logger.info("Less than two days until event. Closing poll", { guildId: event.guildId, requestId })
|
||||
closePoll(event.guild, requestId)
|
||||
} else {
|
||||
logger.info(`ScheduledStart: ${updatedEvent.scheduledStartTimestamp}. Now: ${Date.now()}`, { guildId: event.guildId, requestId })
|
||||
logger.info(`ScheduledStart: ${closePollDate}. Now: ${toDate(Date.now())}`, { guildId: event.guildId, requestId })
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
The npm library date-fns has some very nice functions for date manipulation.
It has superseded Moment.js in almost all cases
fixed