diff --git a/server/commands/announce.ts b/server/commands/announce.ts index 4a6eff3..e803177 100644 --- a/server/commands/announce.ts +++ b/server/commands/announce.ts @@ -6,6 +6,7 @@ import { Maybe } from '../interfaces' import { logger } from '../logger' import { Command } from '../structures/command' import { RunOptions } from '../types/commandTypes' +import { messageIsInitialAnnouncement } from '../helper/messageIdentifiers' export default new Command({ name: 'announce', @@ -61,7 +62,7 @@ async function sendInitialAnnouncement(guildId: string, requestId: string): Prom return } - const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]")) + const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => messageIsInitialAnnouncement(message)) currentPinnedAnnouncementMessages.forEach(async (message) => await message.unpin()) currentPinnedAnnouncementMessages.forEach(message => message.delete()) diff --git a/server/commands/closepoll.ts b/server/commands/closepoll.ts index 7cf05c2..fea96fe 100644 --- a/server/commands/closepoll.ts +++ b/server/commands/closepoll.ts @@ -8,6 +8,7 @@ import { Maybe } from '../interfaces' import { logger } from '../logger' import { Command } from '../structures/command' import { RunOptions } from '../types/commandTypes' +import { messageIsVoteEndedMessage, messageIsVoteMessage } from '../helper/messageIdentifiers' export default new Command({ name: 'closepoll', @@ -41,7 +42,7 @@ export async function closePoll(guild: Guild, requestId: string) { const messages: Message[] = (await announcementChannel.messages.fetch()) //todo: fetch only pinned messages .map((value) => value) - .filter(message => !message.cleanContent.includes("[Abstimmung beendet]") && message.cleanContent.includes("[Abstimmung]")) + .filter(message => !messageIsVoteEndedMessage(message) && messageIsVoteMessage(message)) .sort((a, b) => b.createdTimestamp - a.createdTimestamp) if (!messages || messages.length <= 0) { diff --git a/server/events/deleteAnnouncementsWhenWPEnds.ts b/server/events/deleteAnnouncementsWhenWPEnds.ts index 8d7acfe..9b1a0b0 100644 --- a/server/events/deleteAnnouncementsWhenWPEnds.ts +++ b/server/events/deleteAnnouncementsWhenWPEnds.ts @@ -2,6 +2,7 @@ import { Collection, GuildScheduledEvent, GuildScheduledEventStatus, Message } f import { v4 as uuid } from "uuid"; import { client } from "../.."; import { logger } from "../logger"; +import { messageIsInitialAnnouncement } from "../helper/messageIdentifiers"; export const name = 'guildScheduledEventUpdate' @@ -25,7 +26,7 @@ export async function execute(oldEvent: GuildScheduledEvent, newEvent: GuildSche const events = await newEvent.guild.scheduledEvents.fetch() - const wpAnnouncements = (await announcementChannel.messages.fetch()).filter(message => !message.cleanContent.includes("[initial]")) + const wpAnnouncements = (await announcementChannel.messages.fetch()).filter(message => !messageIsInitialAnnouncement(message)) const announcementsWithoutEvent = filterAnnouncementsByPendingWPs(wpAnnouncements, events) logger.info(`Deleting ${announcementsWithoutEvent.length} announcements.`, { guildId, requestId }) announcementsWithoutEvent.forEach(message => message.delete()) diff --git a/server/structures/client.ts b/server/structures/client.ts index 10be4af..4f4047f 100644 --- a/server/structures/client.ts +++ b/server/structures/client.ts @@ -9,6 +9,7 @@ import { JellyfinHandler } from "../jellyfin/handler"; import { logger } from "../logger"; import { CommandType } from "../types/commandTypes"; import { checkForPollsToClose } from "../commands/closepoll"; +import { messageIsInitialAnnouncement } from "../helper/messageIdentifiers"; @@ -136,7 +137,7 @@ export class ExtendedClient extends Client { } this.announcementRoleHandlerTask.set(guild.id, schedule("*/10 * * * * *", async () => { const requestId = uuid() - const messages = (await textChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]")) + const messages = (await textChannel.messages.fetchPinned()).filter(message => messageIsInitialAnnouncement(message)) if (messages.size > 1) { logger.error("More than one pinned announcement Messages found. Unable to know which one people react to. Please fix!", { guildId: guild.id, requestId })