WIP: basic handling of adding a reaction to a message and deciding whether to reroll or not
This commit is contained in:
parent
331ff89060
commit
d9d1d74ef9
@ -2,18 +2,43 @@
|
|||||||
import { Message, MessageReaction, User } from "discord.js";
|
import { Message, MessageReaction, User } from "discord.js";
|
||||||
import { messageIsVoteMessage } from "../helper/messageIdentifiers";
|
import { messageIsVoteMessage } from "../helper/messageIdentifiers";
|
||||||
import { logger, newRequestId, noGuildId } from "../logger";
|
import { logger, newRequestId, noGuildId } from "../logger";
|
||||||
|
import { NONE_OF_THAT } from "../constants";
|
||||||
|
import { client } from "../..";
|
||||||
|
import { getMembersWithRoleFromGuild } from "../helper/roleFilter";
|
||||||
|
import { config } from "../configuration";
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
logger.info('Skipping bot reaction')
|
||||||
|
|
||||||
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
|
||||||
|
if (!messageReaction.message.guild) return 'No guild'
|
||||||
|
|
||||||
|
logger.info(`Got reaction on message`, { requestId, guildId })
|
||||||
|
logger.debug(`reactedUponMessage payload: ${JSON.stringify(reactedUponMessage)}`)
|
||||||
|
|
||||||
if (messageIsVoteMessage(reactedUponMessage)) {
|
if (messageIsVoteMessage(reactedUponMessage)) {
|
||||||
logger.info(`Got reaction on 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)
|
||||||
|
logger.info("ROLE MEMBERS " + JSON.stringify(watcherRoleMember), { requestId, guildId })
|
||||||
|
const watcherRoleMemberCount = watcherRoleMember.size
|
||||||
|
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)
|
||||||
|
logger.info(`Reroll ${noneOfThatReactions} > ${memberThreshold} ?`, { requestId, guildId })
|
||||||
|
if (noneOfThatReactions > memberThreshold) {
|
||||||
|
logger.info('Starting poll reroll', { requestId, guildId })
|
||||||
|
messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
|
||||||
|
}
|
||||||
|
logger.info(`No reroll`, { requestId, guildId })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user