rewrite (ranks): Adjust role filter.

This commit is contained in:
2023-06-09 01:32:29 +03:00
parent eafadad610
commit 14543d975c
3 changed files with 36 additions and 3 deletions

View File

@@ -457,7 +457,7 @@ class RankCog(LionCog):
@LionCog.placeholder_group @LionCog.placeholder_group
@cmds.hybrid_group('configure', with_app_command=False) @cmds.hybrid_group('configure', with_app_command=False)
async def configure_group(self, ctx: LionContext): async def configure_group(self, ctx: LionContext):
... pass
@configure_group.command( @configure_group.command(
name=_p('cmd:configure_ranks', "ranks"), name=_p('cmd:configure_ranks', "ranks"),

View File

@@ -145,7 +145,24 @@ class RankOverviewUI(MessageUI):
or throw an error if the role is @everyone or not manageable by the client. or throw an error if the role is @everyone or not manageable by the client.
""" """
role: discord.Role = selected.values[0] role: discord.Role = selected.values[0]
if role.is_assignable(): if role >= selection.user.top_role:
# Do not allow user to manage a role above their own top role
t = self.bot.translator.t
error = t(_p(
'ui:rank_overview|menu:roles|error:above_caller',
"You have insufficient permissions to assign {mention} as a rank role! "
"You may only manage roles below your top role."
))
embed = discord.Embed(
title=t(_p(
'ui:rank_overview|menu:roles|error:above_caller|title',
"Insufficient permissions!"
)),
description=error,
colour=discord.Colour.brand_red()
)
await selection.response.send_message(embed=embed, ephemeral=True)
elif role.is_assignable():
existing = next((rank for rank in self.ranks if rank.roleid == role.id), None) existing = next((rank for rank in self.ranks if rank.roleid == role.id), None)
if existing: if existing:
# Display and edit the given role # Display and edit the given role

View File

@@ -212,7 +212,23 @@ class RankPreviewUI(MessageUI):
role: discord.Role = selected.values[0] role: discord.Role = selected.values[0]
await selection.response.defer(thinking=True, ephemeral=True) await selection.response.defer(thinking=True, ephemeral=True)
if role.is_assignable(): if role >= selection.user.top_role:
# Do not allow user to manage a role above their own top role
error = t(_p(
'ui:rank_preview|menu:roles|error:above_caller',
"You have insufficient permissions to assign {mention} as a rank role! "
"You may only manage roles below your top role."
))
embed = discord.Embed(
title=t(_p(
'ui:rank_preview|menu:roles|error:above_caller|title',
"Insufficient permissions!"
)),
description=error,
colour=discord.Colour.brand_red()
)
await selection.response.send_message(embed=embed, ephemeral=True)
elif role.is_assignable():
# Update the rank role # Update the rank role
await self.rank.update(roleid=role.id) await self.rank.update(roleid=role.id)
if self.parent is not None and not self.parent.is_finished(): if self.parent is not None and not self.parent.is_finished():