Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #36 : rename user choice during update_all_guilds for admins' /update #44

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions classes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ 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.
"""
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()
]
)
Expand Down
15 changes: 12 additions & 3 deletions cogs/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ 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)
await Database.load(self.bot)
if (Database.loaded):
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(
Expand Down
Loading