mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Admin] Allow selfroleset command to consume multiple roles (#5238)
* Initial commit * update docs * remove usage kwargs * style * Type hint with SelfRole and not discord.Role * fix docstring * Various improvements, fixes * i need to wake up * more improvements * AAAA * add back check * Improve converter error Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
parent
f8664a4e8a
commit
b0f93a3ce1
@ -150,7 +150,7 @@ selfroleset add
|
||||
|
||||
**Description**
|
||||
|
||||
Add a role to the list of selfroles.
|
||||
Add a role, or a selection of roles, to the list of available selfroles.
|
||||
|
||||
.. warning:: Members will be able to assign themselves the role.
|
||||
Make sure it doesn't give extra perms or anything that can break
|
||||
@ -174,7 +174,7 @@ selfroleset remove
|
||||
|
||||
**Description**
|
||||
|
||||
Removes a role from the list of selfroles.
|
||||
Remove a role, or a selection of roles, from the list of available selfroles.
|
||||
|
||||
**Arguments**
|
||||
|
||||
|
||||
@ -450,34 +450,47 @@ class Admin(commands.Cog):
|
||||
pass
|
||||
|
||||
@selfroleset.command(name="add")
|
||||
async def selfroleset_add(self, ctx: commands.Context, *, role: discord.Role):
|
||||
async def selfroleset_add(self, ctx: commands.Context, *roles: discord.Role):
|
||||
"""
|
||||
Add a role to the list of available selfroles.
|
||||
Add a role, or a selection of roles, to the list of available selfroles.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
current_selfroles = await self.config.guild(ctx.guild).selfroles()
|
||||
for role in roles:
|
||||
if not self.pass_user_hierarchy_check(ctx, role):
|
||||
await ctx.send(
|
||||
_(
|
||||
"I cannot let you add {role.name} as a selfrole because that role is higher than or equal to your highest role in the Discord hierarchy."
|
||||
"I cannot let you add {role.name} as a selfrole because that role is"
|
||||
" higher than or equal to your highest role in the Discord hierarchy."
|
||||
).format(role=role)
|
||||
)
|
||||
return
|
||||
async with self.config.guild(ctx.guild).selfroles() as curr_selfroles:
|
||||
if role.id not in curr_selfroles:
|
||||
curr_selfroles.append(role.id)
|
||||
await ctx.send(_("Added."))
|
||||
if role.id not in current_selfroles:
|
||||
current_selfroles.append(role.id)
|
||||
else:
|
||||
await ctx.send(
|
||||
_('The role "{role.name}" is already a selfrole.').format(role=role)
|
||||
)
|
||||
return
|
||||
|
||||
await ctx.send(_("That role is already a selfrole."))
|
||||
await self.config.guild(ctx.guild).selfroles.set(current_selfroles)
|
||||
if (count := len(roles)) > 1:
|
||||
message = _("Added {count} selfroles.").format(count=count)
|
||||
else:
|
||||
message = _("Added 1 selfrole.")
|
||||
|
||||
await ctx.send(message)
|
||||
|
||||
@selfroleset.command(name="remove")
|
||||
async def selfroleset_remove(self, ctx: commands.Context, *, role: SelfRole):
|
||||
async def selfroleset_remove(self, ctx: commands.Context, *roles: SelfRole):
|
||||
"""
|
||||
Remove a role from the list of available selfroles.
|
||||
Remove a role, or a selection of roles, from the list of available selfroles.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
current_selfroles = await self.config.guild(ctx.guild).selfroles()
|
||||
for role in roles:
|
||||
if not self.pass_user_hierarchy_check(ctx, role):
|
||||
await ctx.send(
|
||||
_(
|
||||
@ -485,10 +498,16 @@ class Admin(commands.Cog):
|
||||
).format(role=role)
|
||||
)
|
||||
return
|
||||
async with self.config.guild(ctx.guild).selfroles() as curr_selfroles:
|
||||
curr_selfroles.remove(role.id)
|
||||
current_selfroles.remove(role.id)
|
||||
|
||||
await ctx.send(_("Removed."))
|
||||
await self.config.guild(ctx.guild).selfroles.set(current_selfroles)
|
||||
|
||||
if (count := len(roles)) > 1:
|
||||
message = _("Removed {count} selfroles.").format(count=count)
|
||||
else:
|
||||
message = _("Removed 1 selfrole.")
|
||||
|
||||
await ctx.send(message)
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
|
||||
@ -17,5 +17,7 @@ class SelfRole(commands.Converter):
|
||||
selfroles = await admin.config.guild(ctx.guild).selfroles()
|
||||
|
||||
if role.id not in selfroles:
|
||||
raise commands.BadArgument(_("The provided role is not a valid selfrole."))
|
||||
raise commands.BadArgument(
|
||||
_('The role "{role_name}" is not a valid selfrole.').format(role_name=role.name)
|
||||
)
|
||||
return role
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user