feat(aurora): added previous commit's functionality to addrole and fixed some bugs

This commit is contained in:
Seaswimmer 2024-01-16 13:43:22 +00:00
parent 2037f385d1
commit fecde10b1c
Signed by untrusted user: cswimr
GPG key ID: D74DDDDF420E13DF
2 changed files with 30 additions and 4 deletions

View file

@ -1,5 +1,6 @@
from discord import ButtonStyle, ui, Interaction
from redbot.core import commands
from redbot.core.utils.chat_formatting import error
from aurora.configuration.embed import addrole
from aurora.utilities.config import config
@ -9,10 +10,10 @@ class Addrole(ui.View):
super().__init__()
self.ctx = ctx
@ui.select(cls=ui.RoleSelect, placeholder="Select a role")
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to add roles to the addrole whitelist.", ephemeral=True)
await interaction.response.send_message(error("You must have the manage guild permission to add roles to the addrole whitelist."), ephemeral=True)
return
await interaction.response.defer()
addrole_whitelist: list = await config.guild(self.ctx.guild).addrole_whitelist()
@ -21,8 +22,20 @@ class Addrole(ui.View):
else:
addrole_whitelist.append(select.values[0].id)
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist)
await interaction.message.edit(embed=await addrole(self.ctx), view=Addrole(self.ctx))
await interaction.message.edit(embed=await addrole(self.ctx))
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's addrole whitelist."), ephemeral=True)
return
await interaction.response.defer()
await config.guild(self.ctx.guild).addrole_whitelist.clear()
await interaction.message.edit(embed=await addrole(self.ctx))
@ui.button(label="Close", style=ButtonStyle.red)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
return
await interaction.message.delete()

View file

@ -1,5 +1,6 @@
from discord import ButtonStyle, ui, Interaction
from redbot.core import commands
from redbot.core.utils.chat_formatting import error
from aurora.configuration.embed import immune
from aurora.utilities.config import config
@ -12,7 +13,7 @@ class Immune(ui.View):
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
async def immune_select(self, interaction: Interaction, select: ui.RoleSelect):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to add immune roles.", ephemeral=True)
await interaction.response.send_message(error("You must have the manage guild permission to add immune roles."), ephemeral=True)
return
await interaction.response.defer()
immune_roles: list = await config.guild(self.ctx.guild).immune_roles()
@ -24,6 +25,18 @@ class Immune(ui.View):
await config.guild(self.ctx.guild).immune_roles.set(immune_roles)
await interaction.message.edit(embed=await immune(self.ctx))
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's immune roles."), ephemeral=True)
return
await interaction.response.defer()
await config.guild(self.ctx.guild).immune_roles.clear()
await interaction.message.edit(embed=await immune(self.ctx))
@ui.button(label="Close", style=ButtonStyle.red)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
return
await interaction.message.delete()