From 14705efddd04766de2325e11269f38d983b6de64 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:58:53 +0000 Subject: [PATCH] feat(aurora): adding the first parts of menu configs --- aurora/configuration/commands.py | 3 +- aurora/configuration/embed.py | 13 ++++--- .../menus/{blacklist.py => addrole.py} | 0 aurora/configuration/menus/core.py | 37 +++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) rename aurora/configuration/menus/{blacklist.py => addrole.py} (100%) create mode 100644 aurora/configuration/menus/core.py diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 41baf34..1342bf5 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -21,7 +21,8 @@ class Configuration(Mixin): @aurora_settings.command(name="core") async def aurora_settings_core(self, ctx: commands.Context): """Manage Aurora's core settings.""" - await ctx.send(embed=await embed(ctx)) + menu = await embed(ctx) + await ctx.send(embed=menu[0], view=menu[1]) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index e513e4b..0600fb9 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -1,11 +1,12 @@ from typing import Union -from discord import Embed, Guild, Member, User +from discord import Embed, Guild, Member, User, ui from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning -from .utils import get_bool_emoji, get_pagesize_str -from ..utilities.config import config +from aurora.configuration.menus.core import Overrides +from aurora.configuration.utils import get_bool_emoji, get_pagesize_str +from aurora.utilities.config import config async def _core(ctx: commands.Context) -> Embed: """Generates the core embed for configuration menus to use.""" @@ -100,13 +101,15 @@ async def _immune(guild: Guild) -> str: immune = warning("No roles are set as immune roles!") return immune -async def embed(ctx: commands.Context) -> Embed: +async def embed(ctx: commands.Context) -> (Embed, ui.View): """Generates the configuration embed for a guild.""" e = await _core(ctx) e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) + view = Overrides(ctx) if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): e.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False) - return e + view = None + return (e, view) async def addrole_embed(ctx: commands.Context) -> Embed: """Generates the addrole embed for a guild.""" diff --git a/aurora/configuration/menus/blacklist.py b/aurora/configuration/menus/addrole.py similarity index 100% rename from aurora/configuration/menus/blacklist.py rename to aurora/configuration/menus/addrole.py diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py new file mode 100644 index 0000000..d7e78d8 --- /dev/null +++ b/aurora/configuration/menus/core.py @@ -0,0 +1,37 @@ +from discord import ui, ButtonStyle, Interaction +from redbot.core import commands + +from aurora.configuration.embed import embed +from aurora.utilities.config import config + +class Overrides(ui.View): + def __init__(self, ctx: commands.Context): + super().__init__() + self.ctx = ctx + + @ui.button(label="Auto Evidence Format", style=ButtonStyle.green) + async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + current_setting = await config.user(self.ctx.author).auto_evidenceformat() + if current_setting: + await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) + else: + await config.user(self.ctx.author).auto_evidenceformat.set(True) + await self.ctx.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="Ephemeral", style=ButtonStyle.green) + async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + current_setting = await config.user(self.ctx.author).history_ephemeral() + if current_setting: + await config.user(self.ctx.author).history_ephemeral.set(not current_setting) + else: + await config.user(self.ctx.author).history_ephemeral.set(True) + await self.ctx.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="Inline", style=ButtonStyle.green) + async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + current_setting = await config.user(self.ctx.author).history_inline() + if current_setting: + await config.user(self.ctx.author).history_inline.set(not current_setting) + else: + await config.user(self.ctx.author).history_inline.set(True) + await self.ctx.message.edit(embed=await embed(self.ctx))