2023-06-26 23:48:52 +02:00
|
|
|
|
|
|
|
import { Message, MessageReaction, User } from "discord.js";
|
|
|
|
import { logger, newRequestId, noGuildId } from "../logger";
|
2023-11-19 20:22:14 +01:00
|
|
|
import { Emoji, ValidVoteEmotes, NONE_OF_THAT } from "../constants";
|
2023-06-26 23:48:52 +02:00
|
|
|
import { client } from "../..";
|
2023-07-05 22:55:24 +02:00
|
|
|
import { isInitialAnnouncement, isVoteMessage } from "../helper/messageIdentifiers";
|
2023-06-26 23:48:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
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.info(`emoji: ${messageReaction.emoji.toString()}`)
|
2023-06-27 20:23:36 +02:00
|
|
|
|
2023-11-19 20:22:14 +01:00
|
|
|
if (!Object.values(ValidVoteEmotes).includes(messageReaction.emoji.toString()) && messageReaction.emoji.toString() !== NONE_OF_THAT) {
|
2023-07-05 22:55:24 +02:00
|
|
|
logger.info(`${messageReaction.emoji.toString()} currently not handled`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.info(`Found a match for ${messageReaction.emoji.toString()}`)
|
|
|
|
if (isVoteMessage(reactedUponMessage)) {
|
|
|
|
if (messageReaction.emoji.toString() === NONE_OF_THAT) {
|
|
|
|
logger.info(`Reaction is NONE_OF_THAT on a vote message. Handling`, { requestId, guildId })
|
2023-07-17 23:30:48 +02:00
|
|
|
return client.voteController.handleNoneOfThatVote(messageReaction, reactedUponMessage, requestId, guildId)
|
2023-07-05 22:55:24 +02:00
|
|
|
}
|
2023-06-26 23:48:52 +02:00
|
|
|
}
|
2023-07-05 22:55:24 +02:00
|
|
|
else if (isInitialAnnouncement(reactedUponMessage)) {
|
|
|
|
if (messageReaction.emoji.toString() === Emoji.ticket) {
|
2023-11-20 00:17:19 +01:00
|
|
|
logger.error(`Got a role emoji. ${reactedUponMessage.id}`)
|
|
|
|
return client.roleController.addMediaRoleToUser(user, guildId, requestId)
|
2023-07-05 22:55:24 +02:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2023-06-26 23:48:52 +02:00
|
|
|
}
|