Aurora Configuration Rewrite #15

Merged
cswimr merged 73 commits from aurora-config-rewrite into main 2024-01-16 12:19:08 -05:00
2 changed files with 19 additions and 10 deletions
Showing only changes of commit 2037f385d1 - Show all commits

View file

@ -1,4 +1,4 @@
from discord import ui, Interaction from discord import ButtonStyle, ui, Interaction
from redbot.core import commands from redbot.core import commands
from aurora.configuration.embed import addrole from aurora.configuration.embed import addrole
@ -10,7 +10,7 @@ class Addrole(ui.View):
self.ctx = ctx self.ctx = ctx
@ui.select(cls=ui.RoleSelect, placeholder="Select a role") @ui.select(cls=ui.RoleSelect, placeholder="Select a role")
async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect,): 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: 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("You must have the manage guild permission to add roles to the addrole whitelist.", ephemeral=True)
return return
@ -22,3 +22,7 @@ class Addrole(ui.View):
addrole_whitelist.append(select.values[0].id) addrole_whitelist.append(select.values[0].id)
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist) 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), view=Addrole(self.ctx))
@ui.button(label="Close", style=ButtonStyle.red)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
await interaction.message.delete()

View file

@ -1,4 +1,4 @@
from discord import ui, Interaction from discord import ButtonStyle, ui, Interaction
from redbot.core import commands from redbot.core import commands
from aurora.configuration.embed import immune from aurora.configuration.embed import immune
@ -9,16 +9,21 @@ class Immune(ui.View):
super().__init__() super().__init__()
self.ctx = ctx 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 immune_select(self, interaction: Interaction, select: ui.RoleSelect,): 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: 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("You must have the manage guild permission to add immune roles.", ephemeral=True)
return return
await interaction.response.defer() await interaction.response.defer()
immune_roles: list = await config.guild(self.ctx.guild).immune_roles() immune_roles: list = await config.guild(self.ctx.guild).immune_roles()
if select.values[0].id in immune_roles: for role in select.values:
immune_roles.remove(select.values[0].id) if role.id in immune_roles:
else: immune_roles.remove(role.id)
immune_roles.append(select.values[0].id) else:
immune_roles.append(role.id)
await config.guild(self.ctx.guild).immune_roles.set(immune_roles) await config.guild(self.ctx.guild).immune_roles.set(immune_roles)
await interaction.message.edit(embed=await immune(self.ctx), view=Immune(self.ctx)) 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
await interaction.message.delete()