SeaCogs/aurora/menus/addrole.py

42 lines
2.3 KiB
Python
Raw Permalink Normal View History

from discord import ButtonStyle, ui, Interaction
from redbot.core import commands
from redbot.core.utils.chat_formatting import error
2024-01-16 09:26:54 -05:00
from aurora.utilities.factory import addrole_embed
from aurora.utilities.config import config
class Addrole(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 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(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()
2024-01-16 08:06:50 -05:00
if select.values[0].id in addrole_whitelist:
addrole_whitelist.remove(select.values[0].id)
else:
addrole_whitelist.append(select.values[0].id)
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist)
2024-01-16 09:26:54 -05:00
await interaction.message.edit(embed=await addrole_embed(self.ctx))
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
2024-01-16 09:08:57 -05:00
async def clear(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 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()
2024-01-16 09:26:54 -05:00
await interaction.message.edit(embed=await addrole_embed(self.ctx))
@ui.button(label="Close", style=ButtonStyle.gray)
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()