From bee022d1bb60d0a632aa9eb6ed9dffc49110a721 Mon Sep 17 00:00:00 2001 From: Wyn <841141+TheWyn@users.noreply.github.com> Date: Tue, 16 Feb 2021 09:16:16 -0500 Subject: [PATCH] Make `[p]selfrole` without subcommand "toggle" the selfrole (#4826) * Merge selfrole and remove into one command replacement pr * docs add to the docs * Update admin.py remove register name * Update admin.rst * Fixes * Fix the duplicated command decorators * Minimize the diff Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- docs/cog_guides/admin.rst | 11 +++++++---- redbot/cogs/admin/admin.py | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/cog_guides/admin.rst b/docs/cog_guides/admin.rst index 9c0a02d35..60e2177c4 100644 --- a/docs/cog_guides/admin.rst +++ b/docs/cog_guides/admin.rst @@ -46,13 +46,16 @@ selfrole .. code-block:: none - [p]selfrole + [p]selfrole **Description** -Add or remove roles to yourself. Those roles must have been configured as user -settable by admins using the :ref:`selfroleset command -`. +Add or remove a role from yourself. It must have been configured as user settable +by admins using the :ref:`selfroleset command `. + +**Arguments** + +* ````: The role you want to attribute or remove from yourself. |role-input| .. _admin-command-selfrole-add: diff --git a/redbot/cogs/admin/admin.py b/redbot/cogs/admin/admin.py index 293cc9410..f0206c885 100644 --- a/redbot/cogs/admin/admin.py +++ b/redbot/cogs/admin/admin.py @@ -391,12 +391,20 @@ class Admin(commands.Cog): return valid_roles @commands.guild_only() - @commands.group() - async def selfrole(self, ctx: commands.Context): - """Apply selfroles.""" - pass + @commands.group(invoke_without_command=True) + async def selfrole(self, ctx: commands.Context, *, selfrole: SelfRole): + """ + Add or remove a selfrole from yourself. - @selfrole.command(name="add") + Server admins must have configured the role as user settable. + NOTE: The role is case sensitive! + """ + if selfrole in ctx.author.roles: + return await self._removerole(ctx, ctx.author, selfrole, check_user=False) + else: + return await self._addrole(ctx, ctx.author, selfrole, check_user=False) + + @selfrole.command(name="add", hidden=True) async def selfrole_add(self, ctx: commands.Context, *, selfrole: SelfRole): """ Add a selfrole to yourself. @@ -407,7 +415,7 @@ class Admin(commands.Cog): # noinspection PyTypeChecker await self._addrole(ctx, ctx.author, selfrole, check_user=False) - @selfrole.command(name="remove") + @selfrole.command(name="remove", hidden=True) async def selfrole_remove(self, ctx: commands.Context, *, selfrole: SelfRole): """ Remove a selfrole from yourself.