2023-06-23 15:51:07 +02:00
|
|
|
import { GuildScheduledEvent, TextChannel } from "discord.js";
|
2023-06-23 14:37:29 +02:00
|
|
|
import { v4 as uuid } from "uuid";
|
2023-06-23 15:51:07 +02:00
|
|
|
import { client } from "../..";
|
2023-06-23 14:37:29 +02:00
|
|
|
import { config } from "../configuration";
|
2023-06-23 15:51:07 +02:00
|
|
|
import { createDateStringFromEvent } from "../helper/dateHelper";
|
2023-06-23 14:37:29 +02:00
|
|
|
import { Maybe } from "../interfaces";
|
|
|
|
import { logger } from "../logger";
|
|
|
|
|
|
|
|
|
|
|
|
export const name = 'guildScheduledEventCreate'
|
|
|
|
|
|
|
|
export async function execute(event: GuildScheduledEvent) {
|
2023-06-24 21:09:56 +02:00
|
|
|
const guildId = event.guildId
|
|
|
|
const requestId = uuid()
|
|
|
|
try {
|
|
|
|
if (!event.description) {
|
|
|
|
logger.debug("Got GuildScheduledEventCreate event. But has no description. Aborting.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.description.includes("!wp")) {
|
|
|
|
logger.info("Got manual create event of watchparty event!", { guildId, requestId })
|
|
|
|
if (event.description.includes("!private")) {
|
|
|
|
logger.info("Event description contains \"!private\". Won't announce.", { guildId, requestId })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const channel: Maybe<TextChannel> = client.getAnnouncementChannelForGuild(guildId)
|
|
|
|
|
|
|
|
if (!channel) {
|
|
|
|
logger.error("Could not obtain announcement channel. Aborting announcement.", { guildId, requestId })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = `[Watchparty] https://discord.com/events/${event.guildId}/${event.id} \nHey <@&${config.bot.announcement_role}>, wir gucken ${event.name} ${createDateStringFromEvent(event, guildId, requestId)}`
|
|
|
|
|
|
|
|
channel.send(message)
|
|
|
|
} else {
|
|
|
|
logger.debug("Got GuildScheduledEventCreate event but no !wp in description. Not creating manual wp announcement.", { guildId, requestId })
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
// sendFailureDM(error)
|
|
|
|
logger.error(<string>error, { guildId, requestId })
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|