From b70170533f1bd86f6f4f11c98ab6ef0b1f58ffd6 Mon Sep 17 00:00:00 2001 From: ticccco <23436953+LucasPlacentino@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:02:59 +0100 Subject: [PATCH 1/3] rename user choice during update_all_guilds during an update_all_guilds command, only updates the user's name if both the guild has rename enabled AND the admin set force rename to true at the command --- classes/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/utils.py b/classes/utils.py index 517554b..d2c03f0 100644 --- a/classes/utils.py +++ b/classes/utils.py @@ -141,7 +141,7 @@ async def update_guild(guild: disnake.Guild, *, role: disnake.Role = None, renam await update_member(member, role=role, rename=rename) -async def update_all_guilds() -> None: +async def update_all_guilds(force_rename: bool = False) -> None: """Update all guilds. This create tasks to do it. @@ -149,7 +149,7 @@ async def update_all_guilds() -> None: logging.info("[Utils] Checking all guilds...") await asyncio.gather( *[ - update_guild(guild, role=guild_data.role, rename=guild_data.rename) + update_guild(guild, role=guild_data.role, rename=force_rename if guild_data.rename else guild_data.rename) # force rename users only if both the guild has rename enabled and the admin set the update to force rename true for guild, guild_data in Database.ulb_guilds.items() ] ) From 89bcf1b093193931c6683154ac967c46c2efabfd Mon Sep 17 00:00:00 2001 From: ticccco <23436953+LucasPlacentino@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:08:09 +0100 Subject: [PATCH 2/3] add option for admin to choose to force rename during `/update` to all servers --- cogs/Admin.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cogs/Admin.py b/cogs/Admin.py index b6564b7..3a4f7e2 100644 --- a/cogs/Admin.py +++ b/cogs/Admin.py @@ -26,12 +26,21 @@ def __init__(self, bot: Bot): default_member_permissions=disnake.Permissions.all(), dm_permission=False, ) - async def update(self, inter: disnake.ApplicationCommandInteraction): + async def update( + self, + inter: disnake.ApplicationCommandInteraction, + rename: str = commands.Param( + description="Forcer un rename à tous les utilisateur.rice.s avec l'update ? (Seulment dans les serveurs ayant le rename d'activé)", + default="Non", + choices=["Non", "Oui"], + ), + ): + force_rename = rename == "Oui" # Convert from str to bool await inter.response.defer(ephemeral=True) Database.load(self.bot) - await utils.update_all_guilds() + await utils.update_all_guilds(force_rename) await inter.edit_original_response( - embed=disnake.Embed(description="All servers updated !", color=disnake.Color.green()) + embed=disnake.Embed(description=f"All servers updated !{" Members renamed." if force_rename else ""}", color=disnake.Color.green()) ) @commands.slash_command( From fa88dd7d254f92e147fb686070728fbc6b560b56 Mon Sep 17 00:00:00 2001 From: ticccco <23436953+LucasPlacentino@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:08:40 +0200 Subject: [PATCH 3/3] resolve merge conflict into bepolytech/dev --- cogs/Admin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cogs/Admin.py b/cogs/Admin.py index 3a4f7e2..6b6bc90 100644 --- a/cogs/Admin.py +++ b/cogs/Admin.py @@ -37,11 +37,12 @@ async def update( ): force_rename = rename == "Oui" # Convert from str to bool await inter.response.defer(ephemeral=True) - Database.load(self.bot) - await utils.update_all_guilds(force_rename) - await inter.edit_original_response( - embed=disnake.Embed(description=f"All servers updated !{" Members renamed." if force_rename else ""}", color=disnake.Color.green()) - ) + await Database.load(self.bot) + if (Database.loaded): + await utils.update_all_guilds(force_rename) + await inter.edit_original_response( + embed=disnake.Embed(description=f"All servers updated !{" Members renamed." if force_rename else ""}", color=disnake.Color.green()) + ) @commands.slash_command( name="yearly-update",