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)) {
return client.VoteController.handleNoneOfThatVote(messageReaction, user, reactedUponMessage, requestId, guildId) logger.info(`Reaction is NONE_OF_THAT on a vote message. Handling`, { requestId, guildId })
return client.VoteController.handleNoneOfThatVote(messageReaction, user, reactedUponMessage, requestId, guildId)
}
} }
return return

View File

@ -10,24 +10,19 @@ 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 }) const watcherRoleMember = await getMembersWithRoleFromGuild(config.bot.announcement_role, messageReaction.message.guild)
if (messageReaction.message.reactions.cache.find(reaction => reaction.emoji.toString() == NONE_OF_THAT)) { logger.info("ROLE MEMBERS " + JSON.stringify(watcherRoleMember), { requestId, guildId })
const watcherRoleMember = await getMembersWithRoleFromGuild(config.bot.announcement_role, messageReaction.message.guild) const watcherRoleMemberCount = watcherRoleMember.size
logger.info("ROLE MEMBERS " + JSON.stringify(watcherRoleMember), { requestId, guildId }) logger.info(`MEMBER COUNT: ${watcherRoleMemberCount}`, { requestId, guildId })
const watcherRoleMemberCount = watcherRoleMember.size let noneOfThatReactions = messageReaction.message.reactions.cache.get(NONE_OF_THAT)?.users.cache.filter(x => x.id !== client.user?.id).size ?? 0
logger.info(`MEMBER COUNT: ${watcherRoleMemberCount}`, { requestId, guildId })
let noneOfThatReactions = messageReaction.message.reactions.cache.get(NONE_OF_THAT)?.users.cache.filter(x => x.id !== client.user?.id).size ?? 0
const memberThreshold = (watcherRoleMemberCount / 2) const memberThreshold = (watcherRoleMemberCount / 2)
logger.info(`Reroll ${noneOfThatReactions} > ${memberThreshold} ?`, { requestId, guildId }) logger.info(`Reroll ${noneOfThatReactions} > ${memberThreshold} ?`, { requestId, guildId })
if (noneOfThatReactions > memberThreshold) { if (noneOfThatReactions > memberThreshold) {
logger.info('Starting poll reroll', { requestId, guildId }) logger.info('Starting poll reroll', { requestId, guildId })
messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.')) messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
}
logger.info(`No reroll`, { requestId, guildId })
}
} }
logger.info(`No reroll`, { requestId, guildId })
} }
} }