Add automatic creation of vote message with random movies #16

Merged
kenobi merged 11 commits from feat/voting into master 2023-06-12 21:00:17 +02:00
Showing only changes of commit 40d220ed7b - Show all commits

View File

@ -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
Review

The npm library date-fns has some very nice functions for date manipulation.
It has superseded Moment.js in almost all cases

The npm library date-fns has some very nice functions for date manipulation. It has superseded Moment.js in almost all cases
Review

fixed

fixed
}
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 })
}
}