jellyfin-discord-bot/server/helper/messageIdentifiers.ts

21 lines
865 B
TypeScript
Raw Permalink Normal View History

2023-06-25 01:57:30 +02:00
import { Message } from "discord.js";
// branded types to differentiate objects of identical Type but different contents
export type VoteEndMessage = Message<true> & { readonly __brand: 'voteend' }
export type AnnouncementMessage = Message<true> & { readonly __brand: 'announcement' }
export type VoteMessage = Message<true> & { readonly __brand: 'vote' }
export type KnownDiscordMessage = VoteMessage | VoteEndMessage | AnnouncementMessage
2023-11-18 18:26:45 +01:00
export function isVoteMessage(message: Message): message is VoteMessage {
return message.cleanContent.includes('[Abstimmung]')
2023-06-25 02:20:34 +02:00
}
2023-11-18 18:26:45 +01:00
export function isInitialAnnouncement(message: Message): message is AnnouncementMessage {
return message.cleanContent.includes("[initial]")
2023-06-25 02:20:34 +02:00
}
2023-11-18 18:26:45 +01:00
export function isVoteEndedMessage(message: Message): message is VoteEndMessage {
return message.cleanContent.includes("[Abstimmung beendet]")
2023-06-25 01:57:30 +02:00
}