added checks for partial structures

This commit is contained in:
Erik 2022-05-08 21:21:30 +03:00
parent 29f500fb0c
commit d3faf0e722
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 33 additions and 5 deletions

View File

@ -442,7 +442,7 @@ class CommandHandler extends Observer {
}
};
return invoker.reply(messages[info.type]());
return invoker.reply(messages[info.type](), { _edit: invoker.replied });
}

View File

@ -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;

View File

@ -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;