Aurora Configuration Rewrite #15

Merged
cswimr merged 73 commits from aurora-config-rewrite into main 2024-01-16 12:19:08 -05:00
6 changed files with 38 additions and 38 deletions
Showing only changes of commit 950d4abf6a - Show all commits

View file

@ -29,7 +29,7 @@ from aurora.menus.immune import Immune
from aurora.menus.overrides import Overrides from aurora.menus.overrides import Overrides
from aurora.utilities.config import config, register_config from aurora.utilities.config import config, register_config
from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log 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.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 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"]) @aurora_settings.command(name="overrides", aliases=["override", "user"])
async def aurora_settings_overrides(self, ctx: commands.Context): async def aurora_settings_overrides(self, ctx: commands.Context):
"""Manage Aurora's user overriddable settings.""" """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"]) @aurora_settings.command(name="guild", aliases=["server"])
@commands.admin_or_permissions(manage_guild=True) @commands.admin_or_permissions(manage_guild=True)
@commands.guild_only() @commands.guild_only()
async def aurora_settings_guild(self, ctx: commands.Context): async def aurora_settings_guild(self, ctx: commands.Context):
"""Manage Aurora's guild settings.""" """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"]) @aurora_settings.command(name="addrole", aliases=["removerole"])
@commands.admin_or_permissions(manage_guild=True) @commands.admin_or_permissions(manage_guild=True)
@ -1054,14 +1054,14 @@ class Aurora(commands.Cog):
"""Manage the addrole whitelist. """Manage the addrole whitelist.
Roles added to this list are also applied to `/removerole`.""" 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") @aurora_settings.command(name="immunity")
@commands.admin_or_permissions(manage_guild=True) @commands.admin_or_permissions(manage_guild=True)
@commands.guild_only() @commands.guild_only()
async def aurora_settings_immunity(self, ctx: commands.Context): async def aurora_settings_immunity(self, ctx: commands.Context):
"""Manage the immunity whitelist.""" """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") @aurora.group(autohelp=True, name="import")
@commands.admin() @commands.admin()

View file

@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction
from redbot.core import commands from redbot.core import commands
from redbot.core.utils.chat_formatting import error 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 from aurora.utilities.config import config
class Addrole(ui.View): class Addrole(ui.View):
@ -22,7 +22,7 @@ class Addrole(ui.View):
else: else:
addrole_whitelist.append(select.values[0].id) addrole_whitelist.append(select.values[0].id)
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist) 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) @ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
@ -31,7 +31,7 @@ class Addrole(ui.View):
return return
await interaction.response.defer() await interaction.response.defer()
await config.guild(self.ctx.guild).addrole_whitelist.clear() 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) @ui.button(label="Close", style=ButtonStyle.gray)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument

View file

@ -1,7 +1,7 @@
from discord import ui, ButtonStyle, Interaction from discord import ui, ButtonStyle, Interaction
from redbot.core import commands 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.utils import create_pagesize_options
from aurora.utilities.config import config from aurora.utilities.config import config
@ -18,7 +18,7 @@ class Guild(ui.View):
await interaction.response.defer() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).show_moderator current_setting = await config.guild(interaction.guild).show_moderator
await config.guild(interaction.guild).show_moderator.set(not current_setting) 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) @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 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).use_discord_permissions() current_setting = await config.guild(interaction.guild).use_discord_permissions()
await config.guild(interaction.guild).use_discord_permissions.set(not current_setting) 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) @ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).ignore_modlog() current_setting = await config.guild(interaction.guild).ignore_modlog()
await config.guild(interaction.guild).ignore_modlog.set(not current_setting) 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) @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 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).ignore_other_bots() current_setting = await config.guild(interaction.guild).ignore_other_bots()
await config.guild(interaction.guild).ignore_other_bots.set(not current_setting) 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) @ui.button(label="DM Users", style=ButtonStyle.green, row=1)
async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).dm_users() current_setting = await config.guild(interaction.guild).dm_users()
await config.guild(interaction.guild).dm_users.set(not current_setting) 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) @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 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).auto_evidenceformat() current_setting = await config.guild(interaction.guild).auto_evidenceformat()
await config.guild(interaction.guild).auto_evidenceformat.set(not current_setting) 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) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=1)
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).history_ephemeral() current_setting = await config.guild(interaction.guild).history_ephemeral()
await config.guild(interaction.guild).history_ephemeral.set(not current_setting) 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) @ui.button(label="History Inline", style=ButtonStyle.green, row=1)
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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() await interaction.response.defer()
current_setting = await config.guild(interaction.guild).history_inline() current_setting = await config.guild(interaction.guild).history_inline()
await config.guild(interaction.guild).history_inline.set(not current_setting) 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) @ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2)
async def pagesize(self, interaction: Interaction, select: ui.Select,): async def pagesize(self, interaction: Interaction, select: ui.Select,):
@ -100,7 +100,7 @@ class Guild(ui.View):
else: else:
await config.guild(interaction.guild).history_pagesize.set(int(select.values[0])) await config.guild(interaction.guild).history_pagesize.set(int(select.values[0]))
await interaction.response.defer() 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) @ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3)
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): async def inline_pagesize(self, interaction: Interaction, select: ui.Select,):
@ -112,7 +112,7 @@ class Guild(ui.View):
else: else:
await config.guild(interaction.guild).history_inline_pagesize.set(int(select.values[0])) await config.guild(interaction.guild).history_inline_pagesize.set(int(select.values[0]))
await interaction.response.defer() 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) @ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=4)
async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect): async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect):
@ -121,4 +121,4 @@ class Guild(ui.View):
return return
await interaction.response.defer() await interaction.response.defer()
await config.guild(interaction.guild).log_channel.set(select.values[0].id) 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))

View file

@ -2,7 +2,7 @@ from discord import ButtonStyle, ui, Interaction
from redbot.core import commands from redbot.core import commands
from redbot.core.utils.chat_formatting import error 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 from aurora.utilities.config import config
class Immune(ui.View): class Immune(ui.View):
@ -23,7 +23,7 @@ class Immune(ui.View):
else: else:
immune_roles.append(role.id) immune_roles.append(role.id)
await config.guild(self.ctx.guild).immune_roles.set(immune_roles) 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) @ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
@ -32,7 +32,7 @@ class Immune(ui.View):
return return
await interaction.response.defer() await interaction.response.defer()
await config.guild(self.ctx.guild).immune_roles.clear() 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) @ui.button(label="Close", style=ButtonStyle.gray)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument

View file

@ -1,7 +1,7 @@
from discord import ui, ButtonStyle, Interaction from discord import ui, ButtonStyle, Interaction
from redbot.core import commands 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.utils import create_pagesize_options
from aurora.utilities.config import config from aurora.utilities.config import config
@ -23,7 +23,7 @@ class Overrides(ui.View):
await config.user(self.ctx.author).auto_evidenceformat.set(True) await config.user(self.ctx.author).auto_evidenceformat.set(True)
else: else:
await config.user(self.ctx.author).auto_evidenceformat.set(False) 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) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0)
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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) await config.user(self.ctx.author).history_ephemeral.set(True)
else: else:
await config.user(self.ctx.author).history_ephemeral.set(False) 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) @ui.button(label="Inline", style=ButtonStyle.green, row=0)
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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) await config.user(self.ctx.author).history_inline.set(True)
else: else:
await config.user(self.ctx.author).history_inline.set(False) 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) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1)
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): 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() await config.user(self.ctx.author).history_inline_pagesize.clear()
else: else:
await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0])) 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) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2)
async def pagesize(self, interaction: Interaction, select: ui.Select,): 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() await config.user(self.ctx.author).history_pagesize.clear()
else: else:
await config.user(self.ctx.author).history_pagesize.set(int(select.values[0])) 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))

View file

@ -230,7 +230,7 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
### Configuration Embeds # ### 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.""" """Generates the core embed for configuration menus to use."""
e = Embed( e = Embed(
title="Aurora Configuration Menu", 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) e.set_thumbnail(url=ctx.bot.user.display_avatar.url)
return e 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.""" """Generates a configuration menu embed for a user's overrides."""
override_settings = { override_settings = {
@ -259,7 +259,7 @@ async def overrides(ctx: commands.Context) -> Embed:
] ]
override_str = '\n'.join(override_str) override_str = '\n'.join(override_str)
e = await _core(ctx) e = await _config(ctx)
e.title += ": User Overrides" e.title += ": User Overrides"
e.description = """ e.description = """
Use the buttons below to manage your user overrides. Use the buttons below to manage your user overrides.
@ -267,7 +267,7 @@ async def overrides(ctx: commands.Context) -> Embed:
""" + override_str """ + override_str
return e 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.""" """Generates a configuration menu field value for a guild's settings."""
guild_settings = { guild_settings = {
@ -305,14 +305,14 @@ async def guild(ctx: commands.Context) -> Embed:
] ]
guild_str = '\n'.join(guild_str) guild_str = '\n'.join(guild_str)
e = await _core(ctx) e = await _config(ctx)
e.title += ": Server Configuration" e.title += ": Server Configuration"
e.description = """ e.description = """
Use the buttons below to manage Aurora's server configuration.\n Use the buttons below to manage Aurora's server configuration.\n
""" + guild_str """ + guild_str
return e 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.""" """Generates a configuration menu field value for a guild's addrole whitelist."""
whitelist = await config.guild(ctx.guild).addrole_whitelist() whitelist = await config.guild(ctx.guild).addrole_whitelist()
@ -322,7 +322,7 @@ async def addrole(ctx: commands.Context) -> Embed:
else: else:
whitelist = warning("No roles are on the addrole whitelist!") whitelist = warning("No roles are on the addrole whitelist!")
e = await _core(ctx) e = await _config(ctx)
e.title += ": Addrole Whitelist" e.title += ": Addrole Whitelist"
e.description = "Use the select menu below to manage this guild's 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 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.""" """Generates a configuration menu field value for a guild's immune roles."""
immune_roles = await config.guild(ctx.guild).immune_roles() immune_roles = await config.guild(ctx.guild).immune_roles()
@ -355,7 +355,7 @@ async def immune(ctx: commands.Context) -> Embed:
else: else:
immune_str = warning("No roles are set as immune roles!") immune_str = warning("No roles are set as immune roles!")
e = await _core(ctx) e = await _config(ctx)
e.title += ": Immune Roles" e.title += ": Immune Roles"
e.description = "Use the select menu below to manage this guild's immune roles." e.description = "Use the select menu below to manage this guild's immune roles."