Compare commits

..

3 Commits

Author SHA1 Message Date
c351e27fdd perform vote message check in reaction handler
All checks were successful
Compile the repository / compile (pull_request) Successful in 1m15s
Run unit tests / test (pull_request) Successful in 1m26s
2023-06-27 20:23:36 +02:00
6d3bea169e return on bot reaction 2023-06-27 20:23:22 +02:00
3f071c8a4e remove duplicate check for none_of_that vote 2023-06-27 20:22:44 +02:00
2 changed files with 21 additions and 20 deletions

View File

@ -3,13 +3,16 @@ import { Message, MessageReaction, User } from "discord.js";
import { logger, newRequestId, noGuildId } from "../logger"; import { logger, newRequestId, noGuildId } from "../logger";
import { NONE_OF_THAT } from "../constants"; import { NONE_OF_THAT } from "../constants";
import { client } from "../.."; import { client } from "../..";
import { messageIsVoteMessage } from "../helper/messageIdentifiers";
export const name = 'messageReactionAdd' export const name = 'messageReactionAdd'
export async function execute(messageReaction: MessageReaction, user: User) { export async function execute(messageReaction: MessageReaction, user: User) {
if (user.id == client.user?.id) if (user.id == client.user?.id) {
logger.info('Skipping bot reaction') logger.info('Skipping bot reaction')
return
}
const requestId = newRequestId() const requestId = newRequestId()
const guildId = messageReaction.message.inGuild() ? messageReaction.message.guildId : noGuildId const guildId = messageReaction.message.inGuild() ? messageReaction.message.guildId : noGuildId
const reactedUponMessage: Message = messageReaction.message.partial ? await messageReaction.message.fetch() : messageReaction.message const reactedUponMessage: Message = messageReaction.message.partial ? await messageReaction.message.fetch() : messageReaction.message
@ -23,8 +26,11 @@ export async function execute(messageReaction: MessageReaction, user: User) {
logger.info(`emoji: ${messageReaction.emoji.toString()}`) logger.info(`emoji: ${messageReaction.emoji.toString()}`)
if (messageReaction.emoji.toString() === NONE_OF_THAT) { if (messageReaction.emoji.toString() === NONE_OF_THAT) {
logger.info(`Reaction is NONE_OF_THAT. Handling`, { requestId, guildId }) 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 client.VoteController.handleNoneOfThatVote(messageReaction, user, reactedUponMessage, requestId, guildId)
}
} }
return return

View File

@ -10,9 +10,7 @@ export default class VoteController {
public async handleNoneOfThatVote(messageReaction: MessageReaction, user: User, reactedUponMessage: Message, requestId: string, guildId: string) { public async handleNoneOfThatVote(messageReaction: MessageReaction, user: User, reactedUponMessage: Message, requestId: string, guildId: string) {
if (!messageReaction.message.guild) return 'No guild' if (!messageReaction.message.guild) return 'No guild'
if (messageIsVoteMessage(reactedUponMessage)) {
logger.debug(`${reactedUponMessage.id} is vote message`, { requestId, guildId }) logger.debug(`${reactedUponMessage.id} is vote message`, { requestId, guildId })
if (messageReaction.message.reactions.cache.find(reaction => reaction.emoji.toString() == NONE_OF_THAT)) {
const watcherRoleMember = await getMembersWithRoleFromGuild(config.bot.announcement_role, messageReaction.message.guild) const watcherRoleMember = await getMembersWithRoleFromGuild(config.bot.announcement_role, messageReaction.message.guild)
logger.info("ROLE MEMBERS " + JSON.stringify(watcherRoleMember), { requestId, guildId }) logger.info("ROLE MEMBERS " + JSON.stringify(watcherRoleMember), { requestId, guildId })
const watcherRoleMemberCount = watcherRoleMember.size const watcherRoleMemberCount = watcherRoleMember.size
@ -28,6 +26,3 @@ export default class VoteController {
logger.info(`No reroll`, { requestId, guildId }) logger.info(`No reroll`, { requestId, guildId })
} }
} }
}
}