From c42b4eca2d56253f89d41a21d16bb60c841e4381 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 13 Jan 2024 15:44:08 +0000 Subject: [PATCH 01/72] feat(aurora): starting work on the config rewrite --- aurora/abc.py | 28 ++ aurora/aurora.py | 328 +----------------------- aurora/configuration/__init__.py | 0 aurora/configuration/commands.py | 42 +++ aurora/configuration/embed.py | 111 ++++++++ aurora/configuration/menus/__init__.py | 0 aurora/configuration/menus/blacklist.py | 0 aurora/configuration/menus/immune.py | 0 aurora/configuration/utils.py | 8 + 9 files changed, 192 insertions(+), 325 deletions(-) create mode 100644 aurora/abc.py create mode 100644 aurora/configuration/__init__.py create mode 100644 aurora/configuration/commands.py create mode 100644 aurora/configuration/embed.py create mode 100644 aurora/configuration/menus/__init__.py create mode 100644 aurora/configuration/menus/blacklist.py create mode 100644 aurora/configuration/menus/immune.py create mode 100644 aurora/configuration/utils.py diff --git a/aurora/abc.py b/aurora/abc.py new file mode 100644 index 0000000..42c9fdf --- /dev/null +++ b/aurora/abc.py @@ -0,0 +1,28 @@ +from abc import ABC + +from redbot.core import commands +from redbot.core.bot import Red + +from .utilities.config import Config + + +class CompositeMetaClass(type(commands.Cog), type(ABC)): + """ + This allows the metaclass used for proper type detection to + coexist with discord.py's metaclass + """ + + pass + + +class Mixin(ABC): + """ + Base class for well behaved type hint detection with composite class. + + Basically, to keep developers sane when not all attributes are defined in each mixin. + """ + + def __init__(self, *_args): + super().__init__() + self.config: Config + self.bot: Red diff --git a/aurora/aurora.py b/aurora/aurora.py index 405372d..d77b670 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -20,6 +20,8 @@ from redbot.core import app_commands, checks, commands, data_manager from redbot.core.app_commands import Choice from redbot.core.utils.chat_formatting import box, error, warning +from .abc import CompositeMetaClass +from .configuration.commands import Configuration from .importers.galacticbot import ImportGalacticBotView from .importers.aurora import ImportAuroraView from .utilities.config import config, register_config @@ -29,7 +31,7 @@ from .utilities.logger import logger from .utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat -class Aurora(commands.Cog): +class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): """Aurora is a fully-featured moderation system. It is heavily inspired by GalacticBot, and is designed to be a more user-friendly alternative to Red's core Mod cogs. This cog stores all of its data in an SQLite database.""" @@ -1016,330 +1018,6 @@ class Aurora(commands.Cog): completion_time = (time.time() - current_time) * 1000 logger.debug("Completed expiry loop in %sms with %s users unbanned", f"{completion_time:.6f}", global_num) - ####################################################################################################################### - ### CONFIGURATION COMMANDS - ####################################################################################################################### - - @commands.group(autohelp=True, aliases=['moderationset', 'modset', 'moderationsettings', 'aurorasettings', 'auroraconfig']) - async def auroraset(self, ctx: commands.Context): - """Manage moderation commands.""" - - @auroraset.command(name='list', aliases=['view', 'show']) - async def auroraset_list(self, ctx: commands.Context): - """List all moderation settings.""" - if ctx.guild: - guild_settings = await config.guild(ctx.guild).all() - - guild_settings_string = "" - for setting in guild_settings: - if 'roles' in setting: - continue - if setting == 'log_channel': - channel = ctx.guild.get_channel(guild_settings[setting]) - guild_settings_string += f"**{setting}**: {channel.mention}\n" if channel else f"**{setting}**: {guild_settings[setting]}\n" - else: - guild_settings_string += f"**{setting}**: {guild_settings[setting]}\n" - - user_settings = await config.user(ctx.author).all() - user_settings_string = "" - for setting in user_settings: - user_settings_string += f"**{setting}**: {user_settings[setting]}\n" - - embed = discord.Embed(color=await self.bot.get_embed_color(ctx.channel)) - embed.set_author(icon_url=ctx.guild.icon.url, name=f"{ctx.guild.name} Moderation Settings") - if ctx.guild: - embed.add_field(name="Guild Settings", value=guild_settings_string) - embed.add_field(name="User Settings", value=user_settings_string) - - await ctx.send(embed=embed) - - @auroraset.group(autohelp=True, name='user') - async def auroraset_user(self, ctx: commands.Context): - """Manage configurations for user configuration options.""" - - @auroraset_user.command(name='autoevidence') - async def auroraset_user_autoevidence(self, ctx: commands.Context, enabled: bool): - """Toggle if the evidenceformat codeblock should be sent automatically.""" - await config.user(ctx.author).auto_evidenceformat.set(enabled) - await ctx.send(f"Auto evidenceformat setting set to {enabled}") - - @auroraset_user.group(autohelp=True, name='history') - async def auroraset_user_history(self, ctx: commands.Context): - """Manage configuration for the /history command.""" - - @auroraset_user_history.command(name='ephemeral', aliases=['hidden', 'hide']) - async def auroraset_user_history_ephemeral(self, ctx: commands.Context, enabled: bool): - """Toggle if the /history command should be ephemeral.""" - await config.user(ctx.author).history_ephemeral.set(enabled) - await ctx.send(f"Ephemeral setting set to {enabled}") - - @auroraset_user_history.command(name='pagesize') - async def auroraset_user_history_pagesize(self, ctx: commands.Context, pagesize: int): - """Set the amount of cases to display per page.""" - if pagesize > 20: - await ctx.send("Pagesize cannot be greater than 20!") - return - if pagesize < 1: - await ctx.send("Pagesize cannot be less than 1!") - return - await config.user(ctx.author).history_pagesize.set(pagesize) - await ctx.send(f"Pagesize set to {await config.user(ctx.author).history_pagesize()}") - - @auroraset_user_history.group(name='inline') - async def auroraset_user_history_inline(self, ctx: commands.Context): - """Manage configuration for the /history command's inline argument.""" - - @auroraset_user_history_inline.command(name='toggle') - async def auroraset_user_history_inline_toggle(self, ctx: commands.Context, enabled: bool): - """Enable the /history command's inline argument by default.""" - await config.user(ctx.author).history_inline.set(enabled) - await ctx.send(f"Inline setting set to {enabled}") - - @auroraset_user_history_inline.command(name='pagesize') - async def auroraset_user_history_inline_pagesize(self, ctx: commands.Context, pagesize: int): - """Set the amount of cases to display per page.""" - if pagesize > 20: - await ctx.send(error("Pagesize cannot be greater than 20!")) - return - if pagesize < 1: - await ctx.send(error("Pagesize cannot be less than 1!")) - return - await config.user(ctx.author).history_inline_pagesize.set(pagesize) - await ctx.send(f"Inline pagesize set to {await config.user(ctx.author).history_inline_pagesize()}") - - @auroraset.group(autohelp=True, name='guild') - @checks.admin() - async def auroraset_guild(self, ctx: commands.Context): - """Manage default configurations for user configuration options, per guild.""" - - @auroraset_guild.command(name='autoevidence') - async def auroraset_guild_autoevidence(self, ctx: commands.Context, enabled: bool): - """Toggle if the evidenceformat codeblock should be sent automatically.""" - await config.guild(ctx.guild).auto_evidenceformat.set(enabled) - await ctx.send(f"Auto evidenceformat setting set to {enabled}") - - @auroraset_guild.group(autohelp=True, name='history') - @checks.admin() - async def auroraset_guild_history(self, ctx: commands.Context): - """Manage configuration for the /history command.""" - - @auroraset_guild_history.command(name='ephemeral', aliases=['hidden', 'hide']) - @checks.admin() - async def auroraset_guild_history_ephemeral(self, ctx: commands.Context, enabled: bool): - """Toggle if the /history command should be ephemeral.""" - await config.guild(ctx.guild).history_ephemeral.set(enabled) - await ctx.send(f"Ephemeral setting set to {enabled}") - - @auroraset_guild_history.command(name='pagesize') - @checks.admin() - async def auroraset_guild_history_pagesize(self, ctx: commands.Context, pagesize: int): - """Set the amount of cases to display per page.""" - if pagesize > 20: - await ctx.send("Pagesize cannot be greater than 20!") - return - if pagesize < 1: - await ctx.send("Pagesize cannot be less than 1!") - return - await config.guild(ctx.guild).history_pagesize.set(pagesize) - await ctx.send(f"Pagesize set to {await config.guild(ctx.guild).history_pagesize()}") - - @auroraset_guild_history.group(name='inline') - @checks.admin() - async def auroraset_guild_history_inline(self, ctx: commands.Context): - """Manage configuration for the /history command's inline argument.""" - - @auroraset_guild_history_inline.command(name='toggle') - @checks.admin() - async def auroraset_guild_history_inline_toggle(self, ctx: commands.Context, enabled: bool): - """Enable the /history command's inline argument by default.""" - await config.guild(ctx.guild).history_inline.set(enabled) - await ctx.send(f"Inline setting set to {enabled}") - - @auroraset_guild_history_inline.command(name='pagesize') - @checks.admin() - async def auroraset_guild_history_inline_pagesize(self, ctx: commands.Context, pagesize: int): - """Set the amount of cases to display per page.""" - if pagesize > 20: - await ctx.send("Pagesize cannot be greater than 20!") - return - if pagesize < 1: - await ctx.send("Pagesize cannot be less than 1!") - return - await config.guild(ctx.guild).history_inline_pagesize.set(pagesize) - await ctx.send(f"Inline pagesize set to {await config.guild(ctx.guild).history_inline_pagesize()}") - - @auroraset.group(autohelp=True, name='immunity') - @checks.admin() - async def auroraset_immunity(self, ctx: commands.Context): - """Manage configuration for immune roles.""" - - @auroraset_immunity.command(name='add') - @checks.admin() - async def auroraset_immunity_add(self, ctx: commands.Context, role: discord.Role): - """Add a role to the immune roles list.""" - immune_roles: list = await config.guild(ctx.guild).immune_roles() - if role.id in immune_roles: - await ctx.send(error("Role is already immune!")) - return - immune_roles.append(role.id) - await config.guild(ctx.guild).immune_roles.set(immune_roles) - await ctx.send(f"Role {role.name} added to immune roles.") - - @auroraset_immunity.command(name='remove') - @checks.admin() - async def auroraset_immunity_remove(self, ctx: commands.Context, role: discord.Role): - """Remove a role from the immune roles list.""" - immune_roles: list = await config.guild(ctx.guild).immune_roles() - if role.id not in immune_roles: - await ctx.send(error("Role is not immune!")) - return - immune_roles.remove(role.id) - await config.guild(ctx.guild).immune_roles.set(immune_roles) - await ctx.send(f"Role {role.name} removed from immune roles.") - - @auroraset_immunity.command(name='list') - @checks.admin() - async def auroraset_immunity_list(self, ctx: commands.Context): - """List all immune roles.""" - immune_roles: list = await config.guild(ctx.guild).immune_roles() - if not immune_roles: - await ctx.send("No immune roles set!") - return - role_list = "" - for role_id in immune_roles: - role = ctx.guild.get_role(role_id) - if role: - role_list += f"{role.mention}\n" - if role_list: - embed = discord.Embed(title="Immune Roles", description=role_list, color=await self.bot.get_embed_color(ctx.channel)) - await ctx.send(embed=embed) - - @auroraset.group(autohelp=True, name='blacklist') - @checks.admin() - async def auroraset_blacklist(self, ctx: commands.Context): - """Manage configuration for the /blacklist command.""" - - @auroraset_blacklist.command(name='add') - @checks.admin() - async def auroraset_blacklist_add(self, ctx: commands.Context, role: discord.Role, duration: str): - """Add a role to the blacklist.""" - blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles() - for blacklist_role in blacklist_roles: - if role.id == blacklist_role['role']: - await ctx.send(error("Role already has an associated blacklist type!")) - return - - try: - parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True) - except ValueError: - await ctx.send(error("Please provide a valid duration!")) - return - - blacklist_roles.append( - { - 'role': role.id, - 'duration': str(parsed_time) - } - ) - await config.guild(ctx.guild).blacklist_roles.set(blacklist_roles) - await ctx.send(f"Role {role.mention} added as a blacklist type.", allowed_mentions=discord.AllowedMentions.none()) - - @auroraset_blacklist.command(name='remove') - @checks.admin() - async def auroraset_blacklist_remove(self, ctx: commands.Context, role: discord.Role): - """Remove a role's blacklist type.""" - blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles() - for blacklist_role in blacklist_roles: - if role.id == blacklist_role['role']: - blacklist_roles.remove(blacklist_role) - await config.guild(ctx.guild).blacklist_roles.set(blacklist_roles) - await ctx.send(f"Role {role.mention} removed from blacklist types.", allowed_mentions=discord.AllowedMentions.none()) - return - await ctx.send(error("Role does not have an associated blacklist type!")) - - @auroraset_blacklist.command(name='list') - @checks.admin() - async def auroraset_blacklist_list(self, ctx: commands.Context): - """List all blacklist types.""" - blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles() - if not blacklist_roles: - await ctx.send("No blacklist types set!") - return - blacklist_list = "" - for blacklist_role in blacklist_roles: - role = ctx.guild.get_role(blacklist_role['role']) - if role: - blacklist_list += f"{role.mention} - {blacklist_role['duration']}\n" - if blacklist_list: - embed = discord.Embed(title="Blacklist Types", description=blacklist_list, color=await self.bot.get_embed_color(ctx.channel)) - await ctx.send(embed=embed) - - @auroraset.command(name="ignorebots") - @checks.admin() - async def auroraset_ignorebots(self, ctx: commands.Context): - """Toggle if the cog should ignore other bots' moderations.""" - await config.guild(ctx.guild).ignore_other_bots.set(not await config.guild(ctx.guild).ignore_other_bots()) - await ctx.send(f"Ignore bots setting set to {await config.guild(ctx.guild).ignore_other_bots()}") - - @auroraset.command(name="dm") - @checks.admin() - async def auroraset_dm(self, ctx: commands.Context): - """Toggle automatically messaging moderated users. - - This option can be overridden by specifying the `silent` argument in any moderation command.""" - await config.guild(ctx.guild).dm_users.set(not await config.guild(ctx.guild).dm_users()) - await ctx.send(f"DM users setting set to {await config.guild(ctx.guild).dm_users()}") - - @auroraset.command(name="permissions") - @checks.admin() - async def auroraset_permissions(self, ctx: commands.Context): - """Toggle whether the bot will check for discord permissions.""" - await config.guild(ctx.guild).use_discord_permissions.set(not await config.guild(ctx.guild).use_discord_permissions()) - await ctx.send(f"Use Discord Permissions setting set to {await config.guild(ctx.guild).use_discord_permissions()}") - - @auroraset.command(name="logchannel") - @checks.admin() - async def auroraset_logchannel(self, ctx: commands.Context, channel: discord.TextChannel = None): - """Set a channel to log infractions to.""" - if channel: - await config.guild(ctx.guild).log_channel.set(channel.id) - await ctx.send(f"Logging channel set to {channel.mention}.") - else: - await config.guild(ctx.guild).log_channel.set(" ") - await ctx.send(warning("Logging channel disabled.")) - - @auroraset.command(name="showmoderator") - @checks.admin() - async def auroraset_showmoderator(self, ctx: commands.Context): - """Toggle if the cog should show the moderator in the case embed when dming a user.""" - await config.guild(ctx.guild).show_moderator.set(not await config.guild(ctx.guild).show_moderator()) - await ctx.send(f"Show moderator setting set to {await config.guild(ctx.guild).show_moderator()}") - - @auroraset.group(autohelp=True, name='import') - @checks.admin() - async def auroraset_import(self, ctx: commands.Context): - """Import moderations from other bots.""" - - @auroraset_import.command(name="aurora") - @checks.admin() - async def auroraset_import_aurora(self, ctx: commands.Context): - """Import moderations from another bot using Aurora.""" - if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': - message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) - await message.edit(view=ImportAuroraView(60, ctx, message)) - else: - await ctx.send(error("Please provide a valid Aurora export file.")) - - @auroraset_import.command(name="galacticbot") - @checks.admin() - async def auroraset_import_galacticbot(self, ctx: commands.Context): - """Import moderations from GalacticBot.""" - if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': - message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) - await message.edit(view=ImportGalacticBotView(60, ctx, message)) - else: - await ctx.send(error("Please provide a valid GalacticBot moderation export file.")) - @commands.command(aliases=["tdc"]) async def timedeltaconvert(self, ctx: commands.Context, *, duration: str): """This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object. diff --git a/aurora/configuration/__init__.py b/aurora/configuration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py new file mode 100644 index 0000000..d562975 --- /dev/null +++ b/aurora/configuration/commands.py @@ -0,0 +1,42 @@ +from redbot.core import commands +from redbot.core.utils.chat_formatting import error, warning + +from .embed import embed +from ..abc import Mixin +from ..importers.aurora import ImportAuroraView +from ..importers.galacticbot import ImportGalacticBotView + +class Configuration(Mixin): + """Configuration commands for Aurora.""" + + @commands.guild_only() + @commands.group(autohelp=True, aliases=['moderationset', 'modset', 'moderationsettings', 'aurorasettings', 'auroraconfig']) + async def auroraset(self, ctx: commands.Context): + """Set Aurora configuration options.""" + await ctx.reply(embed=embed(ctx)) + + @auroraset.group(autohelp=True, name='import') + @commands.admin() + @commands.guild_only() + async def auroraset_import(self, ctx: commands.Context): + """Import moderations from other bots.""" + + @auroraset_import.command(name="aurora") + @commands.admin() + async def auroraset_import_aurora(self, ctx: commands.Context): + """Import moderations from another bot using Aurora.""" + if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': + message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) + await message.edit(view=ImportAuroraView(60, ctx, message)) + else: + await ctx.send(error("Please provide a valid Aurora export file.")) + + @auroraset_import.command(name="galacticbot") + @commands.admin() + async def auroraset_import_galacticbot(self, ctx: commands.Context): + """Import moderations from GalacticBot.""" + if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': + message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) + await message.edit(view=ImportGalacticBotView(60, ctx, message)) + else: + await ctx.send(error("Please provide a valid GalacticBot moderation export file.")) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py new file mode 100644 index 0000000..b5f244a --- /dev/null +++ b/aurora/configuration/embed.py @@ -0,0 +1,111 @@ +from typing import Union + +from discord import Embed, Guild, Member, User +from redbot.core import commands +from redbot.core.utils.chat_formatting import bold, error, warning + +from .utils import get_bool_emoji +from ..utilities.config import config + +async def _core(ctx: commands.Context) -> Embed: + """Generates the core embed for configuration menus to use.""" + embed = Embed( + title="Aurora Configuration Menu", + description="Use the buttons below to configure Aurora.", + color=await ctx.embed_color() + ) + embed.set_thumbnail(url=ctx.bot.user.avatar_url) + return embed + +async def _overrides(user: Union[Member, User]) -> str: + """Generates a configuration menu field value for a user's overrides.""" + + override_settings = { + "ephemeral": await config.user(user).history_ephemeral(), + "inline": await config.user(user).history_inline(), + "inline_pagesize": await config.user(user).history_inline_pagesize(), + "pagesize": await config.user(user).history_pagesize(), + "auto_evidenceformat": await config.user(user).auto_evidenceformat() + } + + overrides = [ + "These settings will override the relevant guild settings.\n", # Add an extra line between the subtitle and the settings + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), + bold("Inline: ") + get_bool_emoji(override_settings['inline']), + bold("Inline Pagesize: ") + override_settings['inline_pagesize'] + " cases per page", + bold("Pagesize: ") + override_settings['pagesize'] + " cases per page", + ] + overrides = '\n'.join(overrides) + return overrides + +async def _guild(guild: Guild) -> str: + """Generates a configuration menu field value for a guild's settings.""" + + guild_settings = { + "show_moderator": await config.guild(guild).show_moderator(), + "use_discord_permissions": await config.guild(guild).use_discord_permissions(), + "ignore_modlog": await config.guild(guild).ignore_modlog(), + "ignore_other_bots": await config.guild(guild).ignore_other_bots(), + "dm_users": await config.guild(guild).dm_users(), + "log_channel": await config.guild(guild).log_channel(), + "history_ephemeral": await config.guild(guild).history_ephemeral(), + "history_inline": await config.guild(guild).history_inline(), + "history_pagesize": await config.guild(guild).history_pagesize(), + "history_inline_pagesize": await config.guild(guild).history_inline_pagesize(), + "auto_evidenceformat": await config.guild(guild).auto_evidenceformat(), + } + + channel = guild.get_channel(guild_settings['log_channel']) + if channel is None: + channel = warning("Not Set") + else: + channel = channel.mention + + guild_str = [ + bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']), + bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']), + bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), + bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), + bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), + bold("Log Channel: ") + channel, + bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), + bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), + bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), + bold("History Pagesize: ") + guild_settings['history_pagesize'] + " cases per page", + bold("History Inline Pagesize: ") + guild_settings['history_inline_pagesize'] + " cases per page" + ] + guild_str = '\n'.join(guild_str) + return guild_str + +async def _blacklist(guild: Guild) -> str: + """Generates a configuration menu field value for a guild's blacklist.""" + + blacklist = await config.guild(guild).blacklist_roles() + if blacklist: + blacklist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in blacklist] + blacklist = '\n'.join(blacklist) + else: + blacklist = warning("No roles are set as blacklist roles!") + return blacklist + +async def _immune(guild: Guild) -> str: + """Generates a configuration menu field value for a guild's immune roles.""" + + immune = await config.guild(guild).immune_roles() + if immune: + immune = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune] + immune = '\n'.join(immune) + else: + immune = warning("No roles are set as immune roles!") + return immune + +async def embed(ctx: commands.Context) -> Embed: + """Generates the configuration embed for a guild.""" + embed = await _core(ctx) + embed.add_field(name="User Overrides", value=await _overrides(ctx.author)) + if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): + embed.add_field(name="Guild Settings", value=await _guild(ctx.guild)) + embed.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild)) + embed.add_field(name="Immune Roles", value=await _immune(ctx.guild)) + return embed diff --git a/aurora/configuration/menus/__init__.py b/aurora/configuration/menus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aurora/configuration/menus/blacklist.py b/aurora/configuration/menus/blacklist.py new file mode 100644 index 0000000..e69de29 diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py new file mode 100644 index 0000000..e69de29 diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py new file mode 100644 index 0000000..6e70e48 --- /dev/null +++ b/aurora/configuration/utils.py @@ -0,0 +1,8 @@ +def get_bool_emoji(value: bool) -> str: + """Returns a unicode emoji based on a boolean value.""" + if value is True: + return "\N{WHITE HEAVY CHECK MARK}" + if value is False: + return "\N{NO ENTRY SIGN}" + if value is None: + return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" From 1a46ca33b0a41d60a3bbb948db3d7d647780a74d Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 13 Jan 2024 15:47:26 +0000 Subject: [PATCH 02/72] fix(docs): mark old configuration page as outdated --- .docs/aurora/configuration.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.docs/aurora/configuration.md b/.docs/aurora/configuration.md index 0c73acf..087cab3 100644 --- a/.docs/aurora/configuration.md +++ b/.docs/aurora/configuration.md @@ -1,5 +1,10 @@ # Configuration +/// admonition | Outdated + type: danger +These docs have not been updated for the configuration rewrite yet. +/// + ## auroraset - Usage: `[p]auroraset` - Aliases: `moderationset, modset, moderationsettings, aurorasettings, and auroraconfig` From e73616774af5744a8adad6e10341f769ba4d57f5 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 14 Jan 2024 06:41:11 +0000 Subject: [PATCH 03/72] fix(aurora): fixed missing return --- aurora/aurora.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aurora/aurora.py b/aurora/aurora.py index d77b670..089b28f 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -747,6 +747,7 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): if case_dict['moderation_type'] in ['UNMUTE', 'UNBAN']: await interaction.response.send_message(content=error("You cannot resolve this type of moderation!"), ephemeral=True) + return if case_dict['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']: if case_dict['moderation_type'] == 'MUTE': From ad9675e60eab2972dda6f39673021fdc8d3096f3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 06:46:12 +0000 Subject: [PATCH 04/72] misc(aurora): renamed configuration commands --- aurora/configuration/commands.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index d562975..dab5824 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -10,18 +10,23 @@ class Configuration(Mixin): """Configuration commands for Aurora.""" @commands.guild_only() - @commands.group(autohelp=True, aliases=['moderationset', 'modset', 'moderationsettings', 'aurorasettings', 'auroraconfig']) - async def auroraset(self, ctx: commands.Context): - """Set Aurora configuration options.""" - await ctx.reply(embed=embed(ctx)) + @commands.group(autohelp=True, aliases=['moderation', 'mod']) + async def aurora(self, ctx: commands.Context): + """Settings and miscellaneous commands for Aurora.""" - @auroraset.group(autohelp=True, name='import') + @aurora.command(name="settings", aliases=['config', 'options', 'set']) + @commands.guild_only() + async def aurora_settings(self, ctx: commands.Context): + """View Aurora configuration settings.""" + await ctx.send(embed=await embed(ctx)) + + @aurora.group(autohelp=True, name='import') @commands.admin() @commands.guild_only() - async def auroraset_import(self, ctx: commands.Context): + async def aurora_import(self, ctx: commands.Context): """Import moderations from other bots.""" - @auroraset_import.command(name="aurora") + @aurora_import.command(name="aurora") @commands.admin() async def auroraset_import_aurora(self, ctx: commands.Context): """Import moderations from another bot using Aurora.""" @@ -31,7 +36,7 @@ class Configuration(Mixin): else: await ctx.send(error("Please provide a valid Aurora export file.")) - @auroraset_import.command(name="galacticbot") + @aurora_import.command(name="galacticbot") @commands.admin() async def auroraset_import_galacticbot(self, ctx: commands.Context): """Import moderations from GalacticBot.""" From d99df7f898d79a143c9199ac0934f0895af7e2d9 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 07:00:53 +0000 Subject: [PATCH 05/72] fix(aurora): fixed _core function using avatar_url instead of display_avatar.url --- aurora/configuration/embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index b5f244a..24632d9 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -14,7 +14,7 @@ async def _core(ctx: commands.Context) -> Embed: description="Use the buttons below to configure Aurora.", color=await ctx.embed_color() ) - embed.set_thumbnail(url=ctx.bot.user.avatar_url) + embed.set_thumbnail(url=ctx.bot.user.display_avatar.url) return embed async def _overrides(user: Union[Member, User]) -> str: From a373f63756b226fd2187a3a69211075930c4a6b6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 07:07:06 +0000 Subject: [PATCH 06/72] fix(aurora): fixed TypeError in embed _overrides function --- aurora/configuration/embed.py | 10 +++++----- aurora/configuration/utils.py | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 24632d9..71593db 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -4,7 +4,7 @@ from discord import Embed, Guild, Member, User from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning -from .utils import get_bool_emoji +from .utils import get_bool_emoji, get_pagesize_str from ..utilities.config import config async def _core(ctx: commands.Context) -> Embed: @@ -33,8 +33,8 @@ async def _overrides(user: Union[Member, User]) -> str: bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), bold("Inline: ") + get_bool_emoji(override_settings['inline']), - bold("Inline Pagesize: ") + override_settings['inline_pagesize'] + " cases per page", - bold("Pagesize: ") + override_settings['pagesize'] + " cases per page", + bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] overrides = '\n'.join(overrides) return overrides @@ -72,8 +72,8 @@ async def _guild(guild: Guild) -> str: bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), - bold("History Pagesize: ") + guild_settings['history_pagesize'] + " cases per page", - bold("History Inline Pagesize: ") + guild_settings['history_inline_pagesize'] + " cases per page" + bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), + bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) ] guild_str = '\n'.join(guild_str) return guild_str diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py index 6e70e48..91376e1 100644 --- a/aurora/configuration/utils.py +++ b/aurora/configuration/utils.py @@ -1,3 +1,5 @@ +from typing import Union + def get_bool_emoji(value: bool) -> str: """Returns a unicode emoji based on a boolean value.""" if value is True: @@ -6,3 +8,9 @@ def get_bool_emoji(value: bool) -> str: return "\N{NO ENTRY SIGN}" if value is None: return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" + +def get_pagesize_str(value: Union[int, None]) -> str: + """Returns a string based on a pagesize value.""" + if value is None: + return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" + return str(value) + " cases per page" From e394518aadcfbf77bf95c88bc6a0880efc168cf2 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 07:08:24 +0000 Subject: [PATCH 07/72] fix(aurora): aurora settings should not be guild only --- aurora/configuration/commands.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index dab5824..17d0786 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -9,13 +9,11 @@ from ..importers.galacticbot import ImportGalacticBotView class Configuration(Mixin): """Configuration commands for Aurora.""" - @commands.guild_only() @commands.group(autohelp=True, aliases=['moderation', 'mod']) async def aurora(self, ctx: commands.Context): """Settings and miscellaneous commands for Aurora.""" @aurora.command(name="settings", aliases=['config', 'options', 'set']) - @commands.guild_only() async def aurora_settings(self, ctx: commands.Context): """View Aurora configuration settings.""" await ctx.send(embed=await embed(ctx)) From bb3da8d03b9fe737faa5d1738154835261f25441 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 07:09:44 +0000 Subject: [PATCH 08/72] fix(aurora): fixed embed fields being inline --- aurora/configuration/embed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 71593db..a4cd1c4 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -103,9 +103,9 @@ async def _immune(guild: Guild) -> str: async def embed(ctx: commands.Context) -> Embed: """Generates the configuration embed for a guild.""" embed = await _core(ctx) - embed.add_field(name="User Overrides", value=await _overrides(ctx.author)) + embed.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): - embed.add_field(name="Guild Settings", value=await _guild(ctx.guild)) - embed.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild)) - embed.add_field(name="Immune Roles", value=await _immune(ctx.guild)) + embed.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False) + embed.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False) + embed.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False) return embed From 166f5bc1ea1af463a3ef5c80141eaecf3b7c207b Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 11:49:20 +0000 Subject: [PATCH 09/72] fix(aurora): pylint fixes --- aurora/abc.py | 29 +++++++++++++++++++++++++---- aurora/aurora.py | 5 ++--- aurora/configuration/commands.py | 4 ++-- aurora/configuration/embed.py | 18 +++++++++--------- aurora/configuration/utils.py | 3 +-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/aurora/abc.py b/aurora/abc.py index 42c9fdf..89857bb 100644 --- a/aurora/abc.py +++ b/aurora/abc.py @@ -1,4 +1,4 @@ -from abc import ABC +from abc import ABC, abstractmethod from redbot.core import commands from redbot.core.bot import Red @@ -12,9 +12,6 @@ class CompositeMetaClass(type(commands.Cog), type(ABC)): coexist with discord.py's metaclass """ - pass - - class Mixin(ABC): """ Base class for well behaved type hint detection with composite class. @@ -26,3 +23,27 @@ class Mixin(ABC): super().__init__() self.config: Config self.bot: Red + + ####################################################################### + # configuration/commands.py # + ####################################################################### + + @abstractmethod + async def aurora(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_config(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_import(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_import_aurora(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_import_galacticbot(self, ctx: commands.Context) -> None: + raise NotImplementedError() diff --git a/aurora/aurora.py b/aurora/aurora.py index 089b28f..1bd001c 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -16,14 +16,12 @@ import discord import humanize from discord.ext import tasks from pytimeparse2 import disable_dateutil, parse -from redbot.core import app_commands, checks, commands, data_manager +from redbot.core import app_commands, commands, data_manager from redbot.core.app_commands import Choice from redbot.core.utils.chat_formatting import box, error, warning from .abc import CompositeMetaClass from .configuration.commands import Configuration -from .importers.galacticbot import ImportGalacticBotView -from .importers.aurora import ImportAuroraView from .utilities.config import config, register_config from .utilities.database import connect, create_guild_table, fetch_case, mysql_log from .utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory @@ -68,6 +66,7 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) def __init__(self, bot): + super().__init__() self.bot = bot register_config(config) disable_dateutil() diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 17d0786..63f8dd1 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -26,7 +26,7 @@ class Configuration(Mixin): @aurora_import.command(name="aurora") @commands.admin() - async def auroraset_import_aurora(self, ctx: commands.Context): + async def aurora_import_aurora(self, ctx: commands.Context): """Import moderations from another bot using Aurora.""" if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) @@ -36,7 +36,7 @@ class Configuration(Mixin): @aurora_import.command(name="galacticbot") @commands.admin() - async def auroraset_import_galacticbot(self, ctx: commands.Context): + async def aurora_import_galacticbot(self, ctx: commands.Context): """Import moderations from GalacticBot.""" if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index a4cd1c4..86ebb91 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -9,13 +9,13 @@ from ..utilities.config import config async def _core(ctx: commands.Context) -> Embed: """Generates the core embed for configuration menus to use.""" - embed = Embed( + e = Embed( title="Aurora Configuration Menu", description="Use the buttons below to configure Aurora.", color=await ctx.embed_color() ) - embed.set_thumbnail(url=ctx.bot.user.display_avatar.url) - return embed + e.set_thumbnail(url=ctx.bot.user.display_avatar.url) + return e async def _overrides(user: Union[Member, User]) -> str: """Generates a configuration menu field value for a user's overrides.""" @@ -102,10 +102,10 @@ async def _immune(guild: Guild) -> str: async def embed(ctx: commands.Context) -> Embed: """Generates the configuration embed for a guild.""" - embed = await _core(ctx) - embed.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) + e = await _core(ctx) + e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): - embed.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False) - embed.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False) - embed.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False) - return embed + e.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False) + e.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False) + e.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False) + return e diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py index 91376e1..ea3c5e0 100644 --- a/aurora/configuration/utils.py +++ b/aurora/configuration/utils.py @@ -6,8 +6,7 @@ def get_bool_emoji(value: bool) -> str: return "\N{WHITE HEAVY CHECK MARK}" if value is False: return "\N{NO ENTRY SIGN}" - if value is None: - return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" + return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" def get_pagesize_str(value: Union[int, None]) -> str: """Returns a string based on a pagesize value.""" From 606cd76ec4f0cbcb7053021c0335b602ef76ebf1 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 11:51:54 +0000 Subject: [PATCH 10/72] fix(aurora): pylint fix --- aurora/aurora.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 1bd001c..d1cd329 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -29,7 +29,7 @@ from .utilities.logger import logger from .utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat -class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): +class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylint: disable=too-many-ancestors """Aurora is a fully-featured moderation system. It is heavily inspired by GalacticBot, and is designed to be a more user-friendly alternative to Red's core Mod cogs. This cog stores all of its data in an SQLite database.""" From e28e32d0c0388bd51d06818690a11951ff493c23 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:03:02 +0000 Subject: [PATCH 11/72] feat(aurora): splitting out the role configuration into different commands --- aurora/aurora.py | 3 +- aurora/configuration/commands.py | 51 ++++++++++++++++++++++++++------ aurora/configuration/embed.py | 26 +++++++++++----- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index d1cd329..d41662f 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -18,6 +18,7 @@ from discord.ext import tasks from pytimeparse2 import disable_dateutil, parse from redbot.core import app_commands, commands, data_manager from redbot.core.app_commands import Choice +from redbot.core.bot import Red from redbot.core.utils.chat_formatting import box, error, warning from .abc import CompositeMetaClass @@ -65,7 +66,7 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylin else: logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) - def __init__(self, bot): + def __init__(self, bot: Red): super().__init__() self.bot = bot register_config(config) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 63f8dd1..8a9c37a 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -1,24 +1,39 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning -from .embed import embed +from .embed import addrole_embed, embed, immune_embed from ..abc import Mixin from ..importers.aurora import ImportAuroraView from ..importers.galacticbot import ImportGalacticBotView + class Configuration(Mixin): """Configuration commands for Aurora.""" - @commands.group(autohelp=True, aliases=['moderation', 'mod']) + @commands.group(autohelp=True, aliases=["moderation", "mod"]) async def aurora(self, ctx: commands.Context): """Settings and miscellaneous commands for Aurora.""" - @aurora.command(name="settings", aliases=['config', 'options', 'set']) + @aurora.command(name="settings", aliases=["config", "options", "set"]) async def aurora_settings(self, ctx: commands.Context): """View Aurora configuration settings.""" await ctx.send(embed=await embed(ctx)) - @aurora.group(autohelp=True, name='import') + @aurora_settings.command(name="addrole", aliases=["removerole"]) + @commands.admin_or_permissions(manage_guild=True) + async def aurora_settings_addrole(self, ctx: commands.Context): + """Manage the addrole whitelist. + + Roles added to this list are also applied to `/removerole`.""" + await ctx.send(embed=await addrole_embed(ctx)) + + @aurora_settings.command(name="immunity") + @commands.admin_or_permissions(manage_guild=True) + async def aurora_settings_immunity(self, ctx: commands.Context): + """Manage the immunity whitelist.""" + await ctx.send(embed=await immune_embed(ctx)) + + @aurora.group(autohelp=True, name="import") @commands.admin() @commands.guild_only() async def aurora_import(self, ctx: commands.Context): @@ -28,8 +43,16 @@ class Configuration(Mixin): @commands.admin() async def aurora_import_aurora(self, ctx: commands.Context): """Import moderations from another bot using Aurora.""" - if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': - message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) + if ( + ctx.message.attachments + and ctx.message.attachments[0].content_type + == "application/json; charset=utf-8" + ): + message = await ctx.send( + warning( + "Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" + ) + ) await message.edit(view=ImportAuroraView(60, ctx, message)) else: await ctx.send(error("Please provide a valid Aurora export file.")) @@ -38,8 +61,18 @@ class Configuration(Mixin): @commands.admin() async def aurora_import_galacticbot(self, ctx: commands.Context): """Import moderations from GalacticBot.""" - if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': - message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")) + if ( + ctx.message.attachments + and ctx.message.attachments[0].content_type + == "application/json; charset=utf-8" + ): + message = await ctx.send( + warning( + "Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" + ) + ) await message.edit(view=ImportGalacticBotView(60, ctx, message)) else: - await ctx.send(error("Please provide a valid GalacticBot moderation export file.")) + await ctx.send( + error("Please provide a valid GalacticBot moderation export file.") + ) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 86ebb91..8af50ed 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -78,15 +78,15 @@ async def _guild(guild: Guild) -> str: guild_str = '\n'.join(guild_str) return guild_str -async def _blacklist(guild: Guild) -> str: - """Generates a configuration menu field value for a guild's blacklist.""" +async def _addrole(guild: Guild) -> str: + """Generates a configuration menu field value for a guild's addrole whitelist.""" - blacklist = await config.guild(guild).blacklist_roles() + whitelist = await config.guild(guild).addrole_roles() if blacklist: - blacklist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in blacklist] + blacklist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] blacklist = '\n'.join(blacklist) else: - blacklist = warning("No roles are set as blacklist roles!") + blacklist = warning("No roles are on the addrole whitelist!") return blacklist async def _immune(guild: Guild) -> str: @@ -106,6 +106,18 @@ async def embed(ctx: commands.Context) -> Embed: e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) 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) - e.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False) - e.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False) + return e + +async def addrole_embed(ctx: commands.Context) -> Embed: + """Generates the addrole embed for a guild.""" + e = await _core(ctx) + e.title += ": Addrole Whitelist" + e.description = "Use the buttons below to manage the addrole whitelist.\n\n" + await _addrole(ctx.guild) + return e + +async def immune_embed(ctx: commands.Context) -> Embed: + """Generates the immune roles embed for a guild.""" + e = await _core(ctx) + e.title += ": Immune Roles" + e.description = "Use the buttons below to manage the immune roles.\n\n" + await _immune(ctx.guild) return e From a475a519109d1d03a4a1aa4ee844c9621ae6226e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:04:51 +0000 Subject: [PATCH 12/72] fix(aurora): fixed command decorator --- aurora/configuration/commands.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 8a9c37a..aa38832 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -14,9 +14,12 @@ class Configuration(Mixin): async def aurora(self, ctx: commands.Context): """Settings and miscellaneous commands for Aurora.""" - @aurora.command(name="settings", aliases=["config", "options", "set"]) + @aurora.group(autohelp=True, name="settings", aliases=["config", "options", "set"]) async def aurora_settings(self, ctx: commands.Context): - """View Aurora configuration settings.""" + """Configure Aurora's settings.""" + + @aurora_settings.command(name="core") + async def aurora_settings_core(self, ctx: commands.Context): await ctx.send(embed=await embed(ctx)) @aurora_settings.command(name="addrole", aliases=["removerole"]) From 8fe8800853739424801808d3203fc0ddf4183c7a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:06:02 +0000 Subject: [PATCH 13/72] fix(aurora): fixed typeerror --- aurora/aurora.py | 1 - 1 file changed, 1 deletion(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index d41662f..dc2173b 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -67,7 +67,6 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylin logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) def __init__(self, bot: Red): - super().__init__() self.bot = bot register_config(config) disable_dateutil() From de5f21eb20d2e4ab913c591745b2cd295e54d335 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:06:58 +0000 Subject: [PATCH 14/72] Revert "fix(aurora): fixed typeerror" This reverts commit 8fe8800853739424801808d3203fc0ddf4183c7a. --- aurora/aurora.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aurora/aurora.py b/aurora/aurora.py index dc2173b..d41662f 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -67,6 +67,7 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylin logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) def __init__(self, bot: Red): + super().__init__() self.bot = bot register_config(config) disable_dateutil() From e27349a2ab4cb364b325514e5c115303145398f3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:08:29 +0000 Subject: [PATCH 15/72] fix(aurora): fixed incorrect import name --- aurora/abc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/abc.py b/aurora/abc.py index 89857bb..bd16d9b 100644 --- a/aurora/abc.py +++ b/aurora/abc.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from redbot.core import commands from redbot.core.bot import Red -from .utilities.config import Config +from .utilities.config import config class CompositeMetaClass(type(commands.Cog), type(ABC)): @@ -21,7 +21,7 @@ class Mixin(ABC): def __init__(self, *_args): super().__init__() - self.config: Config + self.config: config self.bot: Red ####################################################################### From fb9ee7381d7482342d8dd4923672d7432ff79a81 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:11:08 +0000 Subject: [PATCH 16/72] fix(aurora): fixed absent abstractmethods in mixin class --- aurora/abc.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/aurora/abc.py b/aurora/abc.py index bd16d9b..4e1846b 100644 --- a/aurora/abc.py +++ b/aurora/abc.py @@ -33,7 +33,19 @@ class Mixin(ABC): raise NotImplementedError() @abstractmethod - async def aurora_config(self, ctx: commands.Context) -> None: + async def aurora_settings(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_settings_core(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_settings_addrole(self, ctx: commands.Context) -> None: + raise NotImplementedError() + + @abstractmethod + async def aurora_settings_immunity(self, ctx: commands.Context) -> None: raise NotImplementedError() @abstractmethod From 656823611c532d80e663961b32575fd609f13aee Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:13:15 +0000 Subject: [PATCH 17/72] fix(aurora): updated config to have addrole_roles instead of blacklist_roles --- aurora/utilities/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/utilities/config.py b/aurora/utilities/config.py index a98b0b8..88090b7 100644 --- a/aurora/utilities/config.py +++ b/aurora/utilities/config.py @@ -16,7 +16,7 @@ def register_config(config_obj: Config): history_pagesize = 5, history_inline_pagesize = 6, auto_evidenceformat = False, - blacklist_roles = [] + addrole_roles = [] ) config_obj.register_user( history_ephemeral = None, From a7dc1400c487256e3cc9138132f550e4fd1f0bdf Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:13:33 +0000 Subject: [PATCH 18/72] fix(aurora): fixed UnboundLocalError in configuration.embed._addrole --- aurora/configuration/embed.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 8af50ed..e513e4b 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -82,12 +82,12 @@ async def _addrole(guild: Guild) -> str: """Generates a configuration menu field value for a guild's addrole whitelist.""" whitelist = await config.guild(guild).addrole_roles() - if blacklist: - blacklist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] - blacklist = '\n'.join(blacklist) + if whitelist: + whitelist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] + whitelist = '\n'.join(whitelist) else: - blacklist = warning("No roles are on the addrole whitelist!") - return blacklist + whitelist = warning("No roles are on the addrole whitelist!") + return whitelist async def _immune(guild: Guild) -> str: """Generates a configuration menu field value for a guild's immune roles.""" From b86a91882ff1e41faca652614abca237193bb787 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:29:13 +0000 Subject: [PATCH 19/72] misc(aurora): added docstrings/modified docstrings for some of the config commands --- aurora/configuration/commands.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index aa38832..41baf34 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -20,6 +20,7 @@ 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)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @@ -40,12 +41,12 @@ class Configuration(Mixin): @commands.admin() @commands.guild_only() async def aurora_import(self, ctx: commands.Context): - """Import moderations from other bots.""" + """Import moderation history from other bots.""" @aurora_import.command(name="aurora") @commands.admin() async def aurora_import_aurora(self, ctx: commands.Context): - """Import moderations from another bot using Aurora.""" + """Import moderation history from another bot using Aurora.""" if ( ctx.message.attachments and ctx.message.attachments[0].content_type @@ -63,7 +64,7 @@ class Configuration(Mixin): @aurora_import.command(name="galacticbot") @commands.admin() async def aurora_import_galacticbot(self, ctx: commands.Context): - """Import moderations from GalacticBot.""" + """Import moderation history from GalacticBot.""" if ( ctx.message.attachments and ctx.message.attachments[0].content_type From 74a857ca306a5bca0e1477a33cfb4e67482a6106 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:38:38 +0000 Subject: [PATCH 20/72] feat(docs): updated configuration page --- .docs/aurora/configuration.md | 219 ++++++---------------------------- 1 file changed, 37 insertions(+), 182 deletions(-) diff --git a/.docs/aurora/configuration.md b/.docs/aurora/configuration.md index 087cab3..3e3fe76 100644 --- a/.docs/aurora/configuration.md +++ b/.docs/aurora/configuration.md @@ -1,209 +1,64 @@ # Configuration -/// admonition | Outdated - type: danger -These docs have not been updated for the configuration rewrite yet. +/// admonition | Work in progress + type: warn +This page is still a work in progress. /// -## auroraset - - Usage: `[p]auroraset` - - Aliases: `moderationset, modset, moderationsettings, aurorasettings, and auroraconfig` +## aurora -Manage moderation commands. +- Usage: `[p]aurora` +- Aliases: `moderation, mod` -### auroraset ignorebots - - Usage: `[p]auroraset ignorebots` - - Restricted to: `ADMIN` +Settings and miscellaneous commands for Aurora. -Toggle if the cog should ignore other bots' moderations. +### aurora import -### auroraset user - - Usage: `[p]auroraset user` +- Usage: `[p]aurora import` +- Restricted to: `ADMIN` +- Checks: `server_only` -Manage configurations for user configuration options. +Import moderation history from other bots. -#### auroraset user history - - Usage: `[p]auroraset user history` +#### aurora import galacticbot -Manage configuration for the /history command. +- Usage: `[p]aurora import galacticbot` +- Restricted to: `ADMIN` -##### auroraset user history inline - - Usage: `[p]auroraset user history inline` +Import moderation history from GalacticBot. -Manage configuration for the /history command's inline argument. +#### aurora import aurora -###### auroraset user history inline toggle - - Usage: `[p]auroraset user history inline toggle ` +- Usage: `[p]aurora import aurora` +- Restricted to: `ADMIN` -Enable the /history command's inline argument by default. +Import moderation history from another bot using Aurora. -##### auroraset user history inline pagesize - - Usage: `[p]auroraset user history inline pagesize ` +### aurora settings -Set the amount of cases to display per page. +- Usage: `[p]aurora settings` +- Aliases: `config, options, and set` -#### auroraset user history pagesize - - Usage: `[p]auroraset user history pagesize ` +Configure Aurora's settings. -Set the amount of cases to display per page. +#### aurora settings core -#### auroraset user history ephemeral - - Usage: `[p]auroraset user history ephemeral ` - - Aliases: `hidden and hide` +- Usage: `[p]aurora settings core` -Toggle if the /history command should be ephemeral. +Manage Aurora's core settings. -### auroraset user autoevidence - - Usage: `[p]auroraset user autoevidence ` +#### aurora settings addrole -Toggle if the evidenceformat codeblock should be sent automatically. +- Usage: `[p]aurora settings addrole` +- Restricted to: `ADMIN` +- Aliases: `removerole` -## auroraset server - - Usage: `[p]auroraset server` - - Restricted to: `ADMIN` +Manage the addrole whitelist. +Roles added to this list are also applied to `/removerole`. -Manage default configurations for user configuration options, per server. +#### aurora settings immunity -### auroraset server history - - Usage: `[p]auroraset server history` - - Restricted to: `ADMIN` +- Usage: `[p]aurora settings immunity` +- Restricted to: `ADMIN` -Manage configuration for the /history command. - -#### auroraset server history inline - - Usage: `[p]auroraset server history inline` - - Restricted to: `ADMIN` - -Manage configuration for the /history command's inline argument. - -##### auroraset server history inline pagesize - - Usage: `[p]auroraset server history inline pagesize ` - - Restricted to: `ADMIN` - -Set the amount of cases to display per page. - -##### auroraset server history inline toggle - - Usage: `[p]auroraset server history inline toggle ` - - Restricted to: `ADMIN` - -Enable the /history command's inline argument by default. - -#### auroraset server history ephemeral - - Usage: `[p]auroraset server history ephemeral ` - - Restricted to: `ADMIN` - - Aliases: `hidden and hide` - -Toggle if the /history command should be ephemeral. - -#### auroraset server history pagesize - - Usage: `[p]auroraset server history pagesize ` - - Restricted to: `ADMIN` - -Set the amount of cases to display per page. - -### auroraset server autoevidence - - Usage: `[p]auroraset server autoevidence ` - -Toggle if the evidenceformat codeblock should be sent automatically. - -## auroraset showmoderator - - Usage: `[p]auroraset showmoderator` - - Restricted to: `ADMIN` - -Toggle if the cog should show the moderator in the case embed when dming a user. - -## auroraset immunity - - Usage: `[p]auroraset immunity` - - Restricted to: `ADMIN` - -Manage configuration for immune roles. - -### auroraset immunity add - - Usage: `[p]auroraset immunity add ` - - Restricted to: `ADMIN` - -Add a role to the immune roles list. - -### auroraset immunity remove - - Usage: `[p]auroraset immunity remove ` - - Restricted to: `ADMIN` - -Remove a role from the immune roles list. - -### auroraset immunity list - - Usage: `[p]auroraset immunity list` - - Restricted to: `ADMIN` - -List all immune roles. - -## auroraset permissions - - Usage: `[p]auroraset permissions` - - Restricted to: `ADMIN` - -Toggle whether the bot will check for discord permissions. - -## auroraset logchannel - - Usage: `[p]auroraset logchannel [channel=None]` - - Restricted to: `ADMIN` - -Set a channel to log infractions to. - -## auroraset import - - Usage: `[p]auroraset import` - - Restricted to: `ADMIN` - -Import moderations from other bots. - -### auroraset import galacticbot - - Usage: `[p]auroraset import galacticbot` - - Restricted to: `ADMIN` - -Import moderations from GalacticBot. - -### auroraset import aurora - - Usage: `[p]auroraset import aurora` - - Restricted to: `ADMIN` - -Import moderations from another bot using Aurora. - -## auroraset dm - - Usage: `[p]auroraset dm` - - Restricted to: `ADMIN` - -Toggle automatically messaging moderated users.

This option can be overridden by specifying the `silent` argument in any moderation command. - -## auroraset list - - Usage: `[p]auroraset list` - - Aliases: `view and show` - -List all moderation settings. - -## auroraset blacklist - - Usage: `[p]auroraset blacklist` - - Restricted to: `ADMIN` - -Manage configuration for the /blacklist command. - -### auroraset blacklist list - - Usage: `[p]auroraset blacklist list` - - Restricted to: `ADMIN` - -List all blacklist types. - -### auroraset blacklist remove - - Usage: `[p]auroraset blacklist remove ` - - Restricted to: `ADMIN` - -Remove a role's blacklist type. - -### auroraset blacklist add - - Usage: `[p]auroraset blacklist add ` - - Restricted to: `ADMIN` - -Add a role to the blacklist. - -# timedeltaconvert - - Usage: `[p]timedeltaconvert ` - - Aliases: `tdc` - -This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.

**Example usage**
`[p]timedeltaconvert 1 day 15hr 82 minutes 52s`
**Output**
`1 day, 16:22:52` +Manage the immunity whitelist. From ebccec54bf31a6d1c287880a183d6e28ea100521 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:39:20 +0000 Subject: [PATCH 21/72] fix(docs): warn --> warning --- .docs/aurora/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docs/aurora/configuration.md b/.docs/aurora/configuration.md index 3e3fe76..7df5f7b 100644 --- a/.docs/aurora/configuration.md +++ b/.docs/aurora/configuration.md @@ -1,7 +1,7 @@ # Configuration /// admonition | Work in progress - type: warn + type: warning This page is still a work in progress. /// From 14705efddd04766de2325e11269f38d983b6de64 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 14:58:53 +0000 Subject: [PATCH 22/72] 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)) From 900eb16aa9553d76403fc360206d20bb2b7730fa Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:01:20 +0000 Subject: [PATCH 23/72] fix(aurora): fixed circular import --- aurora/configuration/commands.py | 16 ++++++++++------ aurora/configuration/embed.py | 9 +++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 1342bf5..4b99561 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -1,10 +1,11 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning -from .embed import addrole_embed, embed, immune_embed -from ..abc import Mixin -from ..importers.aurora import ImportAuroraView -from ..importers.galacticbot import ImportGalacticBotView +from aurora.configuration.menus.core import Overrides +from aurora.configuration.embed import addrole_embed, embed, immune_embed +from aurora.abc import Mixin +from aurora.importers.aurora import ImportAuroraView +from aurora.importers.galacticbot import ImportGalacticBotView class Configuration(Mixin): @@ -21,8 +22,11 @@ class Configuration(Mixin): @aurora_settings.command(name="core") async def aurora_settings_core(self, ctx: commands.Context): """Manage Aurora's core settings.""" - menu = await embed(ctx) - await ctx.send(embed=menu[0], view=menu[1]) + if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): + view = None + else: + view = Overrides(ctx) + await ctx.send(embed=await embed(ctx), view=view) @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 0600fb9..e6eeca3 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -1,10 +1,9 @@ from typing import Union -from discord import Embed, Guild, Member, User, ui +from discord import Embed, Guild, Member, User from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning -from aurora.configuration.menus.core import Overrides from aurora.configuration.utils import get_bool_emoji, get_pagesize_str from aurora.utilities.config import config @@ -101,15 +100,13 @@ async def _immune(guild: Guild) -> str: immune = warning("No roles are set as immune roles!") return immune -async def embed(ctx: commands.Context) -> (Embed, ui.View): +async def embed(ctx: commands.Context) -> Embed: """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) - view = None - return (e, view) + return e async def addrole_embed(ctx: commands.Context) -> Embed: """Generates the addrole embed for a guild.""" From a5b0055256160b4e699222689964ad2c0e3a1b8a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:09:01 +0000 Subject: [PATCH 24/72] fix(aurora): hopefully fixed erroring views --- aurora/configuration/menus/core.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py index d7e78d8..d04e569 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/core.py @@ -11,27 +11,45 @@ class Overrides(ui.View): @ui.button(label="Auto Evidence Format", style=ButtonStyle.green) async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + await interaction.response.defer(ephemeral=True) current_setting = await config.user(self.ctx.author).auto_evidenceformat() - if current_setting: + if current_setting is not None: await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) else: await config.user(self.ctx.author).auto_evidenceformat.set(True) + if current_setting is True: + response = "Auto Evidence Format disabled." + else: + response = "Auto Evidence Format enabled." await self.ctx.message.edit(embed=await embed(self.ctx)) + await interaction.followup.send(content=response, ephemeral=True) @ui.button(label="Ephemeral", style=ButtonStyle.green) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + await interaction.response.defer(ephemeral=True) 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) + if current_setting is True: + response = "Ephemeral disabled." + else: + response = "Ephemeral enabled." await self.ctx.message.edit(embed=await embed(self.ctx)) + await interaction.followup.send(content=response, ephemeral=True) @ui.button(label="Inline", style=ButtonStyle.green) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + await interaction.response.defer(ephemeral=True) 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) + if current_setting is True: + response = "Inline disabled." + else: + response = "Inline enabled." await self.ctx.message.edit(embed=await embed(self.ctx)) + await interaction.followup.send(content=response, ephemeral=True) From a7f6cff62502832d1c93156505d11adefc6eb7fd Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:20:47 +0000 Subject: [PATCH 25/72] fix(aurora): possibly fixed editing the config menu on settings change --- aurora/configuration/menus/core.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py index d04e569..2d92018 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/core.py @@ -11,18 +11,13 @@ class Overrides(ui.View): @ui.button(label="Auto Evidence Format", style=ButtonStyle.green) async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - await interaction.response.defer(ephemeral=True) + await interaction.response.defer() current_setting = await config.user(self.ctx.author).auto_evidenceformat() if current_setting is not None: await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) else: await config.user(self.ctx.author).auto_evidenceformat.set(True) - if current_setting is True: - response = "Auto Evidence Format disabled." - else: - response = "Auto Evidence Format enabled." - await self.ctx.message.edit(embed=await embed(self.ctx)) - await interaction.followup.send(content=response, ephemeral=True) + await interaction.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 From 1e9a6abe74aedd6ad3847405d476d9010ae46e6a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:22:36 +0000 Subject: [PATCH 26/72] fix(aurora): you can no longer change other people's overrides --- aurora/configuration/menus/core.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py index 2d92018..a2b4022 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/core.py @@ -12,6 +12,9 @@ class Overrides(ui.View): @ui.button(label="Auto Evidence Format", style=ButtonStyle.green) async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return current_setting = await config.user(self.ctx.author).auto_evidenceformat() if current_setting is not None: await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) @@ -21,30 +24,26 @@ class Overrides(ui.View): @ui.button(label="Ephemeral", style=ButtonStyle.green) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - await interaction.response.defer(ephemeral=True) + await interaction.response.defer() + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return 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) - if current_setting is True: - response = "Ephemeral disabled." - else: - response = "Ephemeral enabled." - await self.ctx.message.edit(embed=await embed(self.ctx)) - await interaction.followup.send(content=response, ephemeral=True) + await interaction.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 - await interaction.response.defer(ephemeral=True) + await interaction.response.defer() + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return 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) - if current_setting is True: - response = "Inline disabled." - else: - response = "Inline enabled." - await self.ctx.message.edit(embed=await embed(self.ctx)) - await interaction.followup.send(content=response, ephemeral=True) + await interaction.message.edit(embed=await embed(self.ctx)) From acf2484cbb0beb842c97eed90cc8648a0b669fbf Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:24:18 +0000 Subject: [PATCH 27/72] fix(aurora): followup.send instead of response.send_message --- aurora/configuration/menus/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py index a2b4022..dea74d5 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/core.py @@ -13,7 +13,7 @@ class Overrides(ui.View): async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return current_setting = await config.user(self.ctx.author).auto_evidenceformat() if current_setting is not None: From ffcaeec653a577436f9d68a99cd1066e50998abb Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 15 Jan 2024 15:25:09 +0000 Subject: [PATCH 28/72] fix(aurora): applied previous commit's fix to the other buttons --- aurora/configuration/menus/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/core.py index dea74d5..5b5d2c0 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/core.py @@ -26,7 +26,7 @@ class Overrides(ui.View): async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return current_setting = await config.user(self.ctx.author).history_ephemeral() if current_setting: @@ -39,7 +39,7 @@ class Overrides(ui.View): async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return current_setting = await config.user(self.ctx.author).history_inline() if current_setting: From 7ae16ea258ba3551bd2b2703f25cc773aab55f13 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:31:11 +0000 Subject: [PATCH 29/72] feat(aurora): moving to select menus for user overrides --- aurora/configuration/commands.py | 6 +++--- .../menus/{core.py => overrides.py} | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) rename aurora/configuration/menus/{core.py => overrides.py} (75%) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 4b99561..3244a8e 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -1,7 +1,7 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning -from aurora.configuration.menus.core import Overrides +from aurora.configuration.menus.overrides import Overrides from aurora.configuration.embed import addrole_embed, embed, immune_embed from aurora.abc import Mixin from aurora.importers.aurora import ImportAuroraView @@ -19,9 +19,9 @@ class Configuration(Mixin): async def aurora_settings(self, ctx: commands.Context): """Configure Aurora's settings.""" - @aurora_settings.command(name="core") + @aurora_settings.command(name="user") async def aurora_settings_core(self, ctx: commands.Context): - """Manage Aurora's core settings.""" + """Manage Aurora's user overriddable settings.""" if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): view = None else: diff --git a/aurora/configuration/menus/core.py b/aurora/configuration/menus/overrides.py similarity index 75% rename from aurora/configuration/menus/core.py rename to aurora/configuration/menus/overrides.py index 5b5d2c0..15e822c 100644 --- a/aurora/configuration/menus/core.py +++ b/aurora/configuration/menus/overrides.py @@ -1,4 +1,4 @@ -from discord import ui, ButtonStyle, Interaction +from discord import ui, ButtonStyle, Interaction, SelectOption from redbot.core import commands from aurora.configuration.embed import embed @@ -9,20 +9,20 @@ class Overrides(ui.View): 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 + @ui.select(cls=ui.Select, placeholder="Auto Evidence Format", row=0, options=[ + SelectOption(label="Enabled", value=True, emoji="✅"), + SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Default", value=None, emoji="🔁") + ]) + async def auto_evidenceformat(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - current_setting = await config.user(self.ctx.author).auto_evidenceformat() - if current_setting is not None: - await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) - else: - await config.user(self.ctx.author).auto_evidenceformat.set(True) + await config.user(self.ctx.author).auto_evidenceformat.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Ephemeral", style=ButtonStyle.green) + @ui.button(label="Ephemeral (U)", style=ButtonStyle.green, row=0) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: @@ -35,7 +35,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_ephemeral.set(True) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Inline", style=ButtonStyle.green) + @ui.button(label="Inline (U)", style=ButtonStyle.green, row=0) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: From 98a2c463b91ddadfbf6615cde3e1d8a098af1db3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:33:25 +0000 Subject: [PATCH 30/72] fix(aurora): fixed override embed erroring --- aurora/configuration/menus/overrides.py | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 15e822c..be1c41a 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -22,28 +22,28 @@ class Overrides(ui.View): await config.user(self.ctx.author).auto_evidenceformat.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Ephemeral (U)", style=ButtonStyle.green, row=0) - async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + @ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ + SelectOption(label="Enabled", value=True, emoji="✅"), + SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Default", value=None, emoji="🔁") + ]) + async def ephemeral(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - 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 config.user(self.ctx.author).history_ephemeral.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Inline (U)", style=ButtonStyle.green, row=0) + @ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ + SelectOption(label="Enabled", value=True, emoji="✅"), + SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Default", value=None, emoji="🔁") + ]) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - 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 config.user(self.ctx.author).history_inline.set(button.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) From a43f3de8bcafd0da55e1b3bfb9e2904598e16274 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:36:02 +0000 Subject: [PATCH 31/72] fix(aurora): fixed bad request --- aurora/configuration/commands.py | 5 +---- aurora/configuration/menus/overrides.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 3244a8e..11b226e 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -22,10 +22,7 @@ class Configuration(Mixin): @aurora_settings.command(name="user") async def aurora_settings_core(self, ctx: commands.Context): """Manage Aurora's user overriddable settings.""" - if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): - view = None - else: - view = Overrides(ctx) + view = Overrides(ctx) await ctx.send(embed=await embed(ctx), view=view) @aurora_settings.command(name="addrole", aliases=["removerole"]) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index be1c41a..244ad78 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -12,38 +12,47 @@ class Overrides(ui.View): @ui.select(cls=ui.Select, placeholder="Auto Evidence Format", row=0, options=[ SelectOption(label="Enabled", value=True, emoji="✅"), SelectOption(label="Disabled", value=False, emoji="❌"), - SelectOption(label="Default", value=None, emoji="🔁") + SelectOption(label="Default", value='None', emoji="🔁") ]) async def auto_evidenceformat(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - await config.user(self.ctx.author).auto_evidenceformat.set(select.values[0]) + if select.values[0] == 'None': + await config.user(self.ctx.author).auto_evidenceformat.clear() + else: + await config.user(self.ctx.author).auto_evidenceformat.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ SelectOption(label="Enabled", value=True, emoji="✅"), SelectOption(label="Disabled", value=False, emoji="❌"), - SelectOption(label="Default", value=None, emoji="🔁") + SelectOption(label="Default", value='None', emoji="🔁") ]) async def ephemeral(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - await config.user(self.ctx.author).history_ephemeral.set(select.values[0]) + if select.values[0] == 'None': + await config.user(self.ctx.author).history_ephemeral.clear() + else: + await config.user(self.ctx.author).history_ephemeral.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ SelectOption(label="Enabled", value=True, emoji="✅"), SelectOption(label="Disabled", value=False, emoji="❌"), - SelectOption(label="Default", value=None, emoji="🔁") + SelectOption(label="Default", value='None', emoji="🔁") ]) - async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + async def inline(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument await interaction.response.defer() if self.ctx.author != interaction.user: await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) return - await config.user(self.ctx.author).history_inline.set(button.values[0]) + if select.values[0] == 'None': + await config.user(self.ctx.author).history_inline.clear() + else: + await config.user(self.ctx.author).history_inline.set(select.values[0]) await interaction.message.edit(embed=await embed(self.ctx)) From 219b18e34bcf683fefabdc36b0d9264574d13836 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:39:00 +0000 Subject: [PATCH 32/72] fix(aurora): fixed setting overrides not working --- aurora/configuration/menus/overrides.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 244ad78..810db4c 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -10,8 +10,8 @@ class Overrides(ui.View): self.ctx = ctx @ui.select(cls=ui.Select, placeholder="Auto Evidence Format", row=0, options=[ - SelectOption(label="Enabled", value=True, emoji="✅"), - SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Enabled", value=1, emoji="✅"), + SelectOption(label="Disabled", value=0, emoji="❌"), SelectOption(label="Default", value='None', emoji="🔁") ]) async def auto_evidenceformat(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument @@ -22,12 +22,12 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).auto_evidenceformat.clear() else: - await config.user(self.ctx.author).auto_evidenceformat.set(select.values[0]) + await config.user(self.ctx.author).auto_evidenceformat.set(bool(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ - SelectOption(label="Enabled", value=True, emoji="✅"), - SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Enabled", value=1, emoji="✅"), + SelectOption(label="Disabled", value=0, emoji="❌"), SelectOption(label="Default", value='None', emoji="🔁") ]) async def ephemeral(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument @@ -38,12 +38,12 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).history_ephemeral.clear() else: - await config.user(self.ctx.author).history_ephemeral.set(select.values[0]) + await config.user(self.ctx.author).history_ephemeral.set(bool(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ - SelectOption(label="Enabled", value=True, emoji="✅"), - SelectOption(label="Disabled", value=False, emoji="❌"), + SelectOption(label="Enabled", value=1, emoji="✅"), + SelectOption(label="Disabled", value=0, emoji="❌"), SelectOption(label="Default", value='None', emoji="🔁") ]) async def inline(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument @@ -54,5 +54,5 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).history_inline.clear() else: - await config.user(self.ctx.author).history_inline.set(select.values[0]) + await config.user(self.ctx.author).history_inline.set(bool(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) From c0ab9e89f3a9d799f9a700aa0e1796fcde4317f7 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:42:12 +0000 Subject: [PATCH 33/72] fix(aurora): fix boolean conversion in override menu --- aurora/configuration/menus/overrides.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 810db4c..aa39d2c 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -22,7 +22,7 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).auto_evidenceformat.clear() else: - await config.user(self.ctx.author).auto_evidenceformat.set(bool(select.values[0])) + await config.user(self.ctx.author).auto_evidenceformat.set(bool(int(select.values[0]))) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ @@ -38,7 +38,7 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).history_ephemeral.clear() else: - await config.user(self.ctx.author).history_ephemeral.set(bool(select.values[0])) + await config.user(self.ctx.author).history_ephemeral.set(bool(int(select.values[0]))) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ @@ -54,5 +54,5 @@ class Overrides(ui.View): if select.values[0] == 'None': await config.user(self.ctx.author).history_inline.clear() else: - await config.user(self.ctx.author).history_inline.set(bool(select.values[0])) + await config.user(self.ctx.author).history_inline.set(bool(int(select.values[0]))) await interaction.message.edit(embed=await embed(self.ctx)) From c55cb53a41a6801601c18c2c9c34c707438fdadc Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:57:21 +0000 Subject: [PATCH 34/72] feat(aurora): added configuration options for all of the user overrides --- aurora/configuration/menus/overrides.py | 125 +++++++++++++++++------- aurora/configuration/utils.py | 13 +++ 2 files changed, 103 insertions(+), 35 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index aa39d2c..0202ab0 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -1,7 +1,8 @@ -from discord import ui, ButtonStyle, Interaction, SelectOption +from discord import ui, ButtonStyle, Interaction from redbot.core import commands from aurora.configuration.embed import embed +from aurora.configuration.utils import create_pagesize_options from aurora.utilities.config import config class Overrides(ui.View): @@ -9,50 +10,104 @@ class Overrides(ui.View): super().__init__() self.ctx = ctx - @ui.select(cls=ui.Select, placeholder="Auto Evidence Format", row=0, options=[ - SelectOption(label="Enabled", value=1, emoji="✅"), - SelectOption(label="Disabled", value=0, emoji="❌"), - SelectOption(label="Default", value='None', emoji="🔁") - ]) - async def auto_evidenceformat(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument - await interaction.response.defer() + @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0) + async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: - await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return - if select.values[0] == 'None': - await config.user(self.ctx.author).auto_evidenceformat.clear() + await interaction.response.defer() + current_setting = await config.user(self.ctx.author).auto_evidenceformat() + if current_setting is not None: + await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) else: - await config.user(self.ctx.author).auto_evidenceformat.set(bool(int(select.values[0]))) + await config.user(self.ctx.author).auto_evidenceformat.set(True) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ - SelectOption(label="Enabled", value=1, emoji="✅"), - SelectOption(label="Disabled", value=0, emoji="❌"), - SelectOption(label="Default", value='None', emoji="🔁") - ]) - async def ephemeral(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument - await interaction.response.defer() + @ui.button(label="X", style=ButtonStyle.red, row=0) + async def auto_evidenceformat_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: - await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return - if select.values[0] == 'None': - await config.user(self.ctx.author).history_ephemeral.clear() - else: - await config.user(self.ctx.author).history_ephemeral.set(bool(int(select.values[0]))) + await interaction.response.defer() + await config.user(self.ctx.author).auto_evidenceformat.clear() await interaction.message.edit(embed=await embed(self.ctx)) - @ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ - SelectOption(label="Enabled", value=1, emoji="✅"), - SelectOption(label="Disabled", value=0, emoji="❌"), - SelectOption(label="Default", value='None', emoji="🔁") - ]) - async def inline(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument - await interaction.response.defer() + @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0) + async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: - await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return - if select.values[0] == 'None': - await config.user(self.ctx.author).history_inline.clear() + await interaction.response.defer() + 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_inline.set(bool(int(select.values[0]))) + await config.user(self.ctx.author).history_ephemeral.set(True) + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="X", style=ButtonStyle.red, row=0) + async def ephemeral_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_ephemeral.clear() + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="Inline", style=ButtonStyle.green, row=0) + async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + 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 interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="X", style=ButtonStyle.red, row=0) + async def inline_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_inline.clear() + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) + async def inline_pagesize(self, select: ui.Select, interaction: Interaction): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="X", style=ButtonStyle.red, row=1) + async def inline_pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_inline_pagesize.clear() + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="Pagesize", options=create_pagesize_options(), row=2) + async def pagesize(self, select: ui.Select, interaction: Interaction): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) + await interaction.message.edit(embed=await embed(self.ctx)) + + @ui.button(label="X", style=ButtonStyle.red, row=2) + async def pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if self.ctx.author != interaction.user: + await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) + return + await interaction.response.defer() + await config.user(self.ctx.author).history_pagesize.clear() await interaction.message.edit(embed=await embed(self.ctx)) diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py index ea3c5e0..c836cf4 100644 --- a/aurora/configuration/utils.py +++ b/aurora/configuration/utils.py @@ -1,5 +1,7 @@ from typing import Union +from discord import SelectOption + def get_bool_emoji(value: bool) -> str: """Returns a unicode emoji based on a boolean value.""" if value is True: @@ -13,3 +15,14 @@ def get_pagesize_str(value: Union[int, None]) -> str: if value is None: return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" return str(value) + " cases per page" + +def create_pagesize_options() -> list[SelectOption]: + """Returns a list of SelectOptions for pagesize configuration.""" + return [ + SelectOption( + label=str(i), + value=str(i), + description=f"Set the pagesize to {i}.", + ) + for i in range(1, 21) + ] From fe50eddc25dda8cb61f2b27c4ab0d0583cb6bd37 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:58:33 +0000 Subject: [PATCH 35/72] fix(aurora): fixed incorrect decorator --- aurora/configuration/menus/overrides.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 0202ab0..e5bae55 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -77,7 +77,7 @@ class Overrides(ui.View): await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) - async def inline_pagesize(self, select: ui.Select, interaction: Interaction): # pylint: disable=unused-argument + async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return @@ -94,8 +94,8 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.clear() await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Pagesize", options=create_pagesize_options(), row=2) - async def pagesize(self, select: ui.Select, interaction: Interaction): # pylint: disable=unused-argument + @ui.select(label="Pagesize", options=create_pagesize_options(), row=2) + async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return From b53ca9cac4a55757c766fea8956c821541c32408 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 10:59:02 +0000 Subject: [PATCH 36/72] fix(aurora): fixed incorrect decorator (again) --- aurora/configuration/menus/overrides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index e5bae55..b1f0b06 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -94,7 +94,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.clear() await interaction.message.edit(embed=await embed(self.ctx)) - @ui.select(label="Pagesize", options=create_pagesize_options(), row=2) + @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) From 6d7b551f25fc2a40620cff64c5202c64df702d97 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:00:46 +0000 Subject: [PATCH 37/72] fix(aurora): fixed width error --- aurora/configuration/menus/overrides.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index b1f0b06..07c29d6 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -23,7 +23,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).auto_evidenceformat.set(True) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=0) + @ui.button(label="Reset", style=ButtonStyle.red, row=1) async def auto_evidenceformat_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -45,7 +45,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_ephemeral.set(True) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=0) + @ui.button(label="Reset", style=ButtonStyle.red, row=1) async def ephemeral_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -67,7 +67,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline.set(True) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=0) + @ui.button(label="Reset", style=ButtonStyle.red, row=1) async def inline_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -76,7 +76,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline.clear() await interaction.message.edit(embed=await embed(self.ctx)) - @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) + @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=2) async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -85,7 +85,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=1) + @ui.button(label="X", style=ButtonStyle.red, row=2) async def inline_pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -94,7 +94,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.clear() await interaction.message.edit(embed=await embed(self.ctx)) - @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) + @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=3) async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -103,7 +103,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=2) + @ui.button(label="X", style=ButtonStyle.red, row=3) async def pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) From 045af7788be740e166405e6fd49f06ffba9a0ec1 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:04:28 +0000 Subject: [PATCH 38/72] fix(aurora): fixed width error --- aurora/configuration/menus/overrides.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 07c29d6..5e3d4f9 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -85,7 +85,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=2) + @ui.button(label="Reset Inline Pagesize", style=ButtonStyle.red, row=4) async def inline_pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -103,7 +103,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="X", style=ButtonStyle.red, row=3) + @ui.button(label="Reset Pagesize", style=ButtonStyle.red, row=4) async def pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) From 56857554e9a242b4064fb403fdf84eade478e331 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:11:38 +0000 Subject: [PATCH 39/72] fix(aurora): changed a whole bunch of stuff in the user override config menu --- aurora/configuration/menus/overrides.py | 73 ++++++------------------- aurora/configuration/utils.py | 21 +++++-- 2 files changed, 32 insertions(+), 62 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 5e3d4f9..941bb94 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -17,19 +17,12 @@ class Overrides(ui.View): return await interaction.response.defer() current_setting = await config.user(self.ctx.author).auto_evidenceformat() - if current_setting is not None: - await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting) - else: + if current_setting is False: + await config.user(self.ctx.author).auto_evidenceformat.clear() + if current_setting is None: await config.user(self.ctx.author).auto_evidenceformat.set(True) - await interaction.message.edit(embed=await embed(self.ctx)) - - @ui.button(label="Reset", style=ButtonStyle.red, row=1) - async def auto_evidenceformat_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) - return - await interaction.response.defer() - await config.user(self.ctx.author).auto_evidenceformat.clear() + else: + await config.user(self.ctx.author).auto_evidenceformat.set(False) await interaction.message.edit(embed=await embed(self.ctx)) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0) @@ -39,19 +32,12 @@ class Overrides(ui.View): return await interaction.response.defer() 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: + if current_setting is False: + await config.user(self.ctx.author).history_ephemeral.clear() + if current_setting is None: await config.user(self.ctx.author).history_ephemeral.set(True) - await interaction.message.edit(embed=await embed(self.ctx)) - - @ui.button(label="Reset", style=ButtonStyle.red, row=1) - async def ephemeral_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) - return - await interaction.response.defer() - await config.user(self.ctx.author).history_ephemeral.clear() + else: + await config.user(self.ctx.author).history_ephemeral.set(False) await interaction.message.edit(embed=await embed(self.ctx)) @ui.button(label="Inline", style=ButtonStyle.green, row=0) @@ -61,22 +47,15 @@ class Overrides(ui.View): return await interaction.response.defer() 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: + if current_setting is False: + await config.user(self.ctx.author).history_inline.clear() + if current_setting is None: await config.user(self.ctx.author).history_inline.set(True) + else: + await config.user(self.ctx.author).history_inline.set(False) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Reset", style=ButtonStyle.red, row=1) - async def inline_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) - return - await interaction.response.defer() - await config.user(self.ctx.author).history_inline.clear() - await interaction.message.edit(embed=await embed(self.ctx)) - - @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=2) + @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -85,16 +64,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - @ui.button(label="Reset Inline Pagesize", style=ButtonStyle.red, row=4) - async def inline_pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) - return - await interaction.response.defer() - await config.user(self.ctx.author).history_inline_pagesize.clear() - await interaction.message.edit(embed=await embed(self.ctx)) - - @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=3) + @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) @@ -102,12 +72,3 @@ class Overrides(ui.View): await interaction.response.defer() await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) - - @ui.button(label="Reset Pagesize", style=ButtonStyle.red, row=4) - async def pagesize_reset(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument - if self.ctx.author != interaction.user: - await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) - return - await interaction.response.defer() - await config.user(self.ctx.author).history_pagesize.clear() - await interaction.message.edit(embed=await embed(self.ctx)) diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py index c836cf4..fab5426 100644 --- a/aurora/configuration/utils.py +++ b/aurora/configuration/utils.py @@ -18,11 +18,20 @@ def get_pagesize_str(value: Union[int, None]) -> str: def create_pagesize_options() -> list[SelectOption]: """Returns a list of SelectOptions for pagesize configuration.""" - return [ + options = [] + options.append( SelectOption( - label=str(i), - value=str(i), - description=f"Set the pagesize to {i}.", + label="Default", + value="default", + description="Reset the pagesize to the default value.", ) - for i in range(1, 21) - ] + ) + for i in range(1, 21): + options.append( + SelectOption( + label=str(i), + value=str(i), + description=f"Set the pagesize to {i}.", + ) + ) + return options From d20cb4c3bc5db3925dad59e21c49f63fc105e2d3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:18:05 +0000 Subject: [PATCH 40/72] fix(aurora): fixed resetting pagesize --- aurora/configuration/menus/overrides.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 941bb94..fbb9bb1 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -61,7 +61,10 @@ class Overrides(ui.View): await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return await interaction.response.defer() - await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) + if select.values[0] == "default": + await config.user(self.ctx.author).history_inline_pagesize.clear() + else: + await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) @@ -70,5 +73,8 @@ class Overrides(ui.View): await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return await interaction.response.defer() - await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) + if select.values[0] == "default": + await config.user(self.ctx.author).history_pagesize.clear() + else: + await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) await interaction.message.edit(embed=await embed(self.ctx)) From 4795fac5acf17987afa90e2fc696ed9e73ba3afb Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:20:21 +0000 Subject: [PATCH 41/72] fix(aurora): use elif instead of if --- aurora/configuration/menus/overrides.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index fbb9bb1..7094777 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -19,7 +19,7 @@ class Overrides(ui.View): current_setting = await config.user(self.ctx.author).auto_evidenceformat() if current_setting is False: await config.user(self.ctx.author).auto_evidenceformat.clear() - if current_setting is None: + elif current_setting is None: await config.user(self.ctx.author).auto_evidenceformat.set(True) else: await config.user(self.ctx.author).auto_evidenceformat.set(False) @@ -34,7 +34,7 @@ class Overrides(ui.View): current_setting = await config.user(self.ctx.author).history_ephemeral() if current_setting is False: await config.user(self.ctx.author).history_ephemeral.clear() - if current_setting is None: + elif current_setting is None: await config.user(self.ctx.author).history_ephemeral.set(True) else: await config.user(self.ctx.author).history_ephemeral.set(False) @@ -49,7 +49,7 @@ class Overrides(ui.View): current_setting = await config.user(self.ctx.author).history_inline() if current_setting is False: await config.user(self.ctx.author).history_inline.clear() - if current_setting is None: + elif current_setting is None: await config.user(self.ctx.author).history_inline.set(True) else: await config.user(self.ctx.author).history_inline.set(False) From 0bf6143bf30bac2755f81ff8995dbd67c241428c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:24:39 +0000 Subject: [PATCH 42/72] fix(aurora): fixing some stuff relating to embed generation --- aurora/abc.py | 2 +- aurora/configuration/commands.py | 8 ++++---- aurora/configuration/embed.py | 23 ++++++++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/aurora/abc.py b/aurora/abc.py index 4e1846b..f34d9a9 100644 --- a/aurora/abc.py +++ b/aurora/abc.py @@ -37,7 +37,7 @@ class Mixin(ABC): raise NotImplementedError() @abstractmethod - async def aurora_settings_core(self, ctx: commands.Context) -> None: + async def aurora_settings_overrides(self, ctx: commands.Context) -> None: raise NotImplementedError() @abstractmethod diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 11b226e..cf68dd1 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -2,7 +2,7 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning from aurora.configuration.menus.overrides import Overrides -from aurora.configuration.embed import addrole_embed, embed, immune_embed +from aurora.configuration.embed import addrole_embed, overrides, immune_embed from aurora.abc import Mixin from aurora.importers.aurora import ImportAuroraView from aurora.importers.galacticbot import ImportGalacticBotView @@ -19,11 +19,11 @@ class Configuration(Mixin): async def aurora_settings(self, ctx: commands.Context): """Configure Aurora's settings.""" - @aurora_settings.command(name="user") - async def aurora_settings_core(self, ctx: commands.Context): + @aurora_settings.command(name="overrides", aliases=["override", "user"]) + async def aurora_settings_overrides(self, ctx: commands.Context): """Manage Aurora's user overriddable settings.""" view = Overrides(ctx) - await ctx.send(embed=await embed(ctx), view=view) + await ctx.send(embed=await overrides(ctx), view=view) @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 e6eeca3..9144540 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -17,18 +17,18 @@ async def _core(ctx: commands.Context) -> Embed: e.set_thumbnail(url=ctx.bot.user.display_avatar.url) return e -async def _overrides(user: Union[Member, User]) -> str: +async def overrides(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a user's overrides.""" override_settings = { - "ephemeral": await config.user(user).history_ephemeral(), - "inline": await config.user(user).history_inline(), - "inline_pagesize": await config.user(user).history_inline_pagesize(), - "pagesize": await config.user(user).history_pagesize(), - "auto_evidenceformat": await config.user(user).auto_evidenceformat() + "ephemeral": await config.user(ctx.author).history_ephemeral(), + "inline": await config.user(ctx.author).history_inline(), + "inline_pagesize": await config.user(ctx.author).history_inline_pagesize(), + "pagesize": await config.user(ctx.author).history_pagesize(), + "auto_evidenceformat": await config.user(ctx.author).auto_evidenceformat() } - overrides = [ + override_str = [ "These settings will override the relevant guild settings.\n", # Add an extra line between the subtitle and the settings bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), @@ -36,8 +36,13 @@ async def _overrides(user: Union[Member, User]) -> str: bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] - overrides = '\n'.join(overrides) - return overrides + override_str = '\n'.join(override_str) + + e = _core(ctx) + e.title += ": User Overrides" + e.add_field(name="User Overrides", value=override_str, inline=False) + return e + return override_str async def _guild(guild: Guild) -> str: """Generates a configuration menu field value for a guild's settings.""" From 7c6322041de49053f9fdb2382f5d31284581d75f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:28:51 +0000 Subject: [PATCH 43/72] fix(aurora): fixed overrides embed --- aurora/configuration/embed.py | 12 ++++++------ aurora/configuration/menus/overrides.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 9144540..d96875b 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -11,14 +11,13 @@ async def _core(ctx: commands.Context) -> Embed: """Generates the core embed for configuration menus to use.""" e = Embed( title="Aurora Configuration Menu", - description="Use the buttons below to configure Aurora.", color=await ctx.embed_color() ) e.set_thumbnail(url=ctx.bot.user.display_avatar.url) return e async def overrides(ctx: commands.Context) -> Embed: - """Generates a configuration menu field value for a user's overrides.""" + """Generates a configuration menu embed for a user's overrides.""" override_settings = { "ephemeral": await config.user(ctx.author).history_ephemeral(), @@ -29,7 +28,6 @@ async def overrides(ctx: commands.Context) -> Embed: } override_str = [ - "These settings will override the relevant guild settings.\n", # Add an extra line between the subtitle and the settings bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), bold("Inline: ") + get_bool_emoji(override_settings['inline']), @@ -38,11 +36,13 @@ async def overrides(ctx: commands.Context) -> Embed: ] override_str = '\n'.join(override_str) - e = _core(ctx) + e = await _core(ctx) e.title += ": User Overrides" - e.add_field(name="User Overrides", value=override_str, inline=False) + e.description = """ + Use the buttons below to manage your user overrides. + These settings will override the relevant guild settings.\n\n + """ + override_str return e - return override_str async def _guild(guild: Guild) -> str: """Generates a configuration menu field value for a guild's settings.""" diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 7094777..7ce1b31 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -1,7 +1,7 @@ from discord import ui, ButtonStyle, Interaction from redbot.core import commands -from aurora.configuration.embed import embed +from aurora.configuration.embed import overrides from aurora.configuration.utils import create_pagesize_options from aurora.utilities.config import config @@ -23,7 +23,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).auto_evidenceformat.set(True) else: await config.user(self.ctx.author).auto_evidenceformat.set(False) - await interaction.message.edit(embed=await embed(self.ctx)) + await interaction.message.edit(embed=await overrides(self.ctx)) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -38,7 +38,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_ephemeral.set(True) else: await config.user(self.ctx.author).history_ephemeral.set(False) - await interaction.message.edit(embed=await embed(self.ctx)) + await interaction.message.edit(embed=await overrides(self.ctx)) @ui.button(label="Inline", style=ButtonStyle.green, row=0) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -53,7 +53,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline.set(True) else: await config.user(self.ctx.author).history_inline.set(False) - await interaction.message.edit(embed=await embed(self.ctx)) + await interaction.message.edit(embed=await overrides(self.ctx)) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument @@ -65,7 +65,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.clear() else: await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) - await interaction.message.edit(embed=await embed(self.ctx)) + await interaction.message.edit(embed=await overrides(self.ctx)) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument @@ -77,4 +77,4 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_pagesize.clear() else: await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) - await interaction.message.edit(embed=await embed(self.ctx)) + await interaction.message.edit(embed=await overrides(self.ctx)) From aaf6fcaa3778b12d5207681ca96f9c75322afc04 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:29:58 +0000 Subject: [PATCH 44/72] fix(aurora): fixed formatting in overrides embed --- aurora/configuration/embed.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index d96875b..fd9b153 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -28,11 +28,11 @@ async def overrides(ctx: commands.Context) -> Embed: } override_str = [ - bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), - bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), - bold("Inline: ") + get_bool_emoji(override_settings['inline']), - bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), - bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), + bold("- Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), + bold("- Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), + bold("- Inline: ") + get_bool_emoji(override_settings['inline']), + bold("- Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + bold("- Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] override_str = '\n'.join(override_str) @@ -40,7 +40,7 @@ async def overrides(ctx: commands.Context) -> Embed: e.title += ": User Overrides" e.description = """ Use the buttons below to manage your user overrides. - These settings will override the relevant guild settings.\n\n + These settings will override the relevant guild settings.\n """ + override_str return e From d83e1bf731e647706628fa3b3e8fbd9b6161492c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:30:51 +0000 Subject: [PATCH 45/72] fix(aurora): fixed list formatting in overrides embed --- aurora/configuration/embed.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index fd9b153..90b21c0 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -28,11 +28,11 @@ async def overrides(ctx: commands.Context) -> Embed: } override_str = [ - bold("- Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), - bold("- Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), - bold("- Inline: ") + get_bool_emoji(override_settings['inline']), - bold("- Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), - bold("- Pagesize: ") + get_pagesize_str(override_settings['pagesize']), + '-' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), + '-' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), + '-' + bold("Inline: ") + get_bool_emoji(override_settings['inline']), + '-' + bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + '-' + bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] override_str = '\n'.join(override_str) From f97f010decfc2c57dc3f823c408fe2933d759a8b Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:31:16 +0000 Subject: [PATCH 46/72] fix(aurora): fixed list formatting for real this time --- aurora/configuration/embed.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 90b21c0..2d25ad8 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -28,11 +28,11 @@ async def overrides(ctx: commands.Context) -> Embed: } override_str = [ - '-' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), - '-' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), - '-' + bold("Inline: ") + get_bool_emoji(override_settings['inline']), - '-' + bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), - '-' + bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), + '- ' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), + '- ' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), + '- ' + bold("Inline: ") + get_bool_emoji(override_settings['inline']), + '- ' + bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + '- ' + bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] override_str = '\n'.join(override_str) From 45286ded55d7515c1d487ede8148c8a573121247 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:50:09 +0000 Subject: [PATCH 47/72] feat(aurora): added aurora settings guild command --- aurora/abc.py | 4 + aurora/configuration/commands.py | 14 ++-- aurora/configuration/embed.py | 132 ++++++++++++++++++------------- 3 files changed, 89 insertions(+), 61 deletions(-) diff --git a/aurora/abc.py b/aurora/abc.py index f34d9a9..a228aaa 100644 --- a/aurora/abc.py +++ b/aurora/abc.py @@ -40,6 +40,10 @@ class Mixin(ABC): async def aurora_settings_overrides(self, ctx: commands.Context) -> None: raise NotImplementedError() + @abstractmethod + async def aurora_settings_guild(self, ctx: commands.Context) -> None: + raise NotImplementedError() + @abstractmethod async def aurora_settings_addrole(self, ctx: commands.Context) -> None: raise NotImplementedError() diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index cf68dd1..cbef06f 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -2,7 +2,7 @@ from redbot.core import commands from redbot.core.utils.chat_formatting import error, warning from aurora.configuration.menus.overrides import Overrides -from aurora.configuration.embed import addrole_embed, overrides, immune_embed +from aurora.configuration.embed import addrole, overrides, immune, guild from aurora.abc import Mixin from aurora.importers.aurora import ImportAuroraView from aurora.importers.galacticbot import ImportGalacticBotView @@ -22,8 +22,12 @@ class Configuration(Mixin): @aurora_settings.command(name="overrides", aliases=["override", "user"]) async def aurora_settings_overrides(self, ctx: commands.Context): """Manage Aurora's user overriddable settings.""" - view = Overrides(ctx) - await ctx.send(embed=await overrides(ctx), view=view) + await ctx.send(embed=await overrides(ctx), view=Overrides(ctx)) + + @aurora_settings.command(name="guild", aliases=["server"]) + async def aurora_settings_guild(self, ctx: commands.Context): + """Manage Aurora's guild settings.""" + await ctx.send(embed=await guild(ctx)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) @@ -31,13 +35,13 @@ class Configuration(Mixin): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole_embed(ctx)) + await ctx.send(embed=await addrole(ctx)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" - await ctx.send(embed=await immune_embed(ctx)) + await ctx.send(embed=await immune(ctx)) @aurora.group(autohelp=True, name="import") @commands.admin() diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 2d25ad8..b733aa1 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -1,6 +1,4 @@ -from typing import Union - -from discord import Embed, Guild, Member, User +from discord import Embed, Guild from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning @@ -44,85 +42,107 @@ async def overrides(ctx: commands.Context) -> Embed: """ + override_str return e -async def _guild(guild: Guild) -> str: +async def guild(ctx: commands.Context) -> str: """Generates a configuration menu field value for a guild's settings.""" guild_settings = { - "show_moderator": await config.guild(guild).show_moderator(), - "use_discord_permissions": await config.guild(guild).use_discord_permissions(), - "ignore_modlog": await config.guild(guild).ignore_modlog(), - "ignore_other_bots": await config.guild(guild).ignore_other_bots(), - "dm_users": await config.guild(guild).dm_users(), - "log_channel": await config.guild(guild).log_channel(), - "history_ephemeral": await config.guild(guild).history_ephemeral(), - "history_inline": await config.guild(guild).history_inline(), - "history_pagesize": await config.guild(guild).history_pagesize(), - "history_inline_pagesize": await config.guild(guild).history_inline_pagesize(), - "auto_evidenceformat": await config.guild(guild).auto_evidenceformat(), + "show_moderator": await config.guild(ctx.guild).show_moderator(), + "use_discord_permissions": await config.guild(ctx.guild).use_discord_permissions(), + "ignore_modlog": await config.guild(ctx.guild).ignore_modlog(), + "ignore_other_bots": await config.guild(ctx.guild).ignore_other_bots(), + "dm_users": await config.guild(ctx.guild).dm_users(), + "log_channel": await config.guild(ctx.guild).log_channel(), + "history_ephemeral": await config.guild(ctx.guild).history_ephemeral(), + "history_inline": await config.guild(ctx.guild).history_inline(), + "history_pagesize": await config.guild(ctx.guild).history_pagesize(), + "history_inline_pagesize": await config.guild(ctx.guild).history_inline_pagesize(), + "auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(), } - channel = guild.get_channel(guild_settings['log_channel']) + channel = ctx.guild.get_channel(guild_settings['log_channel']) if channel is None: channel = warning("Not Set") else: channel = channel.mention guild_str = [ - bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']), - bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']), - bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), - bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), - bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), - bold("Log Channel: ") + channel, - bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), - bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), - bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), - bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), - bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) + '- '+ bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']), + '- '+ bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']), + '- '+ bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), + '- '+ bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), + '- '+ bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), + '- '+ bold("Log Channel: ") + channel, + '- '+ bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), + '- '+ bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), + '- '+ bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), + '- '+ bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), + '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) ] guild_str = '\n'.join(guild_str) return guild_str -async def _addrole(guild: Guild) -> str: +async def addrole(ctx: commands.Context) -> str: """Generates a configuration menu field value for a guild's addrole whitelist.""" - whitelist = await config.guild(guild).addrole_roles() + whitelist = await config.guild(ctx.guild).addrole_roles() if whitelist: - whitelist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] + whitelist = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] whitelist = '\n'.join(whitelist) else: whitelist = warning("No roles are on the addrole whitelist!") - return whitelist -async def _immune(guild: Guild) -> str: - """Generates a configuration menu field value for a guild's immune roles.""" - - immune = await config.guild(guild).immune_roles() - if immune: - immune = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune] - immune = '\n'.join(immune) - else: - immune = warning("No roles are set as immune roles!") - return immune - -async def embed(ctx: commands.Context) -> Embed: - """Generates the configuration embed for a guild.""" - e = await _core(ctx) - e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) - 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 - -async def addrole_embed(ctx: commands.Context) -> Embed: - """Generates the addrole embed for a guild.""" e = await _core(ctx) e.title += ": Addrole Whitelist" - e.description = "Use the buttons below to manage the addrole whitelist.\n\n" + await _addrole(ctx.guild) + e.description = "Use the buttons below to manage this guild's addrole whitelist." + + if len(whitelist) > 4000 and len(whitelist) < 5000: + lines = whitelist.split('\n') + chunks = [] + chunk = "" + for line in lines: + if len(chunk) + len(line) > 1024: + chunks.append(chunk) + chunk = line + else: + chunk += '\n' + line if chunk else line + chunks.append(chunk) + + for chunk in chunks: + e.add_field(name="", value=chunk) + else: + e.description += '\n' + whitelist + return e -async def immune_embed(ctx: commands.Context) -> Embed: - """Generates the immune roles embed for a guild.""" +async def immune(ctx: commands.Context) -> str: + """Generates a configuration menu field value for a guild's immune roles.""" + + immune_roles = await config.guild(ctx.guild).immune_roles() + if immune_roles: + immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune] + immune_str = '\n'.join(immune) + else: + immune_str = warning("No roles are set as immune roles!") + e = await _core(ctx) e.title += ": Immune Roles" - e.description = "Use the buttons below to manage the immune roles.\n\n" + await _immune(ctx.guild) + e.description = "Use the buttons below to manage this guild's immune roles." + + if len(immune_str) > 4000 and len(immune_str) < 5000: + lines = immune_str.split('\n') + chunks = [] + chunk = "" + for line in lines: + if len(chunk) + len(line) > 1024: + chunks.append(chunk) + chunk = line + else: + chunk += '\n' + line if chunk else line + chunks.append(chunk) + + for chunk in chunks: + e.add_field(name="", value=chunk) + else: + e.description += '\n' + immune_str + return e From 3cbc8a744cf4cd93b0be644ab730da42169a4243 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:53:22 +0000 Subject: [PATCH 48/72] fix(aurora): fixed guild command --- aurora/configuration/commands.py | 4 ++++ aurora/configuration/embed.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index cbef06f..1071f41 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -25,12 +25,15 @@ class Configuration(Mixin): await ctx.send(embed=await overrides(ctx), view=Overrides(ctx)) @aurora_settings.command(name="guild", aliases=["server"]) + @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() async def aurora_settings_guild(self, ctx: commands.Context): """Manage Aurora's guild settings.""" await ctx.send(embed=await guild(ctx)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() async def aurora_settings_addrole(self, ctx: commands.Context): """Manage the addrole whitelist. @@ -39,6 +42,7 @@ class Configuration(Mixin): @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" await ctx.send(embed=await immune(ctx)) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index b733aa1..93fd9d0 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -42,7 +42,7 @@ async def overrides(ctx: commands.Context) -> Embed: """ + override_str return e -async def guild(ctx: commands.Context) -> str: +async def guild(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's settings.""" guild_settings = { @@ -79,9 +79,15 @@ async def guild(ctx: commands.Context) -> str: '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) ] guild_str = '\n'.join(guild_str) - return guild_str -async def addrole(ctx: commands.Context) -> str: + e = await _core(ctx) + e.title += ": Server Configuration" + e.description = """ + Use the buttons below to manage Aurora's server configuration.\n + """ + guild_str + return e + +async def addrole(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's addrole whitelist.""" whitelist = await config.guild(ctx.guild).addrole_roles() @@ -114,7 +120,7 @@ async def addrole(ctx: commands.Context) -> str: return e -async def immune(ctx: commands.Context) -> str: +async def immune(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's immune roles.""" immune_roles = await config.guild(ctx.guild).immune_roles() From a88a3dbf65fbec0de1e916fb2f4d14a6cf29018b Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 11:56:04 +0000 Subject: [PATCH 49/72] fix(aurora): fix embed formatting for addrole/immunity --- aurora/configuration/embed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 93fd9d0..4a88d1f 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -116,7 +116,7 @@ async def addrole(ctx: commands.Context) -> Embed: for chunk in chunks: e.add_field(name="", value=chunk) else: - e.description += '\n' + whitelist + e.description += '\n\n' + whitelist return e @@ -149,6 +149,6 @@ async def immune(ctx: commands.Context) -> Embed: for chunk in chunks: e.add_field(name="", value=chunk) else: - e.description += '\n' + immune_str + e.description += '\n\n' + immune_str return e From 13e82f8768a1628df01e9f4b127118e92a040533 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 12:57:42 +0000 Subject: [PATCH 50/72] feat(aurora): added views for addrole and immunity --- aurora/configuration/commands.py | 4 ++-- aurora/configuration/menus/addrole.py | 24 ++++++++++++++++++++++++ aurora/configuration/menus/immune.py | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 1071f41..f5a677b 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -38,14 +38,14 @@ class Configuration(Mixin): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole(ctx)) + await ctx.send(embed=await addrole(ctx), view=addrole(ctx)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" - await ctx.send(embed=await immune(ctx)) + await ctx.send(embed=await immune(ctx), view=immune(ctx)) @aurora.group(autohelp=True, name="import") @commands.admin() diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index e69de29..1d92e57 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -0,0 +1,24 @@ +from discord import ui, Interaction +from redbot.core import commands + +from aurora.configuration.embed import addrole +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") + async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument + if not interaction.user.guild_permissions.manage_guild: + await interaction.response.send_message("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() + if select.values[0] in addrole_whitelist: + addrole_whitelist.remove(select.values[0]) + else: + addrole_whitelist.append(select.values[0]) + await config.guild(self.ctx.guild).addrole_whitelist.set(int(select.values[0])) + await interaction.message.edit(embed=await addrole(self.ctx)) diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index e69de29..a04c741 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -0,0 +1,24 @@ +from discord import 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") + async def immune_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument + if not interaction.user.guild_permissions.manage_guild: + 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() + if select.values[0] in immune_roles: + immune_roles.remove(select.values[0]) + else: + immune_roles.append(select.values[0]) + await config.guild(self.ctx.guild).immune_roles.set(int(select.values[0])) + await interaction.message.edit(embed=await immune(self.ctx)) From 4a262dc6a1c39a24d5ec5c713782b5c9a2fc97df Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 12:58:18 +0000 Subject: [PATCH 51/72] fix(aurora): awaited two coroutines --- aurora/configuration/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index f5a677b..0d1e5ef 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -38,14 +38,14 @@ class Configuration(Mixin): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole(ctx), view=addrole(ctx)) + await ctx.send(embed=await addrole(ctx), view=await addrole(ctx)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" - await ctx.send(embed=await immune(ctx), view=immune(ctx)) + await ctx.send(embed=await immune(ctx), view=await immune(ctx)) @aurora.group(autohelp=True, name="import") @commands.admin() From 4226f1a14c39398c73e877011227ef2bf88f8dc9 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 12:59:15 +0000 Subject: [PATCH 52/72] fix(aurora): use views for views instead of embeds --- aurora/configuration/commands.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py index 0d1e5ef..a563b6c 100644 --- a/aurora/configuration/commands.py +++ b/aurora/configuration/commands.py @@ -1,6 +1,8 @@ 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.immune import Immune from aurora.configuration.menus.overrides import Overrides from aurora.configuration.embed import addrole, overrides, immune, guild from aurora.abc import Mixin @@ -38,14 +40,14 @@ class Configuration(Mixin): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole(ctx), view=await addrole(ctx)) + await ctx.send(embed=await addrole(ctx), view=Addrole(ctx)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" - await ctx.send(embed=await immune(ctx), view=await immune(ctx)) + await ctx.send(embed=await immune(ctx), view=Immune(ctx)) @aurora.group(autohelp=True, name="import") @commands.admin() From 89a3e958b2d4c05228fcbe4d12818c805d45af22 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:00:00 +0000 Subject: [PATCH 53/72] fix(aurora): rename configuration value --- aurora/utilities/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/utilities/config.py b/aurora/utilities/config.py index 88090b7..944efae 100644 --- a/aurora/utilities/config.py +++ b/aurora/utilities/config.py @@ -16,7 +16,7 @@ def register_config(config_obj: Config): history_pagesize = 5, history_inline_pagesize = 6, auto_evidenceformat = False, - addrole_roles = [] + addrole_whitelist = [] ) config_obj.register_user( history_ephemeral = None, From d8def3cfc8c48a9eeb0a58db8beea74757a24be9 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:03:51 +0000 Subject: [PATCH 54/72] fix(aurora): fixed a few errors in addrole/immune --- aurora/configuration/menus/addrole.py | 8 ++++---- aurora/configuration/menus/immune.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index 1d92e57..87cc811 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -11,14 +11,14 @@ class Addrole(ui.View): @ui.select(cls=ui.RoleSelect, placeholder="Select a role") async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument - if not interaction.user.guild_permissions.manage_guild: + 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) return await interaction.response.defer() addrole_whitelist: list = await config.guild(self.ctx.guild).addrole_whitelist() if select.values[0] in addrole_whitelist: - addrole_whitelist.remove(select.values[0]) + addrole_whitelist.remove(select.values[0].id) else: - addrole_whitelist.append(select.values[0]) - await config.guild(self.ctx.guild).addrole_whitelist.set(int(select.values[0])) + addrole_whitelist.append(select.values[0].id) + await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist) await interaction.message.edit(embed=await addrole(self.ctx)) diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index a04c741..680e53d 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -11,14 +11,14 @@ class Immune(ui.View): @ui.select(cls=ui.RoleSelect, placeholder="Select a role") async def immune_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument - if not interaction.user.guild_permissions.manage_guild: + 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() if select.values[0] in immune_roles: - immune_roles.remove(select.values[0]) + immune_roles.remove(select.values[0].id) else: - immune_roles.append(select.values[0]) - await config.guild(self.ctx.guild).immune_roles.set(int(select.values[0])) + immune_roles.append(select.values[0].id) + await config.guild(self.ctx.guild).immune_roles.set(immune_roles) await interaction.message.edit(embed=await immune(self.ctx)) From 4788f3189cbb7fe20a6a786a158605329fd1195a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:04:44 +0000 Subject: [PATCH 55/72] fix(aurora): fixed the addrole embed generator having an outdated config variable name --- aurora/configuration/embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 4a88d1f..6a820af 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -90,7 +90,7 @@ async def guild(ctx: commands.Context) -> Embed: async def addrole(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's addrole whitelist.""" - whitelist = await config.guild(ctx.guild).addrole_roles() + whitelist = await config.guild(ctx.guild).addrole_whitelist() if whitelist: whitelist = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] whitelist = '\n'.join(whitelist) From 464fa9f97aca755f8f525a2aa88c32c5923142c5 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:06:50 +0000 Subject: [PATCH 56/72] fix(aurora): fixed some errors --- aurora/configuration/menus/addrole.py | 6 +++--- aurora/configuration/menus/immune.py | 6 +++--- aurora/configuration/menus/overrides.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index 87cc811..b1abaa5 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -10,15 +10,15 @@ class Addrole(ui.View): self.ctx = ctx @ui.select(cls=ui.RoleSelect, placeholder="Select a role") - async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument + 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("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() - if select.values[0] in addrole_whitelist: + 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) - await interaction.message.edit(embed=await addrole(self.ctx)) + await interaction.message.edit(embed=await addrole(self.ctx), view=Addrole(self.ctx)) diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index 680e53d..496b04e 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -10,15 +10,15 @@ class Immune(ui.View): self.ctx = ctx @ui.select(cls=ui.RoleSelect, placeholder="Select a role") - async def immune_select(self, interaction: Interaction, select: ui.RoleSelect,): # pylint: disable=unused-argument + 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() - if select.values[0] in immune_roles: + if select.values[0].id in immune_roles: immune_roles.remove(select.values[0].id) else: immune_roles.append(select.values[0].id) await config.guild(self.ctx.guild).immune_roles.set(immune_roles) - await interaction.message.edit(embed=await immune(self.ctx)) + await interaction.message.edit(embed=await immune(self.ctx), view=Immune(self.ctx)) diff --git a/aurora/configuration/menus/overrides.py b/aurora/configuration/menus/overrides.py index 7ce1b31..f7abd97 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/configuration/menus/overrides.py @@ -56,7 +56,7 @@ class Overrides(ui.View): await interaction.message.edit(embed=await overrides(self.ctx)) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) - async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument + async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return @@ -68,7 +68,7 @@ class Overrides(ui.View): await interaction.message.edit(embed=await overrides(self.ctx)) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) - async def pagesize(self, interaction: Interaction, select: ui.Select,): # pylint: disable=unused-argument + async def pagesize(self, interaction: Interaction, select: ui.Select,): if self.ctx.author != interaction.user: await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) return From 7476fcaa8ded7e9248c882c390bb2162467e9542 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:10:16 +0000 Subject: [PATCH 57/72] misc(aurora): changed some strings in the addrole and immunity embeds --- aurora/configuration/embed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 6a820af..ecf6f68 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -99,7 +99,7 @@ async def addrole(ctx: commands.Context) -> Embed: e = await _core(ctx) e.title += ": Addrole Whitelist" - e.description = "Use the buttons below to manage this guild's addrole whitelist." + e.description = "Use the select menu below to manage this guild's addrole whitelist." if len(whitelist) > 4000 and len(whitelist) < 5000: lines = whitelist.split('\n') @@ -132,7 +132,7 @@ async def immune(ctx: commands.Context) -> Embed: e = await _core(ctx) e.title += ": Immune Roles" - e.description = "Use the buttons below to manage this guild's immune roles." + e.description = "Use the select menu below to manage this guild's immune roles." if len(immune_str) > 4000 and len(immune_str) < 5000: lines = immune_str.split('\n') From 630381328b3bf1624c079c9ee42328e5c7e2d3d3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:11:25 +0000 Subject: [PATCH 58/72] fix(aurora): fixed an error in the immune embed generator --- aurora/configuration/embed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index ecf6f68..73bd7f9 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -125,8 +125,8 @@ async def immune(ctx: commands.Context) -> Embed: immune_roles = await config.guild(ctx.guild).immune_roles() if immune_roles: - immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune] - immune_str = '\n'.join(immune) + immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune_roles] + immune_str = '\n'.join(immune_roles) else: immune_str = warning("No roles are set as immune roles!") From a4a0ec924a2a0482b7680ca66dd0501ba481f9a0 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:13:48 +0000 Subject: [PATCH 59/72] fix(aurora): fixed another error in the immune embed generator --- aurora/configuration/embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 73bd7f9..7eb33b1 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -126,7 +126,7 @@ async def immune(ctx: commands.Context) -> Embed: immune_roles = await config.guild(ctx.guild).immune_roles() if immune_roles: immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune_roles] - immune_str = '\n'.join(immune_roles) + immune_str = '\n'.join(immune_str) else: immune_str = warning("No roles are set as immune roles!") From 2037f385d18d2e24a0622417542434874a37af2a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:39:12 +0000 Subject: [PATCH 60/72] feat(aurora): allow setting multiple immune roles at once --- aurora/configuration/menus/addrole.py | 8 ++++++-- aurora/configuration/menus/immune.py | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index b1abaa5..974e978 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -1,4 +1,4 @@ -from discord import ui, Interaction +from discord import ButtonStyle, ui, Interaction from redbot.core import commands from aurora.configuration.embed import addrole @@ -10,7 +10,7 @@ class Addrole(ui.View): self.ctx = ctx @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: await interaction.response.send_message("You must have the manage guild permission to add roles to the addrole whitelist.", ephemeral=True) return @@ -22,3 +22,7 @@ class Addrole(ui.View): addrole_whitelist.append(select.values[0].id) await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist) 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() diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index 496b04e..f11a005 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -1,4 +1,4 @@ -from discord import ui, Interaction +from discord import ButtonStyle, ui, Interaction from redbot.core import commands from aurora.configuration.embed import immune @@ -9,16 +9,21 @@ class Immune(ui.View): super().__init__() self.ctx = ctx - @ui.select(cls=ui.RoleSelect, placeholder="Select a role") - async def immune_select(self, interaction: Interaction, select: ui.RoleSelect,): + @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() - if select.values[0].id in immune_roles: - immune_roles.remove(select.values[0].id) - else: - immune_roles.append(select.values[0].id) + 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), 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() From fecde10b1ca4413e0c7cad91f6fc634e91c24a6b Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:43:22 +0000 Subject: [PATCH 61/72] feat(aurora): added previous commit's functionality to addrole and fixed some bugs --- aurora/configuration/menus/addrole.py | 19 ++++++++++++++++--- aurora/configuration/menus/immune.py | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index 974e978..1ca91a1 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -1,5 +1,6 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands +from redbot.core.utils.chat_formatting import error from aurora.configuration.embed import addrole from aurora.utilities.config import config @@ -9,10 +10,10 @@ class Addrole(ui.View): super().__init__() 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 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("You must have the manage guild permission to add roles to the addrole whitelist.", ephemeral=True) + 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() @@ -21,8 +22,20 @@ class Addrole(ui.View): else: addrole_whitelist.append(select.values[0].id) 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)) + + @ui.button(label="Clear", style=ButtonStyle.red, row=1) + async def clear(self, interaction: Interaction, button: ui.Button): + 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() + await interaction.message.edit(embed=await addrole(self.ctx)) @ui.button(label="Close", style=ButtonStyle.red) 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() diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index f11a005..933b5bd 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -1,5 +1,6 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands +from redbot.core.utils.chat_formatting import error from aurora.configuration.embed import immune from aurora.utilities.config import config @@ -12,7 +13,7 @@ class Immune(ui.View): @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) + await interaction.response.send_message(error("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() @@ -24,6 +25,18 @@ class Immune(ui.View): await config.guild(self.ctx.guild).immune_roles.set(immune_roles) await interaction.message.edit(embed=await immune(self.ctx)) + @ui.button(label="Clear", style=ButtonStyle.red, row=1) + async def clear(self, interaction: Interaction, button: ui.Button): + 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 immune roles."), ephemeral=True) + return + await interaction.response.defer() + await config.guild(self.ctx.guild).immune_roles.clear() + 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 + 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() From 4d8aa465b11e1a425e30252e20e2321b2bb8e9a6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:44:19 +0000 Subject: [PATCH 62/72] fix(aurora): changed color of close buttons to gray instead of red --- aurora/configuration/menus/addrole.py | 2 +- aurora/configuration/menus/immune.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index 1ca91a1..d5a61bb 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -33,7 +33,7 @@ class Addrole(ui.View): await config.guild(self.ctx.guild).addrole_whitelist.clear() await interaction.message.edit(embed=await addrole(self.ctx)) - @ui.button(label="Close", style=ButtonStyle.red) + @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) diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index 933b5bd..34f096b 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -34,7 +34,7 @@ class Immune(ui.View): await config.guild(self.ctx.guild).immune_roles.clear() await interaction.message.edit(embed=await immune(self.ctx)) - @ui.button(label="Close", style=ButtonStyle.red) + @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) From 4db7c912cb8919797c36873214c34e28a72bc586 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 13:54:48 +0000 Subject: [PATCH 63/72] misc(aurora): changed some strings in the overrides embed --- aurora/configuration/embed.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 7eb33b1..e5b3fc2 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -28,9 +28,9 @@ async def overrides(ctx: commands.Context) -> Embed: override_str = [ '- ' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), '- ' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), - '- ' + bold("Inline: ") + get_bool_emoji(override_settings['inline']), - '- ' + bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), - '- ' + bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), + '- ' + bold("History Inline: ") + get_bool_emoji(override_settings['inline']), + '- ' + bold("History Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + '- ' + bold("History Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] override_str = '\n'.join(override_str) From 3d4b6800a5aec25a0f3d060ca58ebdcef95a42d6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:02:10 +0000 Subject: [PATCH 64/72] 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)) From 78a5103b1fc379f918cae0e9330c1035bac10cfc Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:03:58 +0000 Subject: [PATCH 65/72] fix(aurora): changed up the guild embed a bit --- aurora/configuration/embed.py | 4 ++-- aurora/configuration/menus/guild.py | 32 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index e5b3fc2..179b7f5 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -71,12 +71,12 @@ async def guild(ctx: commands.Context) -> Embed: '- '+ bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), '- '+ bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), '- '+ bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), - '- '+ bold("Log Channel: ") + channel, '- '+ bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), '- '+ bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), '- '+ bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), '- '+ bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), - '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) + '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']), + '- '+ bold("Log Channel: ") + channel ] guild_str = '\n'.join(guild_str) diff --git a/aurora/configuration/menus/guild.py b/aurora/configuration/menus/guild.py index 8a489cf..afaaf0e 100644 --- a/aurora/configuration/menus/guild.py +++ b/aurora/configuration/menus/guild.py @@ -11,13 +11,13 @@ class Guild(ui.View): 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 + async def show_moderator(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) + current_setting = await config.guild(interaction.guild).show_moderator + await config.guild(interaction.guild).show_moderator.set(not current_setting) await interaction.message.edit(embed=await guild(self.ctx)) @ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0) @@ -50,7 +50,7 @@ class Guild(ui.View): 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) + @ui.button(label="DM Users", style=ButtonStyle.green, row=1) 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) @@ -60,16 +60,7 @@ class Guild(ui.View): 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) + @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1) 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) @@ -79,7 +70,7 @@ class Guild(ui.View): 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) + @ui.button(label="Ephemeral", style=ButtonStyle.green, row=1) 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) @@ -89,7 +80,7 @@ class Guild(ui.View): 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) + @ui.button(label="History Inline", style=ButtonStyle.green, row=1) 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) @@ -99,6 +90,15 @@ class Guild(ui.View): await config.guild(interaction.guild).history_inline.set(not current_setting) await interaction.message.edit(embed=await guild(self.ctx)) + @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=2) + 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.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: From fc86db94dae510f2c17d545aac3054835967bb42 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:06:50 +0000 Subject: [PATCH 66/72] misc(aurora): moved log_channel to the bottom of the guild view --- aurora/configuration/menus/guild.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/aurora/configuration/menus/guild.py b/aurora/configuration/menus/guild.py index afaaf0e..fd1dfa0 100644 --- a/aurora/configuration/menus/guild.py +++ b/aurora/configuration/menus/guild.py @@ -90,16 +90,7 @@ class Guild(ui.View): await config.guild(interaction.guild).history_inline.set(not current_setting) await interaction.message.edit(embed=await guild(self.ctx)) - @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=2) - 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.select(placeholder="History Pagesize", options=create_pagesize_options(), row=3) + @ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2) 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) @@ -111,7 +102,7 @@ class Guild(ui.View): 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) + @ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3) 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) @@ -122,3 +113,12 @@ class Guild(ui.View): 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)) + + @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=4) + 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)) From 3b8506cba83b798dc937b60680c548cf218a645d Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:08:57 +0000 Subject: [PATCH 67/72] fix(aurora): pylint fixes --- aurora/configuration/embed.py | 2 +- aurora/configuration/menus/addrole.py | 2 +- aurora/configuration/menus/immune.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py index 179b7f5..1fd78aa 100644 --- a/aurora/configuration/embed.py +++ b/aurora/configuration/embed.py @@ -1,4 +1,4 @@ -from discord import Embed, Guild +from discord import Embed from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning diff --git a/aurora/configuration/menus/addrole.py b/aurora/configuration/menus/addrole.py index d5a61bb..a28ba9c 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/configuration/menus/addrole.py @@ -25,7 +25,7 @@ class Addrole(ui.View): await interaction.message.edit(embed=await addrole(self.ctx)) @ui.button(label="Clear", style=ButtonStyle.red, row=1) - async def clear(self, interaction: Interaction, button: ui.Button): + 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 diff --git a/aurora/configuration/menus/immune.py b/aurora/configuration/menus/immune.py index 34f096b..49df36a 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/configuration/menus/immune.py @@ -26,7 +26,7 @@ class Immune(ui.View): await interaction.message.edit(embed=await immune(self.ctx)) @ui.button(label="Clear", style=ButtonStyle.red, row=1) - async def clear(self, interaction: Interaction, button: ui.Button): + 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 immune roles."), ephemeral=True) return From 46a290aad3ebfae58e618945dc546b937649be17 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:23:45 +0000 Subject: [PATCH 68/72] feat(aurora): merged all of the changes made in the configuration rewrite into the codebase of the cog itself --- aurora/abc.py | 65 ------- aurora/aurora.py | 110 ++++++++++-- aurora/configuration/commands.py | 95 ----------- aurora/configuration/embed.py | 154 ----------------- aurora/configuration/menus/__init__.py | 0 aurora/configuration/utils.py | 37 ---- aurora/{configuration => menus}/__init__.py | 0 aurora/{configuration => }/menus/addrole.py | 2 +- aurora/{configuration => }/menus/guild.py | 4 +- aurora/{configuration => }/menus/immune.py | 2 +- aurora/{configuration => }/menus/overrides.py | 4 +- aurora/utilities/factory.py | 160 +++++++++++++++++- aurora/utilities/utils.py | 36 +++- 13 files changed, 297 insertions(+), 372 deletions(-) delete mode 100644 aurora/abc.py delete mode 100644 aurora/configuration/commands.py delete mode 100644 aurora/configuration/embed.py delete mode 100644 aurora/configuration/menus/__init__.py delete mode 100644 aurora/configuration/utils.py rename aurora/{configuration => menus}/__init__.py (100%) rename aurora/{configuration => }/menus/addrole.py (98%) rename aurora/{configuration => }/menus/guild.py (98%) rename aurora/{configuration => }/menus/immune.py (98%) rename aurora/{configuration => }/menus/overrides.py (97%) diff --git a/aurora/abc.py b/aurora/abc.py deleted file mode 100644 index a228aaa..0000000 --- a/aurora/abc.py +++ /dev/null @@ -1,65 +0,0 @@ -from abc import ABC, abstractmethod - -from redbot.core import commands -from redbot.core.bot import Red - -from .utilities.config import config - - -class CompositeMetaClass(type(commands.Cog), type(ABC)): - """ - This allows the metaclass used for proper type detection to - coexist with discord.py's metaclass - """ - -class Mixin(ABC): - """ - Base class for well behaved type hint detection with composite class. - - Basically, to keep developers sane when not all attributes are defined in each mixin. - """ - - def __init__(self, *_args): - super().__init__() - self.config: config - self.bot: Red - - ####################################################################### - # configuration/commands.py # - ####################################################################### - - @abstractmethod - async def aurora(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_settings(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_settings_overrides(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_settings_guild(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_settings_addrole(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_settings_immunity(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_import(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_import_aurora(self, ctx: commands.Context) -> None: - raise NotImplementedError() - - @abstractmethod - async def aurora_import_galacticbot(self, ctx: commands.Context) -> None: - raise NotImplementedError() diff --git a/aurora/aurora.py b/aurora/aurora.py index d41662f..783f0a2 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -21,16 +21,20 @@ from redbot.core.app_commands import Choice from redbot.core.bot import Red from redbot.core.utils.chat_formatting import box, error, warning -from .abc import CompositeMetaClass -from .configuration.commands import Configuration -from .utilities.config import config, register_config -from .utilities.database import connect, create_guild_table, fetch_case, mysql_log -from .utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory -from .utilities.logger import logger -from .utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat +from aurora.importers.aurora import ImportAuroraView +from aurora.importers.galacticbot import ImportGalacticBotView +from aurora.menus.addrole import Addrole +from aurora.menus.guild import Guild +from aurora.menus.immune import Immune +from aurora.menus.overrides import Overrides +from aurora.utilities.config import config, register_config +from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log +from aurora.utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory, overrides, immune, guild, addrole +from aurora.utilities.logger import logger +from aurora.utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat -class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylint: disable=too-many-ancestors +class Aurora(commands.Cog): """Aurora is a fully-featured moderation system. It is heavily inspired by GalacticBot, and is designed to be a more user-friendly alternative to Red's core Mod cogs. This cog stores all of its data in an SQLite database.""" @@ -1019,12 +1023,96 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylin completion_time = (time.time() - current_time) * 1000 logger.debug("Completed expiry loop in %sms with %s users unbanned", f"{completion_time:.6f}", global_num) - @commands.command(aliases=["tdc"]) - async def timedeltaconvert(self, ctx: commands.Context, *, duration: str): +######################################################################################################################## +### Configuration Commands # +######################################################################################################################## + + @commands.group(autohelp=True, aliases=["moderation", "mod"]) + async def aurora(self, ctx: commands.Context): + """Settings and miscellaneous commands for Aurora.""" + + @aurora.group(autohelp=True, name="settings", aliases=["config", "options", "set"]) + async def aurora_settings(self, ctx: commands.Context): + """Configure Aurora's settings.""" + + @aurora_settings.command(name="overrides", aliases=["override", "user"]) + async def aurora_settings_overrides(self, ctx: commands.Context): + """Manage Aurora's user overriddable settings.""" + await ctx.send(embed=await overrides(ctx), view=Overrides(ctx)) + + @aurora_settings.command(name="guild", aliases=["server"]) + @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() + async def aurora_settings_guild(self, ctx: commands.Context): + """Manage Aurora's guild settings.""" + await ctx.send(embed=await guild(ctx), view=Guild(ctx)) + + @aurora_settings.command(name="addrole", aliases=["removerole"]) + @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() + async def aurora_settings_addrole(self, ctx: commands.Context): + """Manage the addrole whitelist. + + Roles added to this list are also applied to `/removerole`.""" + await ctx.send(embed=await addrole(ctx), view=Addrole(ctx)) + + @aurora_settings.command(name="immunity") + @commands.admin_or_permissions(manage_guild=True) + @commands.guild_only() + async def aurora_settings_immunity(self, ctx: commands.Context): + """Manage the immunity whitelist.""" + await ctx.send(embed=await immune(ctx), view=Immune(ctx)) + + @aurora.group(autohelp=True, name="import") + @commands.admin() + @commands.guild_only() + async def aurora_import(self, ctx: commands.Context): + """Import moderation history from other bots.""" + + @aurora_import.command(name="aurora") + @commands.admin() + async def aurora_import_aurora(self, ctx: commands.Context): + """Import moderation history from another bot using Aurora.""" + if ( + ctx.message.attachments + and ctx.message.attachments[0].content_type + == "application/json; charset=utf-8" + ): + message = await ctx.send( + warning( + "Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" + ) + ) + await message.edit(view=ImportAuroraView(60, ctx, message)) + else: + await ctx.send(error("Please provide a valid Aurora export file.")) + + @aurora_import.command(name="galacticbot") + @commands.admin() + async def aurora_import_galacticbot(self, ctx: commands.Context): + """Import moderation history from GalacticBot.""" + if ( + ctx.message.attachments + and ctx.message.attachments[0].content_type + == "application/json; charset=utf-8" + ): + message = await ctx.send( + warning( + "Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" + ) + ) + await message.edit(view=ImportGalacticBotView(60, ctx, message)) + else: + await ctx.send( + error("Please provide a valid GalacticBot moderation export file.") + ) + + @aurora.command(aliases=["tdc", 'td', 'timedeltaconvert']) + async def timedelta(self, ctx: commands.Context, *, duration: str): """This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object. **Example usage** - `[p]timedeltaconvert 1 day 15hr 82 minutes 52s` + `[p]timedelta 1 day 15hr 82 minutes 52s` **Output** `1 day, 16:22:52`""" try: diff --git a/aurora/configuration/commands.py b/aurora/configuration/commands.py deleted file mode 100644 index 08ea6d3..0000000 --- a/aurora/configuration/commands.py +++ /dev/null @@ -1,95 +0,0 @@ -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 -from aurora.abc import Mixin -from aurora.importers.aurora import ImportAuroraView -from aurora.importers.galacticbot import ImportGalacticBotView - - -class Configuration(Mixin): - """Configuration commands for Aurora.""" - - @commands.group(autohelp=True, aliases=["moderation", "mod"]) - async def aurora(self, ctx: commands.Context): - """Settings and miscellaneous commands for Aurora.""" - - @aurora.group(autohelp=True, name="settings", aliases=["config", "options", "set"]) - async def aurora_settings(self, ctx: commands.Context): - """Configure Aurora's settings.""" - - @aurora_settings.command(name="overrides", aliases=["override", "user"]) - async def aurora_settings_overrides(self, ctx: commands.Context): - """Manage Aurora's user overriddable settings.""" - await ctx.send(embed=await overrides(ctx), view=Overrides(ctx)) - - @aurora_settings.command(name="guild", aliases=["server"]) - @commands.admin_or_permissions(manage_guild=True) - @commands.guild_only() - async def aurora_settings_guild(self, ctx: commands.Context): - """Manage Aurora's guild settings.""" - await ctx.send(embed=await guild(ctx), view=Guild(ctx)) - - @aurora_settings.command(name="addrole", aliases=["removerole"]) - @commands.admin_or_permissions(manage_guild=True) - @commands.guild_only() - async def aurora_settings_addrole(self, ctx: commands.Context): - """Manage the addrole whitelist. - - Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole(ctx), view=Addrole(ctx)) - - @aurora_settings.command(name="immunity") - @commands.admin_or_permissions(manage_guild=True) - @commands.guild_only() - async def aurora_settings_immunity(self, ctx: commands.Context): - """Manage the immunity whitelist.""" - await ctx.send(embed=await immune(ctx), view=Immune(ctx)) - - @aurora.group(autohelp=True, name="import") - @commands.admin() - @commands.guild_only() - async def aurora_import(self, ctx: commands.Context): - """Import moderation history from other bots.""" - - @aurora_import.command(name="aurora") - @commands.admin() - async def aurora_import_aurora(self, ctx: commands.Context): - """Import moderation history from another bot using Aurora.""" - if ( - ctx.message.attachments - and ctx.message.attachments[0].content_type - == "application/json; charset=utf-8" - ): - message = await ctx.send( - warning( - "Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" - ) - ) - await message.edit(view=ImportAuroraView(60, ctx, message)) - else: - await ctx.send(error("Please provide a valid Aurora export file.")) - - @aurora_import.command(name="galacticbot") - @commands.admin() - async def aurora_import_galacticbot(self, ctx: commands.Context): - """Import moderation history from GalacticBot.""" - if ( - ctx.message.attachments - and ctx.message.attachments[0].content_type - == "application/json; charset=utf-8" - ): - message = await ctx.send( - warning( - "Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" - ) - ) - await message.edit(view=ImportGalacticBotView(60, ctx, message)) - else: - await ctx.send( - error("Please provide a valid GalacticBot moderation export file.") - ) diff --git a/aurora/configuration/embed.py b/aurora/configuration/embed.py deleted file mode 100644 index 1fd78aa..0000000 --- a/aurora/configuration/embed.py +++ /dev/null @@ -1,154 +0,0 @@ -from discord import Embed -from redbot.core import commands -from redbot.core.utils.chat_formatting import bold, error, warning - -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.""" - e = Embed( - title="Aurora Configuration Menu", - color=await ctx.embed_color() - ) - e.set_thumbnail(url=ctx.bot.user.display_avatar.url) - return e - -async def overrides(ctx: commands.Context) -> Embed: - """Generates a configuration menu embed for a user's overrides.""" - - override_settings = { - "ephemeral": await config.user(ctx.author).history_ephemeral(), - "inline": await config.user(ctx.author).history_inline(), - "inline_pagesize": await config.user(ctx.author).history_inline_pagesize(), - "pagesize": await config.user(ctx.author).history_pagesize(), - "auto_evidenceformat": await config.user(ctx.author).auto_evidenceformat() - } - - override_str = [ - '- ' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), - '- ' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), - '- ' + bold("History Inline: ") + get_bool_emoji(override_settings['inline']), - '- ' + bold("History Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), - '- ' + bold("History Pagesize: ") + get_pagesize_str(override_settings['pagesize']), - ] - override_str = '\n'.join(override_str) - - e = await _core(ctx) - e.title += ": User Overrides" - e.description = """ - Use the buttons below to manage your user overrides. - These settings will override the relevant guild settings.\n - """ + override_str - return e - -async def guild(ctx: commands.Context) -> Embed: - """Generates a configuration menu field value for a guild's settings.""" - - guild_settings = { - "show_moderator": await config.guild(ctx.guild).show_moderator(), - "use_discord_permissions": await config.guild(ctx.guild).use_discord_permissions(), - "ignore_modlog": await config.guild(ctx.guild).ignore_modlog(), - "ignore_other_bots": await config.guild(ctx.guild).ignore_other_bots(), - "dm_users": await config.guild(ctx.guild).dm_users(), - "log_channel": await config.guild(ctx.guild).log_channel(), - "history_ephemeral": await config.guild(ctx.guild).history_ephemeral(), - "history_inline": await config.guild(ctx.guild).history_inline(), - "history_pagesize": await config.guild(ctx.guild).history_pagesize(), - "history_inline_pagesize": await config.guild(ctx.guild).history_inline_pagesize(), - "auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(), - } - - channel = ctx.guild.get_channel(guild_settings['log_channel']) - if channel is None: - channel = warning("Not Set") - else: - channel = channel.mention - - guild_str = [ - '- '+ bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']), - '- '+ bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']), - '- '+ bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), - '- '+ bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), - '- '+ bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), - '- '+ bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), - '- '+ bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), - '- '+ bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), - '- '+ bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), - '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']), - '- '+ bold("Log Channel: ") + channel - ] - guild_str = '\n'.join(guild_str) - - e = await _core(ctx) - e.title += ": Server Configuration" - e.description = """ - Use the buttons below to manage Aurora's server configuration.\n - """ + guild_str - return e - -async def addrole(ctx: commands.Context) -> Embed: - """Generates a configuration menu field value for a guild's addrole whitelist.""" - - whitelist = await config.guild(ctx.guild).addrole_whitelist() - if whitelist: - whitelist = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] - whitelist = '\n'.join(whitelist) - else: - whitelist = warning("No roles are on the addrole whitelist!") - - e = await _core(ctx) - e.title += ": Addrole Whitelist" - e.description = "Use the select menu below to manage this guild's addrole whitelist." - - if len(whitelist) > 4000 and len(whitelist) < 5000: - lines = whitelist.split('\n') - chunks = [] - chunk = "" - for line in lines: - if len(chunk) + len(line) > 1024: - chunks.append(chunk) - chunk = line - else: - chunk += '\n' + line if chunk else line - chunks.append(chunk) - - for chunk in chunks: - e.add_field(name="", value=chunk) - else: - e.description += '\n\n' + whitelist - - return e - -async def immune(ctx: commands.Context) -> Embed: - """Generates a configuration menu field value for a guild's immune roles.""" - - immune_roles = await config.guild(ctx.guild).immune_roles() - if immune_roles: - immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune_roles] - immune_str = '\n'.join(immune_str) - else: - immune_str = warning("No roles are set as immune roles!") - - e = await _core(ctx) - e.title += ": Immune Roles" - e.description = "Use the select menu below to manage this guild's immune roles." - - if len(immune_str) > 4000 and len(immune_str) < 5000: - lines = immune_str.split('\n') - chunks = [] - chunk = "" - for line in lines: - if len(chunk) + len(line) > 1024: - chunks.append(chunk) - chunk = line - else: - chunk += '\n' + line if chunk else line - chunks.append(chunk) - - for chunk in chunks: - e.add_field(name="", value=chunk) - else: - e.description += '\n\n' + immune_str - - return e diff --git a/aurora/configuration/menus/__init__.py b/aurora/configuration/menus/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/aurora/configuration/utils.py b/aurora/configuration/utils.py deleted file mode 100644 index fab5426..0000000 --- a/aurora/configuration/utils.py +++ /dev/null @@ -1,37 +0,0 @@ -from typing import Union - -from discord import SelectOption - -def get_bool_emoji(value: bool) -> str: - """Returns a unicode emoji based on a boolean value.""" - if value is True: - return "\N{WHITE HEAVY CHECK MARK}" - if value is False: - return "\N{NO ENTRY SIGN}" - return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" - -def get_pagesize_str(value: Union[int, None]) -> str: - """Returns a string based on a pagesize value.""" - if value is None: - return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" - return str(value) + " cases per page" - -def create_pagesize_options() -> list[SelectOption]: - """Returns a list of SelectOptions for pagesize configuration.""" - options = [] - options.append( - SelectOption( - label="Default", - value="default", - description="Reset the pagesize to the default value.", - ) - ) - for i in range(1, 21): - options.append( - SelectOption( - label=str(i), - value=str(i), - description=f"Set the pagesize to {i}.", - ) - ) - return options diff --git a/aurora/configuration/__init__.py b/aurora/menus/__init__.py similarity index 100% rename from aurora/configuration/__init__.py rename to aurora/menus/__init__.py diff --git a/aurora/configuration/menus/addrole.py b/aurora/menus/addrole.py similarity index 98% rename from aurora/configuration/menus/addrole.py rename to aurora/menus/addrole.py index a28ba9c..0e0257a 100644 --- a/aurora/configuration/menus/addrole.py +++ b/aurora/menus/addrole.py @@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands from redbot.core.utils.chat_formatting import error -from aurora.configuration.embed import addrole +from aurora.utilities.factory import addrole from aurora.utilities.config import config class Addrole(ui.View): diff --git a/aurora/configuration/menus/guild.py b/aurora/menus/guild.py similarity index 98% rename from aurora/configuration/menus/guild.py rename to aurora/menus/guild.py index fd1dfa0..7067c29 100644 --- a/aurora/configuration/menus/guild.py +++ b/aurora/menus/guild.py @@ -1,8 +1,8 @@ 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.factory import guild +from aurora.utilities.utils import create_pagesize_options from aurora.utilities.config import config class Guild(ui.View): diff --git a/aurora/configuration/menus/immune.py b/aurora/menus/immune.py similarity index 98% rename from aurora/configuration/menus/immune.py rename to aurora/menus/immune.py index 49df36a..cdeaa1b 100644 --- a/aurora/configuration/menus/immune.py +++ b/aurora/menus/immune.py @@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands from redbot.core.utils.chat_formatting import error -from aurora.configuration.embed import immune +from aurora.utilities.factory import immune from aurora.utilities.config import config class Immune(ui.View): diff --git a/aurora/configuration/menus/overrides.py b/aurora/menus/overrides.py similarity index 97% rename from aurora/configuration/menus/overrides.py rename to aurora/menus/overrides.py index f7abd97..1e062a1 100644 --- a/aurora/configuration/menus/overrides.py +++ b/aurora/menus/overrides.py @@ -1,8 +1,8 @@ from discord import ui, ButtonStyle, Interaction from redbot.core import commands -from aurora.configuration.embed import overrides -from aurora.configuration.utils import create_pagesize_options +from aurora.utilities.factory import overrides +from aurora.utilities.utils import create_pagesize_options from aurora.utilities.config import config class Overrides(ui.View): diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 02dbc99..a92c6c1 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -5,10 +5,11 @@ from datetime import datetime, timedelta import humanize from discord import Color, Embed, Guild, Interaction, InteractionMessage, User, Member -from redbot.core.utils.chat_formatting import box +from redbot.core import commands +from redbot.core.utils.chat_formatting import box, bold, error, warning -from .config import config -from .utils import fetch_channel_dict, fetch_user_dict, get_next_case_number +from aurora.utilities.config import config +from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_next_case_number, get_bool_emoji, get_pagesize_str async def message_factory(color: Color, guild: Guild, reason: str, moderation_type: str, moderator: Union[Member, User] = None, duration: timedelta = None, response: InteractionMessage = None) -> Embed: @@ -223,3 +224,156 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s content += f"\nReason: {case_dict['reason']}" return box(content, 'prolog') + + +######################################################################################################################## +### Configuration Embeds # +######################################################################################################################## + +async def _core(ctx: commands.Context) -> Embed: + """Generates the core embed for configuration menus to use.""" + e = Embed( + title="Aurora Configuration Menu", + color=await ctx.embed_color() + ) + e.set_thumbnail(url=ctx.bot.user.display_avatar.url) + return e + +async def overrides(ctx: commands.Context) -> Embed: + """Generates a configuration menu embed for a user's overrides.""" + + override_settings = { + "ephemeral": await config.user(ctx.author).history_ephemeral(), + "inline": await config.user(ctx.author).history_inline(), + "inline_pagesize": await config.user(ctx.author).history_inline_pagesize(), + "pagesize": await config.user(ctx.author).history_pagesize(), + "auto_evidenceformat": await config.user(ctx.author).auto_evidenceformat() + } + + override_str = [ + '- ' + bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']), + '- ' + bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']), + '- ' + bold("History Inline: ") + get_bool_emoji(override_settings['inline']), + '- ' + bold("History Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), + '- ' + bold("History Pagesize: ") + get_pagesize_str(override_settings['pagesize']), + ] + override_str = '\n'.join(override_str) + + e = await _core(ctx) + e.title += ": User Overrides" + e.description = """ + Use the buttons below to manage your user overrides. + These settings will override the relevant guild settings.\n + """ + override_str + return e + +async def guild(ctx: commands.Context) -> Embed: + """Generates a configuration menu field value for a guild's settings.""" + + guild_settings = { + "show_moderator": await config.guild(ctx.guild).show_moderator(), + "use_discord_permissions": await config.guild(ctx.guild).use_discord_permissions(), + "ignore_modlog": await config.guild(ctx.guild).ignore_modlog(), + "ignore_other_bots": await config.guild(ctx.guild).ignore_other_bots(), + "dm_users": await config.guild(ctx.guild).dm_users(), + "log_channel": await config.guild(ctx.guild).log_channel(), + "history_ephemeral": await config.guild(ctx.guild).history_ephemeral(), + "history_inline": await config.guild(ctx.guild).history_inline(), + "history_pagesize": await config.guild(ctx.guild).history_pagesize(), + "history_inline_pagesize": await config.guild(ctx.guild).history_inline_pagesize(), + "auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(), + } + + channel = ctx.guild.get_channel(guild_settings['log_channel']) + if channel is None: + channel = warning("Not Set") + else: + channel = channel.mention + + guild_str = [ + '- '+ bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']), + '- '+ bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']), + '- '+ bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']), + '- '+ bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']), + '- '+ bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']), + '- '+ bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']), + '- '+ bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']), + '- '+ bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']), + '- '+ bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), + '- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']), + '- '+ bold("Log Channel: ") + channel + ] + guild_str = '\n'.join(guild_str) + + e = await _core(ctx) + e.title += ": Server Configuration" + e.description = """ + Use the buttons below to manage Aurora's server configuration.\n + """ + guild_str + return e + +async def addrole(ctx: commands.Context) -> Embed: + """Generates a configuration menu field value for a guild's addrole whitelist.""" + + whitelist = await config.guild(ctx.guild).addrole_whitelist() + if whitelist: + whitelist = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] + whitelist = '\n'.join(whitelist) + else: + whitelist = warning("No roles are on the addrole whitelist!") + + e = await _core(ctx) + e.title += ": Addrole Whitelist" + e.description = "Use the select menu below to manage this guild's addrole whitelist." + + if len(whitelist) > 4000 and len(whitelist) < 5000: + lines = whitelist.split('\n') + chunks = [] + chunk = "" + for line in lines: + if len(chunk) + len(line) > 1024: + chunks.append(chunk) + chunk = line + else: + chunk += '\n' + line if chunk else line + chunks.append(chunk) + + for chunk in chunks: + e.add_field(name="", value=chunk) + else: + e.description += '\n\n' + whitelist + + return e + +async def immune(ctx: commands.Context) -> Embed: + """Generates a configuration menu field value for a guild's immune roles.""" + + immune_roles = await config.guild(ctx.guild).immune_roles() + if immune_roles: + immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune_roles] + immune_str = '\n'.join(immune_str) + else: + immune_str = warning("No roles are set as immune roles!") + + e = await _core(ctx) + e.title += ": Immune Roles" + e.description = "Use the select menu below to manage this guild's immune roles." + + if len(immune_str) > 4000 and len(immune_str) < 5000: + lines = immune_str.split('\n') + chunks = [] + chunk = "" + for line in lines: + if len(chunk) + len(line) > 1024: + chunks.append(chunk) + chunk = line + else: + chunk += '\n' + line if chunk else line + chunks.append(chunk) + + for chunk in chunks: + e.add_field(name="", value=chunk) + else: + e.description += '\n\n' + immune_str + + return e diff --git a/aurora/utilities/utils.py b/aurora/utilities/utils.py index aeab27e..4555509 100644 --- a/aurora/utilities/utils.py +++ b/aurora/utilities/utils.py @@ -4,7 +4,7 @@ import json from datetime import timedelta as td from typing import Union -from discord import Guild, Interaction, Member, User +from discord import Guild, Interaction, Member, User, SelectOption from discord.errors import Forbidden, NotFound from redbot.core import commands from redbot.core.utils.chat_formatting import error @@ -228,3 +228,37 @@ def convert_timedelta_to_str(timedelta: td) -> str: minutes = (total_seconds % 3600) // 60 seconds = total_seconds % 60 return f"{hours}:{minutes}:{seconds}" + +def get_bool_emoji(value: bool) -> str: + """Returns a unicode emoji based on a boolean value.""" + if value is True: + return "\N{WHITE HEAVY CHECK MARK}" + if value is False: + return "\N{NO ENTRY SIGN}" + return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" + +def get_pagesize_str(value: Union[int, None]) -> str: + """Returns a string based on a pagesize value.""" + if value is None: + return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" + return str(value) + " cases per page" + +def create_pagesize_options() -> list[SelectOption]: + """Returns a list of SelectOptions for pagesize configuration.""" + options = [] + options.append( + SelectOption( + label="Default", + value="default", + description="Reset the pagesize to the default value.", + ) + ) + for i in range(1, 21): + options.append( + SelectOption( + label=str(i), + value=str(i), + description=f"Set the pagesize to {i}.", + ) + ) + return options From 950d4abf6a1355b1608e11e1803a27836e4bfdb9 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:26:54 +0000 Subject: [PATCH 69/72] fix(aurora): pylint fixes --- aurora/aurora.py | 10 +++++----- aurora/menus/addrole.py | 6 +++--- aurora/menus/guild.py | 24 ++++++++++++------------ aurora/menus/immune.py | 6 +++--- aurora/menus/overrides.py | 12 ++++++------ aurora/utilities/factory.py | 18 +++++++++--------- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 783f0a2..2f1a913 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -29,7 +29,7 @@ from aurora.menus.immune import Immune from aurora.menus.overrides import Overrides from aurora.utilities.config import config, register_config from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log -from aurora.utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory, overrides, immune, guild, addrole +from aurora.utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory, overrides_embed, immune_embed, guild_embed, addrole_embed from aurora.utilities.logger import logger from aurora.utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat @@ -1038,14 +1038,14 @@ class Aurora(commands.Cog): @aurora_settings.command(name="overrides", aliases=["override", "user"]) async def aurora_settings_overrides(self, ctx: commands.Context): """Manage Aurora's user overriddable settings.""" - await ctx.send(embed=await overrides(ctx), view=Overrides(ctx)) + await ctx.send(embed=await overrides_embed(ctx), view=Overrides(ctx)) @aurora_settings.command(name="guild", aliases=["server"]) @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() async def aurora_settings_guild(self, ctx: commands.Context): """Manage Aurora's guild settings.""" - await ctx.send(embed=await guild(ctx), view=Guild(ctx)) + await ctx.send(embed=await guild_embed(ctx), view=Guild(ctx)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) @@ -1054,14 +1054,14 @@ class Aurora(commands.Cog): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole(ctx), view=Addrole(ctx)) + await ctx.send(embed=await addrole_embed(ctx), view=Addrole(ctx)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() async def aurora_settings_immunity(self, ctx: commands.Context): """Manage the immunity whitelist.""" - await ctx.send(embed=await immune(ctx), view=Immune(ctx)) + await ctx.send(embed=await immune_embed(ctx), view=Immune(ctx)) @aurora.group(autohelp=True, name="import") @commands.admin() diff --git a/aurora/menus/addrole.py b/aurora/menus/addrole.py index 0e0257a..c792566 100644 --- a/aurora/menus/addrole.py +++ b/aurora/menus/addrole.py @@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands from redbot.core.utils.chat_formatting import error -from aurora.utilities.factory import addrole +from aurora.utilities.factory import addrole_embed from aurora.utilities.config import config class Addrole(ui.View): @@ -22,7 +22,7 @@ class Addrole(ui.View): else: addrole_whitelist.append(select.values[0].id) await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist) - await interaction.message.edit(embed=await addrole(self.ctx)) + await interaction.message.edit(embed=await addrole_embed(self.ctx)) @ui.button(label="Clear", style=ButtonStyle.red, row=1) async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -31,7 +31,7 @@ class Addrole(ui.View): return await interaction.response.defer() await config.guild(self.ctx.guild).addrole_whitelist.clear() - await interaction.message.edit(embed=await addrole(self.ctx)) + 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 diff --git a/aurora/menus/guild.py b/aurora/menus/guild.py index 7067c29..7d14ebc 100644 --- a/aurora/menus/guild.py +++ b/aurora/menus/guild.py @@ -1,7 +1,7 @@ from discord import ui, ButtonStyle, Interaction from redbot.core import commands -from aurora.utilities.factory import guild +from aurora.utilities.factory import guild_embed from aurora.utilities.utils import create_pagesize_options from aurora.utilities.config import config @@ -18,7 +18,7 @@ class Guild(ui.View): await interaction.response.defer() current_setting = await config.guild(interaction.guild).show_moderator await config.guild(interaction.guild).show_moderator.set(not current_setting) - await interaction.message.edit(embed=await guild(self.ctx)) + await interaction.message.edit(embed=await guild_embed(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 @@ -28,7 +28,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(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 @@ -38,7 +38,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(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 @@ -48,7 +48,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.button(label="DM Users", style=ButtonStyle.green, row=1) async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -58,7 +58,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1) async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -68,7 +68,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=1) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -78,7 +78,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.button(label="History Inline", style=ButtonStyle.green, row=1) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -88,7 +88,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2) async def pagesize(self, interaction: Interaction, select: ui.Select,): @@ -100,7 +100,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3) async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): @@ -112,7 +112,7 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=4) async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect): @@ -121,4 +121,4 @@ class Guild(ui.View): 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)) + await interaction.message.edit(embed=await guild_embed(self.ctx)) diff --git a/aurora/menus/immune.py b/aurora/menus/immune.py index cdeaa1b..e48aba8 100644 --- a/aurora/menus/immune.py +++ b/aurora/menus/immune.py @@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction from redbot.core import commands from redbot.core.utils.chat_formatting import error -from aurora.utilities.factory import immune +from aurora.utilities.factory import immune_embed from aurora.utilities.config import config class Immune(ui.View): @@ -23,7 +23,7 @@ class Immune(ui.View): 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)) + await interaction.message.edit(embed=await immune_embed(self.ctx)) @ui.button(label="Clear", style=ButtonStyle.red, row=1) async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -32,7 +32,7 @@ class Immune(ui.View): return await interaction.response.defer() await config.guild(self.ctx.guild).immune_roles.clear() - await interaction.message.edit(embed=await immune(self.ctx)) + await interaction.message.edit(embed=await immune_embed(self.ctx)) @ui.button(label="Close", style=ButtonStyle.gray) async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument diff --git a/aurora/menus/overrides.py b/aurora/menus/overrides.py index 1e062a1..4475706 100644 --- a/aurora/menus/overrides.py +++ b/aurora/menus/overrides.py @@ -1,7 +1,7 @@ from discord import ui, ButtonStyle, Interaction from redbot.core import commands -from aurora.utilities.factory import overrides +from aurora.utilities.factory import overrides_embed from aurora.utilities.utils import create_pagesize_options from aurora.utilities.config import config @@ -23,7 +23,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).auto_evidenceformat.set(True) else: await config.user(self.ctx.author).auto_evidenceformat.set(False) - await interaction.message.edit(embed=await overrides(self.ctx)) + await interaction.message.edit(embed=await overrides_embed(self.ctx)) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0) async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -38,7 +38,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_ephemeral.set(True) else: await config.user(self.ctx.author).history_ephemeral.set(False) - await interaction.message.edit(embed=await overrides(self.ctx)) + await interaction.message.edit(embed=await overrides_embed(self.ctx)) @ui.button(label="Inline", style=ButtonStyle.green, row=0) async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument @@ -53,7 +53,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline.set(True) else: await config.user(self.ctx.author).history_inline.set(False) - await interaction.message.edit(embed=await overrides(self.ctx)) + await interaction.message.edit(embed=await overrides_embed(self.ctx)) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): @@ -65,7 +65,7 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_inline_pagesize.clear() else: await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) - await interaction.message.edit(embed=await overrides(self.ctx)) + await interaction.message.edit(embed=await overrides_embed(self.ctx)) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) async def pagesize(self, interaction: Interaction, select: ui.Select,): @@ -77,4 +77,4 @@ class Overrides(ui.View): await config.user(self.ctx.author).history_pagesize.clear() else: await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) - await interaction.message.edit(embed=await overrides(self.ctx)) + await interaction.message.edit(embed=await overrides_embed(self.ctx)) diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index a92c6c1..4d22f39 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -230,7 +230,7 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s ### Configuration Embeds # ######################################################################################################################## -async def _core(ctx: commands.Context) -> Embed: +async def _config(ctx: commands.Context) -> Embed: """Generates the core embed for configuration menus to use.""" e = Embed( title="Aurora Configuration Menu", @@ -239,7 +239,7 @@ async def _core(ctx: commands.Context) -> Embed: e.set_thumbnail(url=ctx.bot.user.display_avatar.url) return e -async def overrides(ctx: commands.Context) -> Embed: +async def overrides_embed(ctx: commands.Context) -> Embed: """Generates a configuration menu embed for a user's overrides.""" override_settings = { @@ -259,7 +259,7 @@ async def overrides(ctx: commands.Context) -> Embed: ] override_str = '\n'.join(override_str) - e = await _core(ctx) + e = await _config(ctx) e.title += ": User Overrides" e.description = """ Use the buttons below to manage your user overrides. @@ -267,7 +267,7 @@ async def overrides(ctx: commands.Context) -> Embed: """ + override_str return e -async def guild(ctx: commands.Context) -> Embed: +async def guild_embed(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's settings.""" guild_settings = { @@ -305,14 +305,14 @@ async def guild(ctx: commands.Context) -> Embed: ] guild_str = '\n'.join(guild_str) - e = await _core(ctx) + e = await _config(ctx) e.title += ": Server Configuration" e.description = """ Use the buttons below to manage Aurora's server configuration.\n """ + guild_str return e -async def addrole(ctx: commands.Context) -> Embed: +async def addrole_embed(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's addrole whitelist.""" whitelist = await config.guild(ctx.guild).addrole_whitelist() @@ -322,7 +322,7 @@ async def addrole(ctx: commands.Context) -> Embed: else: whitelist = warning("No roles are on the addrole whitelist!") - e = await _core(ctx) + e = await _config(ctx) e.title += ": Addrole Whitelist" e.description = "Use the select menu below to manage this guild's addrole whitelist." @@ -345,7 +345,7 @@ async def addrole(ctx: commands.Context) -> Embed: return e -async def immune(ctx: commands.Context) -> Embed: +async def immune_embed(ctx: commands.Context) -> Embed: """Generates a configuration menu field value for a guild's immune roles.""" immune_roles = await config.guild(ctx.guild).immune_roles() @@ -355,7 +355,7 @@ async def immune(ctx: commands.Context) -> Embed: else: immune_str = warning("No roles are set as immune roles!") - e = await _core(ctx) + e = await _config(ctx) e.title += ": Immune Roles" e.description = "Use the select menu below to manage this guild's immune roles." From a7d8a20c57e3c6232ccfbb3cf257022ebcef48fa Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 14:29:57 +0000 Subject: [PATCH 70/72] fix(aurora): fixed incorrect example usage for `[p]aurora timedelta` --- aurora/aurora.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 2f1a913..2cba6bc 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -1112,7 +1112,7 @@ class Aurora(commands.Cog): """This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object. **Example usage** - `[p]timedelta 1 day 15hr 82 minutes 52s` + `[p]aurora timedelta 1 day 15hr 82 minutes 52s` **Output** `1 day, 16:22:52`""" try: From eb79025d2a3706282eaa99e24553badcedbe6bc4 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 15:23:55 +0000 Subject: [PATCH 71/72] feat(docs): updated configuration docs with all of the new text commands --- .docs/aurora/configuration.md | 49 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/.docs/aurora/configuration.md b/.docs/aurora/configuration.md index 7df5f7b..114654a 100644 --- a/.docs/aurora/configuration.md +++ b/.docs/aurora/configuration.md @@ -8,7 +8,7 @@ This page is still a work in progress. ## aurora - Usage: `[p]aurora` -- Aliases: `moderation, mod` +- Aliases: `moderation and mod` Settings and miscellaneous commands for Aurora. @@ -20,13 +20,6 @@ Settings and miscellaneous commands for Aurora. Import moderation history from other bots. -#### aurora import galacticbot - -- Usage: `[p]aurora import galacticbot` -- Restricted to: `ADMIN` - -Import moderation history from GalacticBot. - #### aurora import aurora - Usage: `[p]aurora import aurora` @@ -34,6 +27,13 @@ Import moderation history from GalacticBot. Import moderation history from another bot using Aurora. +#### aurora import galacticbot + +- Usage: `[p]aurora import galacticbot` +- Restricted to: `ADMIN` + +Import moderation history from GalacticBot. + ### aurora settings - Usage: `[p]aurora settings` @@ -41,24 +41,47 @@ Import moderation history from another bot using Aurora. Configure Aurora's settings. -#### aurora settings core +#### aurora settings server -- Usage: `[p]aurora settings core` +- Usage: `[p]aurora settings server` +- Restricted to: `ADMIN` +- Aliases: `server` +- Checks: `server_only` -Manage Aurora's core settings. +Manage Aurora's server settings. + +#### aurora settings overrides + +- Usage: `[p]aurora settings overrides` +- Aliases: `override and user` + +Manage Aurora's user overriddable settings. #### aurora settings addrole - Usage: `[p]aurora settings addrole` - Restricted to: `ADMIN` - Aliases: `removerole` +- Checks: `server_only` -Manage the addrole whitelist. -Roles added to this list are also applied to `/removerole`. +Manage the addrole whitelist.

Roles added to this list are also applied to `/removerole`. #### aurora settings immunity - Usage: `[p]aurora settings immunity` - Restricted to: `ADMIN` +- Checks: `server_only` Manage the immunity whitelist. + +### aurora timedelta + +- Usage: `[p]aurora timedelta ` +- Aliases: `tdc, td, and timedeltaconvert` + +This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object. + +**Example usage** +`[p]timedelta 1 day 15hr 82 minutes 52s` +**Output** +`1 day, 16:22:52` From b9ca8d32d3476db7efd44c6e7f5e3fbb291a4f20 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 16 Jan 2024 15:24:24 +0000 Subject: [PATCH 72/72] fix(docs): removed some inline html --- .docs/aurora/configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.docs/aurora/configuration.md b/.docs/aurora/configuration.md index 114654a..6fe29ed 100644 --- a/.docs/aurora/configuration.md +++ b/.docs/aurora/configuration.md @@ -64,7 +64,8 @@ Manage Aurora's user overriddable settings. - Aliases: `removerole` - Checks: `server_only` -Manage the addrole whitelist.

Roles added to this list are also applied to `/removerole`. +Manage the addrole whitelist. +Roles added to this list are also applied to `/removerole`. #### aurora settings immunity