From 195c1706bcaa918dbd2bdff197e6c8694b0e7dab Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Thu, 29 Dec 2022 23:48:24 +0000 Subject: [PATCH] Fix the majority of verification race conditions Data races can probably still occur in the following cases: - If Discord is still adding the role when we fetch the user for the second time - If we don't all verify, for example if someone does a kick and someone else does a verify These are substantially less likely than the common case, which has happened several times now --- handlers/VERIFY_USER.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/handlers/VERIFY_USER.js b/handlers/VERIFY_USER.js index f642df5..df36bea 100644 --- a/handlers/VERIFY_USER.js +++ b/handlers/VERIFY_USER.js @@ -43,14 +43,23 @@ exports.run = async (client, interaction, member) => { ephemeral: true }) }else { + let role = await interaction.guild.roles.fetch(process.env.VERIFIED_ROLE); + let guildMember = await interaction.guild.members.fetch(threadName[1]); if (!guildMember) return interaction.reply({ content: "Member is no longer apart of guild.", ephemeral: true }) - let role = await interaction.guild.roles.fetch(process.env.VERIFIED_ROLE); + if (guildMember.roles.has(role)) { + return await interaction.reply({ + content: `<@${threadName[1]}> was already verified`, + allowedMentions: { + users: [client.user.id], + } + }) + } // Add the verified role to the user guildMember.roles.add(role) @@ -200,4 +209,4 @@ exports.run = async (client, interaction, member) => { } -exports.data = {} \ No newline at end of file +exports.data = {}