40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { GuildScheduledEvent, TextChannel } from "discord.js";
|
|
import { v4 as uuid } from "uuid";
|
|
import { client, yavinJellyfinHandler } from "../..";
|
|
import { Maybe } from "../interfaces";
|
|
import { logger } from "../logger";
|
|
|
|
|
|
export const name = 'guildScheduledEventCreate'
|
|
|
|
export async function execute(event: GuildScheduledEvent) {
|
|
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
|
|
}
|
|
const sentMessageText = client.voteController.createVoteMessageText(event.id, event.scheduledStartAt, movies, event.guild?.id ?? "", requestId)
|
|
const sentMessage = await client.voteController.sendVoteMessage(sentMessageText, movies.length, announcementChannel)
|
|
|
|
sentMessage.pin()
|
|
}
|
|
}
|
|
|