2023-06-13 23:15:03 +02:00
import { GuildScheduledEvent , Message , MessageCreateOptions , TextChannel } from "discord.js" ;
2023-06-10 14:23:10 +02:00
import { v4 as uuid } from "uuid" ;
2023-06-15 22:33:22 +02:00
import { client , yavinJellyfinHandler } from "../.." ;
2023-06-10 14:23:10 +02:00
import { config } from "../configuration" ;
2023-06-23 15:51:07 +02:00
import { createDateStringFromEvent } from "../helper/dateHelper" ;
2023-06-15 21:56:15 +02:00
import { Maybe } from "../interfaces" ;
2023-06-15 22:33:22 +02:00
import { logger } from "../logger" ;
2023-06-25 22:46:46 +02:00
import { Emotes , NONE_OF_THAT } from "../constants" ;
2023-06-10 14:23:10 +02:00
export const name = 'guildScheduledEventCreate'
export async function execute ( event : GuildScheduledEvent ) {
2023-06-24 21:09:56 +02:00
const requestId = uuid ( )
if ( event . name . toLowerCase ( ) . includes ( "!nextwp" ) ) {
logger . info ( "Event was a placeholder event to start a new watchparty and voting. Creating vote!" , { guildId : event.guildId , requestId } )
logger . debug ( "Renaming event" , { guildId : event.guildId , requestId } )
event . edit ( { name : "Watchparty - Voting offen" } )
const movies = await yavinJellyfinHandler . getRandomMovieNames ( 5 , event . guildId , requestId )
logger . info ( ` Got ${ movies . length } random movies. Creating voting ` , { guildId : event.guildId , requestId } )
logger . debug ( ` Movies: ${ JSON . stringify ( movies ) } ` , { guildId : event.guildId , requestId } )
const announcementChannel : Maybe < TextChannel > = client . getAnnouncementChannelForGuild ( event . guildId )
if ( ! announcementChannel ) {
logger . error ( "Could not find announcement channel. Aborting" , { guildId : event.guildId , requestId } )
return
}
logger . debug ( ` Found channel ${ JSON . stringify ( announcementChannel , null , 2 ) } ` , { guildId : event.guildId , requestId } )
if ( ! event . scheduledStartAt ) {
logger . info ( "EVENT DOES NOT HAVE STARTDATE; CANCELLING" , { guildId : event.guildId , requestId } )
return
}
let message = ` [Abstimmung] für https://discord.com/events/ ${ event . guildId } / ${ event . id } \ n<@& ${ config . bot . announcement_role } > Es gibt eine neue Abstimmung für die nächste Watchparty ${ createDateStringFromEvent ( event , event . guildId , requestId ) } ! Stimme hierunter für den nächsten Film ab! \ n `
for ( let i = 0 ; i < movies . length ; i ++ ) {
message = message . concat ( Emotes [ i ] ) . concat ( ": " ) . concat ( movies [ i ] ) . concat ( "\n" )
}
message = message . concat ( NONE_OF_THAT ) . concat ( ": Wenn dir nichts davon gefällt." )
const options : MessageCreateOptions = {
allowedMentions : { parse : [ "roles" ] } ,
content : message ,
}
const sentMessage : Message < true > = await ( await announcementChannel . fetch ( ) ) . send ( options )
for ( let i = 0 ; i < movies . length ; i ++ ) {
sentMessage . react ( Emotes [ i ] )
}
sentMessage . react ( NONE_OF_THAT )
// sentMessage.pin() //todo: uncomment when bot has permission to pin messages. Also update closepoll.ts to only fetch pinned messages
}
2023-06-10 22:53:11 +02:00
}