From 108751f561e8e9fa4335d043301ffd3e44bac3e2 Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Sun, 19 Dec 2021 12:05:01 +0000 Subject: [PATCH] implemented fix for #477 --- handlers/events.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/handlers/events.js b/handlers/events.js index 159aaec..bf4903a 100644 --- a/handlers/events.js +++ b/handlers/events.js @@ -993,6 +993,16 @@ async function handleReactionAdd(reaction, user, guildConfig) { let eventForMessage = await EventModel.findOne({ guildID: reaction.message.guild.id, channelID: reaction.message.channel.id, messageID: reaction.message.id }); if (!eventForMessage) { console.info('handleReactionAdd: Did not find event for reaction.'); + } else { + // scrub users that are no longer on server + await eventForMessage.attendees.forEach(async (attendee, index) => { + let attendeeUser = await reaction.message.guild.members.resolve(attendee.userID); + if (!attendeeUser) { + console.debug(`handleReactionAdd: removing an attendee that is no longer in guild: ${attendee.userID}`); + eventForMessage.attendees.splice(index, 1); + } + }); + await eventForMessage.save(); } if (reaction.emoji?.name == utils.EMOJIS.CHECK && eventForMessage) { await attendeeAdd(reaction.message, user, eventForMessage, guildConfig);