From d3faf0e72223bec33d81398792a3faf0fc35ed57 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 8 May 2022 21:21:30 +0300 Subject: [PATCH] added checks for partial structures --- .../components/observers/CommandHandler.js | 2 +- .../components/observers/GuildLogging.js | 8 ++++-- .../components/observers/UtilityHook.js | 28 ++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 6164506..c1d87e6 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -442,7 +442,7 @@ class CommandHandler extends Observer { } }; - return invoker.reply(messages[info.type]()); + return invoker.reply(messages[info.type](), { _edit: invoker.replied }); } diff --git a/src/structure/components/observers/GuildLogging.js b/src/structure/components/observers/GuildLogging.js index 0e55902..4085136 100644 --- a/src/structure/components/observers/GuildLogging.js +++ b/src/structure/components/observers/GuildLogging.js @@ -140,7 +140,8 @@ class GuildLogger extends Observer { || message.webhookId || message.author.bot || !message.guildWrapper - || !message.guild.available) return; + || !message.guild.available + || message.partial) return; const wrapper = message.guildWrapper; const settings = await wrapper.settings(); @@ -320,8 +321,8 @@ class GuildLogger extends Observer { //Status: Should be complete, though additional testing might be necessary - const { guild, channel } = messages.first(); - if (!guild) return; + const { guild, channel, partial } = messages.first(); + if (!guild || partial) return; const wrapper = this.client.getGuildWrapper(guild.id); const settings = await wrapper.settings(); @@ -495,6 +496,7 @@ class GuildLogger extends Observer { async messageEdit(oldMessage, newMessage) { //Status: Uses webhook, complete + if (oldMessage.partial || newMessage.partial) return; // embeds loading in (ex. when a link is posted) would cause a message edit event if (oldMessage.embeds.length !== newMessage.embeds.length && oldMessage.content === newMessage.content) return; diff --git a/src/structure/components/observers/UtilityHook.js b/src/structure/components/observers/UtilityHook.js index bdc3f0d..d5f4e99 100644 --- a/src/structure/components/observers/UtilityHook.js +++ b/src/structure/components/observers/UtilityHook.js @@ -1,5 +1,6 @@ const { Observer } = require("../../interfaces"); const { Util } = require('../../../utilities'); +const { PollReactions } = require("../../../constants/Constants"); class UtilityHook extends Observer { @@ -18,7 +19,8 @@ class UtilityHook extends Observer { ['guildMemberAdd', this.stickyRole.bind(this)], ['guildMemberRemove', this.storeRoles.bind(this)], ['inviteCreate', this.inviteCreate.bind(this)], - ['inviteDelete', this.inviteDelete.bind(this)] + ['inviteDelete', this.inviteDelete.bind(this)], + // ['messageReactionAdd', this.reactionAdd.bind(this)] ]; } @@ -161,6 +163,30 @@ class UtilityHook extends Observer { } + async reactionAdd(reaction, user) { + if (reaction.partial) reaction = await reaction.fetch(); + if (user.partial) user = await user.fetch(); + if (user.bot || ![...PollReactions.Multi, ...PollReactions.Single].includes(reaction.emoji.name)) return; + let { message } = reaction; + if (!message.guildId) return; + + const guild = this.client.getGuildWrapper(message.guildId); + const channel = await guild.resolveChannel(message.channelId); + const poll = guild.callbacks.find((cb) => cb.data.type === 'poll' && cb.data.message === message.id)?.data; + if (!poll || poll.multichoice) return; + + if (message.partial) message = await channel.messages.fetch(message.id); + const reactions = message.reactions.cache; + const emojis = poll.questions.length > 1 ? PollReactions.Multi : PollReactions.Single; + + for (const emoji of emojis) { + const react = reactions.get(emoji); + if (!react) continue; + if (react.emoji.name === reaction.emoji.name) continue; + await react.users.remove(user); + } + } + } module.exports = UtilityHook; \ No newline at end of file