From b64ece3ee9a36a57d28cd1a39a21f9da6e246ae6 Mon Sep 17 00:00:00 2001 From: Kreus Amredes <67752638+Kreusada@users.noreply.github.com> Date: Sun, 17 Oct 2021 17:51:04 +0100 Subject: [PATCH] [Admin] Add `[p]selfroleset clear` command (#5387) --- docs/cog_guides/admin.rst | 16 ++++++++++++++++ redbot/cogs/admin/admin.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/cog_guides/admin.rst b/docs/cog_guides/admin.rst index fe1022c66..5c3c048d6 100644 --- a/docs/cog_guides/admin.rst +++ b/docs/cog_guides/admin.rst @@ -160,6 +160,22 @@ Add a role, or a selection of roles, to the list of available selfroles. * ````: The role to add to the list. |role-input| +.. _admin-command-selfroleset-clear: + +""""""""""""""""" +selfroleset clear +""""""""""""""""" + +**Syntax** + +.. code-block:: none + + [p]selfroleset clear + +**Description** + +Clear the list of available selfroles for this server. + .. _admin-command-selfroleset-remove: """""""""""""""""" diff --git a/redbot/cogs/admin/admin.py b/redbot/cogs/admin/admin.py index bb76cde10..00753cda5 100644 --- a/redbot/cogs/admin/admin.py +++ b/redbot/cogs/admin/admin.py @@ -3,10 +3,11 @@ import logging from typing import Tuple import discord - from redbot.core import Config, checks, commands from redbot.core.i18n import Translator, cog_i18n from redbot.core.utils.chat_formatting import box +from redbot.core.utils.predicates import MessagePredicate + from .announcer import Announcer from .converters import SelfRole @@ -509,6 +510,40 @@ class Admin(commands.Cog): await ctx.send(message) + @selfroleset.command(name="clear") + async def selfroleset_clear(self, ctx: commands.Context): + """Clear the list of available selfroles for this server.""" + current_selfroles = await self.config.guild(ctx.guild).selfroles() + + if not current_selfroles: + return await ctx.send(_("There are currently no selfroles.")) + + await ctx.send( + _("Are you sure you want to clear this server's selfrole list?") + " (yes/no)" + ) + try: + pred = MessagePredicate.yes_or_no(ctx, user=ctx.author) + await ctx.bot.wait_for("message", check=pred, timeout=60) + except asyncio.TimeoutError: + await ctx.send(_("You took too long to respond.")) + return + if pred.result: + for role in current_selfroles: + role = ctx.guild.get_role(role) + if role is None: + continue + if not self.pass_user_hierarchy_check(ctx, role): + await ctx.send( + _( + "I cannot clear the selfroles because the selfrole '{role.name}' is higher than or equal to your highest role in the Discord hierarchy." + ).format(role=role) + ) + return + await self.config.guild(ctx.guild).selfroles.clear() + await ctx.send(_("Selfrole list cleared.")) + else: + await ctx.send(_("No changes have been made.")) + @commands.command() @checks.is_owner() async def serverlock(self, ctx: commands.Context):