fix/movie_names_and_background_task #46

Merged
kenobi merged 5 commits from fix/movie_names_and_background_task into master 2023-06-19 11:29:04 +02:00
Showing only changes of commit 670a64af22 - Show all commits

View File

@ -1,4 +1,4 @@
import { addDays, format, isAfter, toDate } from 'date-fns'
import { addDays, differenceInDays, format, isAfter, toDate } from 'date-fns'
import { Guild, GuildScheduledEvent, GuildScheduledEventEditOptions, GuildScheduledEventSetStatusArg, GuildScheduledEventStatus, Message, MessageCreateOptions, TextChannel } from 'discord.js'
import { v4 as uuid } from 'uuid'
import { client } from '../..'
@ -23,7 +23,7 @@ export default new Command({
}
const guildId = command.guildId
logger.info("Got command for closing poll!", { guildId, requestId })
command.followUp("Alles klar, beende die Umfrage :)")
closePoll(command.guild, requestId)
}
@ -34,7 +34,7 @@ export async function closePoll(guild: Guild, requestId: string) {
logger.info("stopping poll", { guildId, requestId })
const announcementChannel: Maybe<TextChannel> = client.getAnnouncementChannelForGuild(guildId)
if(!announcementChannel) {
if (!announcementChannel) {
logger.error("Could not find the textchannel. Unable to close poll.", { guildId, requestId })
return
}
@ -55,16 +55,16 @@ export async function closePoll(guild: Guild, requestId: string) {
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
const votes = await (await getVotesByEmote(lastMessage, guildId, requestId))
.sort((a, b) => b.count - a.count)
.sort((a, b) => b.count - a.count)
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
logger.info("Deleting vote message")
await lastMessage.delete()
const event = await getEvent(guild, guild.id, requestId)
if(event) {
if (event) {
updateEvent(event, votes, guild, guildId, requestId)
sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
}
@ -82,7 +82,7 @@ async function sendVoteClosedMessage(event: GuildScheduledEvent, movie: string,
}
const announcementChannel = client.getAnnouncementChannelForGuild(guildId)
logger.info("Sending vote closed message.", { guildId, requestId })
if(!announcementChannel) {
if (!announcementChannel) {
logger.error("Could not find announcement channel. Please fix!", { guildId, requestId })
return
}
@ -151,10 +151,10 @@ export async function checkForPollsToClose(guild: Guild): Promise<void> {
const requestId = uuid()
logger.info(`Automatic check for poll closing.`, { guildId: guild.id, requestId })
const events = (await guild.scheduledEvents.fetch()).filter(event => event.name.toLocaleLowerCase().includes("voting offen")).map(event => event)
if(events.length > 1) {
if (events.length > 1) {
logger.error("Handling more than one Event is not implemented yet. Found more than one poll to close")
return
} else if(events.length == 0) {
} else if (events.length == 0) {
logger.info("Could not find any events. Cancelling", { guildId: guild.id, requestId })
}
@ -165,14 +165,14 @@ export async function checkForPollsToClose(guild: Guild): Promise<void> {
}
const createDate: Date = toDate(updatedEvent.createdTimestamp)
const closePollMinDate: Date = addDays(createDate, 1)
const eventDate: Date = toDate(updatedEvent.scheduledStartTimestamp)
const difference: number = differenceInDays(createDate, eventDate)
kenobi marked this conversation as resolved Outdated

This would also meant that it is not possible to start an impromptu poll for a Watchparty 'tonight'.
Maybe it's possible to also check if the post is older than 24 hours?

This would also meant that it is not possible to start an impromptu poll for a Watchparty 'tonight'. Maybe it's possible to also check if the post is older than 24 hours?

I think this would better be solved by !noautoclose or something when making the !nextwp? Could be carried to the voting offen event or the message to parse for that?

I think this would better be solved by !noautoclose or something when making the !nextwp? Could be carried to the voting offen event or the message to parse for that?

This would increase 'friction' I feel.
An easy thing for users to forget to do and be surprised by how the bot acts.
I would propose that we could do both.
If the distance between poll post date and event date is less than 2 days it does not auto close, but the poll creation would need to be adjusted to contain guidance on how to close the poll manually for the creator of the event.
'Normal' poll posts would be made a week in advance to a watch party so the 2-day auto close would be fine.

This would increase 'friction' I feel. An easy thing for users to forget to do and be surprised by how the bot acts. I would propose that we could do both. If the distance between poll post date and event date is less than 2 days it does not auto close, but the poll creation would need to be adjusted to contain guidance on how to close the poll manually for the creator of the event. 'Normal' poll posts would be made a week in advance to a watch party so the 2-day auto close would be fine.

Implemented check to see if less than or equal to two days between start and create date of event

Implemented check to see if less than or equal to two days between start and create date of event
if(isAfter(closePollMinDate, Date.now())) {
logger.info("Event is less than 24h old. Not closing poll!", { guildId: guild.id, requestId })
if (difference <= 2) {
logger.info("Less than two days between event create and event start. Not closing poll.", { guildId: guild.id, requestId })
return
}
const eventDate: Date = toDate(updatedEvent.scheduledStartTimestamp)
const closePollDate: Date = addDays(eventDate, -2)
if (isAfter(Date.now(), closePollDate)) {