Aurora Configuration Rewrite #15

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

View file

@ -18,6 +18,7 @@ from discord.ext import tasks
from pytimeparse2 import disable_dateutil, parse from pytimeparse2 import disable_dateutil, parse
from redbot.core import app_commands, commands, data_manager from redbot.core import app_commands, commands, data_manager
from redbot.core.app_commands import Choice from redbot.core.app_commands import Choice
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import box, error, warning from redbot.core.utils.chat_formatting import box, error, warning
from .abc import CompositeMetaClass from .abc import CompositeMetaClass
@ -65,7 +66,7 @@ class Aurora(Configuration, commands.Cog, metaclass=CompositeMetaClass): # pylin
else: else:
logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester)
def __init__(self, bot): def __init__(self, bot: Red):
super().__init__() super().__init__()
self.bot = bot self.bot = bot
register_config(config) register_config(config)

View file

@ -1,24 +1,39 @@
from redbot.core import commands from redbot.core import commands
from redbot.core.utils.chat_formatting import error, warning 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 ..abc import Mixin
from ..importers.aurora import ImportAuroraView from ..importers.aurora import ImportAuroraView
from ..importers.galacticbot import ImportGalacticBotView from ..importers.galacticbot import ImportGalacticBotView
class Configuration(Mixin): class Configuration(Mixin):
"""Configuration commands for Aurora.""" """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): async def aurora(self, ctx: commands.Context):
"""Settings and miscellaneous commands for Aurora.""" """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): async def aurora_settings(self, ctx: commands.Context):
"""View Aurora configuration settings.""" """View Aurora configuration settings."""
await ctx.send(embed=await embed(ctx)) 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.admin()
@commands.guild_only() @commands.guild_only()
async def aurora_import(self, ctx: commands.Context): async def aurora_import(self, ctx: commands.Context):
@ -28,8 +43,16 @@ class Configuration(Mixin):
@commands.admin() @commands.admin()
async def aurora_import_aurora(self, ctx: commands.Context): async def aurora_import_aurora(self, ctx: commands.Context):
"""Import moderations from another bot using Aurora.""" """Import moderations from another bot using Aurora."""
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': if (
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.*")) 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)) await message.edit(view=ImportAuroraView(60, ctx, message))
else: else:
await ctx.send(error("Please provide a valid Aurora export file.")) await ctx.send(error("Please provide a valid Aurora export file."))
@ -38,8 +61,18 @@ class Configuration(Mixin):
@commands.admin() @commands.admin()
async def aurora_import_galacticbot(self, ctx: commands.Context): async def aurora_import_galacticbot(self, ctx: commands.Context):
"""Import moderations from GalacticBot.""" """Import moderations from GalacticBot."""
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8': if (
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.*")) 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)) await message.edit(view=ImportGalacticBotView(60, ctx, message))
else: 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.")
)

View file

@ -78,15 +78,15 @@ async def _guild(guild: Guild) -> str:
guild_str = '\n'.join(guild_str) guild_str = '\n'.join(guild_str)
return guild_str return guild_str
async def _blacklist(guild: Guild) -> str: async def _addrole(guild: Guild) -> str:
"""Generates a configuration menu field value for a guild's blacklist.""" """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: 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) blacklist = '\n'.join(blacklist)
else: else:
blacklist = warning("No roles are set as blacklist roles!") blacklist = warning("No roles are on the addrole whitelist!")
return blacklist return blacklist
async def _immune(guild: Guild) -> str: 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) 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): 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="Guild Settings", value=await _guild(ctx.guild), inline=False)
e.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False) return e
e.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False)
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 return e