From 3d4b6800a5aec25a0f3d060ca58ebdcef95a42d6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:02:10 +0000 Subject: [PATCH] feat(aurora): added configuration menu for guild --- aurora/configuration/commands.py | 3 +- aurora/configuration/menus/guild.py | 124 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 aurora/configuration/menus/guild.py diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index a563b6c..08ea6d3 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -2,6 +2,7 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning from aurora.configuration.menus.addrole import Addrole +from aurora.configuration.menus.guild import Guild from aurora.configuration.menus.immune import Immune from aurora.configuration.menus.overrides import Overrides from aurora.configuration.embed import addrole, overrides, immune, guild @@ -31,7 +32,7 @@ class Configuration(Mixin): @commands.guild_only() async def aurora_settings_guild(self, ctx: commands.Context): """Manage Aurora's guild settings.""" - await ctx.send(embed=await guild(ctx)) + await ctx.send(embed=await guild(ctx), view=Guild(ctx)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) diff --git a/aurora/configuration/menus/guild.py b/aurora/configuration/menus/guild.py new file mode 100644 index 0000000..8a489cf --- /dev/null +++ b/aurora/configuration/menus/guild.py @@ -0,0 +1,124 @@ +from discord import ui, ButtonStyle, Interaction +from redbot.core import commands + +from aurora.configuration.embed import guild +from aurora.configuration.utils import create_pagesize_options +from aurora.utilities.config import config + +class Guild(ui.View): + def __init__(self, ctx: commands.Context): + super().__init__() + self.ctx = ctx + + @ui.button(label="Show Moderator", style=ButtonStyle.green, row=0) + async def show_modeartor(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).show_modeartor + await config.guild(interaction.guild).show_modeartor.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0) + async def use_discord_permissions(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).use_discord_permissions() + await config.guild(interaction.guild).use_discord_permissions.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0) + async def ignore_modlog(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).ignore_modlog() + await config.guild(interaction.guild).ignore_modlog.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="Ignore Other Bots", style=ButtonStyle.green, row=0) + async def ignore_other_bots(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).ignore_other_bots() + await config.guild(interaction.guild).ignore_other_bots.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="DM Users", style=ButtonStyle.green, row=0) + async def dm_users(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).dm_users() + await config.guild(interaction.guild).dm_users.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=1) + async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect): + 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 change this setting.", ephemeral=True) + return + await interaction.response.defer() + await config.guild(interaction.guild).log_channel.set(select.values[0].id) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=2) + async def auto_evidenceformat(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).auto_evidenceformat() + await config.guild(interaction.guild).auto_evidenceformat.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="Ephemeral", style=ButtonStyle.green, row=2) + async def ephemeral(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).history_ephemeral() + await config.guild(interaction.guild).history_ephemeral.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.button(label="History Inline", style=ButtonStyle.green, row=2) + async def inline(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("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).history_inline() + await config.guild(interaction.guild).history_inline.set(not current_setting) + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=3) + async def pagesize(self, interaction: Interaction, select: ui.Select,): + 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 change this setting.", ephemeral=True) + return + if select.values[0] == "default": + await config.guild(interaction.guild).history_pagesize.clear() + else: + await config.guild(interaction.guild).history_pagesize.set(int(select.values[0])) + await interaction.response.defer() + await interaction.message.edit(embed=await guild(self.ctx)) + + @ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=4) + async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): + 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 change this setting.", ephemeral=True) + return + if select.values[0] == "default": + await config.guild(interaction.guild).history_inline_pagesize.clear() + else: + await config.guild(interaction.guild).history_inline_pagesize.set(int(select.values[0])) + await interaction.response.defer() + await interaction.message.edit(embed=await guild(self.ctx))