2023-06-26 23:48:52 +02:00
|
|
|
|
|
|
|
import { Message, MessageReaction, User } from "discord.js";
|
|
|
|
import { logger, newRequestId, noGuildId } from "../logger";
|
|
|
|
import { NONE_OF_THAT } from "../constants";
|
|
|
|
import { client } from "../..";
|
|
|
|
|
|
|
|
|
|
|
|
export const name = 'messageReactionAdd'
|
|
|
|
|
|
|
|
export async function execute(messageReaction: MessageReaction, user: User) {
|
2023-06-27 20:23:22 +02:00
|
|
|
if (user.id == client.user?.id) {
|
2023-06-26 23:48:52 +02:00
|
|
|
logger.info('Skipping bot reaction')
|
2023-06-27 20:23:22 +02:00
|
|
|
return
|
|
|
|
}
|
2023-06-27 20:19:42 +02:00
|
|
|
const requestId = newRequestId()
|
2023-06-26 23:48:52 +02:00
|
|
|
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) {
|
|
|
|
logger.info(`Reaction is NONE_OF_THAT. Handling`, { requestId, guildId })
|
|
|
|
return client.VoteController.handleNoneOfThatVote(messageReaction, user, reactedUponMessage, requestId, guildId)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|