Compare commits
3 Commits
d9d1d74ef9
...
8ad651c753
Author | SHA1 | Date | |
---|---|---|---|
8ad651c753 | |||
a4a834ad27 | |||
e8dcfd8340 |
@ -1,3 +1,15 @@
|
||||
|
||||
export enum Emotes { "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" }
|
||||
export const NONE_OF_THAT = "❌"
|
||||
export const Emoji = {
|
||||
"one": "\u0031\uFE0F\u20E3",
|
||||
"two": "\u0032\uFE0F\u20E3",
|
||||
"three": "\u0033\uFE0F\u20E3",
|
||||
"four": "\u0034\uFE0F\u20E3",
|
||||
"five": "\u0035\uFE0F\u20E3",
|
||||
"six": "\u0036\uFE0F\u20E3",
|
||||
"seven": "\u0037\uFE0F\u20E3",
|
||||
"eight": "\u0038\uFE0F\u20E3",
|
||||
"nine": "\u0039\uFE0F\u20E3",
|
||||
"ten": "\uD83D\uDD1F"
|
||||
}
|
||||
|
31
server/events/handleMessageReactionAdd.ts
Normal file
31
server/events/handleMessageReactionAdd.ts
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
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) {
|
||||
if (user.id == client.user?.id)
|
||||
logger.info('Skipping bot reaction')
|
||||
const requestId = newRequestId
|
||||
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
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
|
||||
import { Message, MessageReaction, User } from "discord.js";
|
||||
import { messageIsVoteMessage } from "../helper/messageIdentifiers";
|
||||
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 async function execute(messageReaction: MessageReaction, user: User) {
|
||||
if (user.id == client.user?.id)
|
||||
logger.info('Skipping bot reaction')
|
||||
|
||||
const requestId = newRequestId
|
||||
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) return 'No guild'
|
||||
|
||||
logger.info(`Got reaction on message`, { requestId, guildId })
|
||||
logger.debug(`reactedUponMessage payload: ${JSON.stringify(reactedUponMessage)}`)
|
||||
|
||||
if (messageIsVoteMessage(reactedUponMessage)) {
|
||||
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
|
||||
}
|
33
server/helper/vote.controller.ts
Normal file
33
server/helper/vote.controller.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Message, MessageReaction, User } from "discord.js"
|
||||
import { client } from "../.."
|
||||
import { NONE_OF_THAT } from "../constants"
|
||||
import { logger } from "../logger"
|
||||
import { messageIsVoteMessage } from "./messageIdentifiers"
|
||||
import { getMembersWithRoleFromGuild } from "./roleFilter"
|
||||
import { config } from "../configuration"
|
||||
|
||||
export default class VoteController {
|
||||
|
||||
public async handleNoneOfThatVote(messageReaction: MessageReaction, user: User, reactedUponMessage: Message, requestId: string, guildId: string) {
|
||||
if (!messageReaction.message.guild) return 'No guild'
|
||||
if (messageIsVoteMessage(reactedUponMessage)) {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import { logger } from "../logger";
|
||||
import { CommandType } from "../types/commandTypes";
|
||||
import { checkForPollsToClose } from "../commands/closepoll";
|
||||
import { messageIsInitialAnnouncement } from "../helper/messageIdentifiers";
|
||||
import VoteController from "../helper/vote.controller";
|
||||
|
||||
|
||||
|
||||
@ -17,6 +18,7 @@ export class ExtendedClient extends Client {
|
||||
private eventFilePath = `${__dirname}/../events`
|
||||
private commandFilePath = `${__dirname}/../commands`
|
||||
private jellyfin: JellyfinHandler
|
||||
public VoteController: VoteController = new VoteController()
|
||||
public commands: Collection<string, CommandType> = new Collection()
|
||||
private announcementChannels: Collection<string, TextChannel> = new Collection() //guildId to TextChannel
|
||||
private announcementRoleHandlerTask: Collection<string, ScheduledTask> = new Collection() //one task per guild
|
||||
|
Loading…
Reference in New Issue
Block a user