From baefcf9bb9976080ddab893f170965004b9d1386 Mon Sep 17 00:00:00 2001 From: Sammy Date: Tue, 13 Jun 2023 21:12:32 +0200 Subject: [PATCH] add options for announcements --- server/commands/announce.ts | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/server/commands/announce.ts b/server/commands/announce.ts index 631351b..4fac196 100644 --- a/server/commands/announce.ts +++ b/server/commands/announce.ts @@ -1,4 +1,4 @@ -import { Guild, GuildMember, Message, MessageCreateOptions, MessageReaction, Role, TextChannel, User } from 'discord.js' +import { ApplicationCommandOptionType, Guild, GuildMember, Message, MessageCreateOptions, MessageReaction, Role, TextChannel, User } from 'discord.js' import { v4 as uuid } from 'uuid' import { client } from '../..' import { config } from '../configuration' @@ -13,12 +13,24 @@ let task: ScheduledTask export default new Command({ name: 'announce', description: 'Neues announcement im announcement Channel an alle senden.', - options: [], + options: [{ + name: "typ", + type: ApplicationCommandOptionType.String, + description:"Was für ein announcement?", + choices: [{name: "initial", value:"initial"},{name: "votepls", value:"votepls"},{name: "cancel", value:"cancel"}], + required: true + }], run: async (interaction: RunOptions) => { const command = interaction.interaction const requestId = uuid() const guildId = command.guildId! - logger.info("Got command for announcing!", { guildId, requestId }) + const announcementType = command.options.data.find(option => option.name.includes("typ")) + logger.info(`Got command for announcing ${announcementType?.value}!`, { guildId, requestId }) + + if(!announcementType) { + logger.error("Did not get an announcement type!", { guildId, requestId }) + return + } if (!isAdmin(command.member)) { logger.info(`Announcement was requested by ${command.member.displayName} but they are not an admin! Not sending announcement.`, { guildId, requestId }) @@ -26,8 +38,13 @@ export default new Command({ } else { logger.info(`User ${command.member.displayName} seems to be admin`) } - sendAnnouncement(guildId, requestId) - command.followUp("Ist rausgeschickt!") + + if((announcementType.value).includes("initial")) { + sendInitialAnnouncement(guildId, requestId) + command.followUp("Ist rausgeschickt!") + } else { + command.followUp(`${announcementType.value} ist aktuell noch nicht implementiert`) + } } }) @@ -35,15 +52,15 @@ function isAdmin(member: GuildMember): boolean { return member.roles.cache.find((role, _) => role.id === config.bot.jf_admin_role) !== undefined } -async function sendAnnouncement(guildId: string, requestId: string): Promise { - logger.info("Sending announcement") +async function sendInitialAnnouncement(guildId: string, requestId: string): Promise { + logger.info("Sending initial announcement") const announcementChannel: TextChannel = client.getAnnouncementChannelForGuild(guildId) - const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[announcement]")) + const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]")) currentPinnedAnnouncementMessages.forEach(async (message) => await message.unpin()) currentPinnedAnnouncementMessages.forEach(message => message.delete()) - const body = `[announcement] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett. + const body = `[initial] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett. Wir machen in Zukunft regelmäßig Watchparties! Falls du mitmachen möchtest, reagiere einfach auf diesen Post mit 🎫, dann bekommst du automatisch eine Rolle zugewiesen und wirst benachrichtigt sobald es in der Zukunft weitere Watchparties und Filme zum abstimmen gibt.