feat(aurora): starting work on the config rewrite
This commit is contained in:
parent
a1b038057e
commit
c42b4eca2d
9 changed files with 192 additions and 325 deletions
328
aurora/aurora.py
328
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue