SeaCogs/aurora/configuration/menus/immune.py
SeaswimmerTheFsh 2037f385d1
Some checks failed
Actions / Lint Code (Pylint) (pull_request) Failing after 15s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 12s
feat(aurora): allow setting multiple immune roles at once
2024-01-16 13:39:12 +00:00

29 lines
1.4 KiB
Python

from discord import ButtonStyle, ui, Interaction
from redbot.core import commands
from aurora.configuration.embed import immune
from aurora.utilities.config import config
class Immune(ui.View):
def __init__(self, ctx: commands.Context):
super().__init__()
self.ctx = ctx
@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)
return
await interaction.response.defer()
immune_roles: list = await config.guild(self.ctx.guild).immune_roles()
for role in select.values:
if role.id in immune_roles:
immune_roles.remove(role.id)
else:
immune_roles.append(role.id)
await config.guild(self.ctx.guild).immune_roles.set(immune_roles)
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()