feat(moderation): added checking for role hierarchy issues
All checks were successful
Pylint / Pylint (3.10) (push) Successful in 55s
All checks were successful
Pylint / Pylint (3.10) (push) Successful in 55s
This commit is contained in:
parent
e61d787edf
commit
d752484662
1 changed files with 56 additions and 0 deletions
|
@ -316,6 +316,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you noting this user?
|
Why are you noting this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
||||||
if silent is None:
|
if silent is None:
|
||||||
silent = not await self.config.guild(interaction.guild).dm_users()
|
silent = not await self.config.guild(interaction.guild).dm_users()
|
||||||
|
@ -339,6 +347,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you warning this user?
|
Why are you warning this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
||||||
if silent is None:
|
if silent is None:
|
||||||
silent = not await self.config.guild(interaction.guild).dm_users()
|
silent = not await self.config.guild(interaction.guild).dm_users()
|
||||||
|
@ -364,6 +380,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you unbanning this user?
|
Why are you unbanning this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
@ -403,6 +427,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you unmuting this user?
|
Why are you unmuting this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
@ -438,6 +470,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you kicking this user?
|
Why are you kicking this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
permissions = self.check_permissions(interaction.client.user, ['kick_members'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['kick_members'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
@ -478,6 +518,14 @@ class Moderation(commands.Cog):
|
||||||
How many days of messages to delete?
|
How many days of messages to delete?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
permissions = self.check_permissions(interaction.client.user, ['ban_members'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['ban_members'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
@ -527,6 +575,14 @@ class Moderation(commands.Cog):
|
||||||
Why are you unbanning this user?
|
Why are you unbanning this user?
|
||||||
silent: bool
|
silent: bool
|
||||||
Should the user be messaged?"""
|
Should the user be messaged?"""
|
||||||
|
if interaction.guild.get_member(target.id):
|
||||||
|
target_member = interaction.guild.get_member(target.id)
|
||||||
|
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||||
|
return
|
||||||
|
if interaction.user.top_role <= target_member.top_role:
|
||||||
|
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||||
|
return
|
||||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
|
Loading…
Reference in a new issue