From e7d5ab6355d10e04cc688e8db132c5bf1a72926a Mon Sep 17 00:00:00 2001 From: Matthew Cohen Date: Fri, 13 Sep 2024 19:36:09 -0400 Subject: [PATCH] Fix duplicate friend code check --- modules/social.py | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/modules/social.py b/modules/social.py index 7f2d832..fe683b7 100644 --- a/modules/social.py +++ b/modules/social.py @@ -842,32 +842,31 @@ async def _profile_friendcode(self, interaction: discord.Interaction, code: str) msg = f'{config.greenTick} Your friend code has been successfully updated on your profile card! Here\'s how it looks:' # Duplicate friend code detection - if db.count_documents({'friendcode': friendcode}) > 1: - duplicates = db.find({'$and': {{'_id': {'$ne': interaction.user.id}}, {'friendcode': friendcode}}}) - - if duplicates: - # Check if accounts with matching friend codes have infractions on file - punsDB = mclient.bowser.puns - hasPuns = False - otherUsers = [] - for u in duplicates: - if punsDB.count_documents({'user': u['_id']}): - hasPuns = True - - if interaction.user.id != u['id']: - user = interaction.guild.get_member(u['_id']) - if not user: - user = await self.bot.fetch_user(u['_id']) - - otherUsers.append(f'> **{user}** ({u["_id"]})') - - if hasPuns: - admin_channel = self.bot.get_channel(config.nintendoswitch) - others = '\n'.join(otherUsers) - plural = "that of another user" if (len(otherUsers) == 1) else "those of other users" - await admin_channel.send( - f'🕵️ **{interaction.user}** ({interaction.user.id}) has set a friend code (`{friendcode}`) that matches {plural}: \n{others}' - ) + duplicates = db.find({'_id': {'$ne': interaction.user.id}, 'friendcode': friendcode}) + + if duplicates: + # Check if accounts with matching friend codes have infractions on file + punsDB = mclient.bowser.puns + hasPuns = False + otherUsers = [] + for u in duplicates: + if punsDB.count_documents({'user': u['_id']}): + hasPuns = True + + if interaction.user.id != u['id']: + user = interaction.guild.get_member(u['_id']) + if not user: + user = await self.bot.fetch_user(u['_id']) + + otherUsers.append(f'> **{user}** ({u["_id"]})') + + if hasPuns: + admin_channel = self.bot.get_channel(config.nintendoswitch) + others = '\n'.join(otherUsers) + plural = "that of another user" if (len(otherUsers) == 1) else "those of other users" + await admin_channel.send( + f'🕵️ **{interaction.user}** ({interaction.user.id}) has set a friend code (`{friendcode}`) that matches {plural}: \n{others}' + ) else: return await interaction.followup.send(