jellyfin-discord-bot/server/events/handleMessageReactionAdd.ts
kenobi c351e27fdd
All checks were successful
Compile the repository / compile (pull_request) Successful in 1m15s
Run unit tests / test (pull_request) Successful in 1m26s
perform vote message check in reaction handler
2023-06-27 20:23:36 +02:00

38 lines
1.4 KiB
TypeScript

import { Message, MessageReaction, User } from "discord.js";
import { logger, newRequestId, noGuildId } from "../logger";
import { NONE_OF_THAT } from "../constants";
import { client } from "../..";
import { messageIsVoteMessage } from "../helper/messageIdentifiers";
export const name = 'messageReactionAdd'
export async function execute(messageReaction: MessageReaction, user: User) {
if (user.id == client.user?.id) {
logger.info('Skipping bot reaction')
return
}
const requestId = newRequestId()
const guildId = messageReaction.message.inGuild() ? messageReaction.message.guildId : noGuildId
const reactedUponMessage: Message = messageReaction.message.partial ? await messageReaction.message.fetch() : messageReaction.message
if (!messageReaction.message.guild) {
logger.warn(`Received messageReactionAdd on non-guild message.`, { requestId })
return
}
logger.info(`Got reaction on message`, { requestId, guildId })
//logger.debug(`reactedUponMessage payload: ${JSON.stringify(reactedUponMessage)}`)
logger.info(`emoji: ${messageReaction.emoji.toString()}`)
if (messageReaction.emoji.toString() === NONE_OF_THAT) {
if (messageIsVoteMessage(reactedUponMessage)) {
logger.info(`Reaction is NONE_OF_THAT on a vote message. Handling`, { requestId, guildId })
return client.VoteController.handleNoneOfThatVote(messageReaction, user, reactedUponMessage, requestId, guildId)
}
}
return
}