WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
5 changed files with 694 additions and 647 deletions
Showing only changes of commit 97406e7bac - Show all commits

View file

@ -46,7 +46,7 @@ class Aurora(commands.Cog):
This cog stores all of its data in an SQLite database.""" This cog stores all of its data in an SQLite database."""
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"] __author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
__version__ = "3.0.0-indev26" __version__ = "3.0.0-indev27"
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs" __git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
__documentation__ = "https://seacogs.coastalcommits.com/aurora/" __documentation__ = "https://seacogs.coastalcommits.com/aurora/"
@ -119,7 +119,7 @@ class Aurora(commands.Cog):
It checks if the target can be moderated, then calls the handler method of the moderation type specified. It checks if the target can be moderated, then calls the handler method of the moderation type specified.
Args: Args:
ctx (Union[commands.Context, discord.Interaction]): The context of the command. If this is a `discord.Interaction` object, it will be converted to a `commands.Context` object. Additionally, if the interaction orignated from a context menu, the `ctx.author` attribute will be overriden to `interaction.user`. ctx (Union[commands.Context, discord.Interaction]): The context of the command. If this is a `discord.Interaction` object, it will be converted to a `commands.Context` object. Additionally, if the interaction originated from a context menu the `ctx.author` attribute will be overridden to `interaction.user`.
target (discord.Member, discord.User, discord.abc.Messageable): The target user or channel to moderate. target (discord.Member, discord.User, discord.abc.Messageable): The target user or channel to moderate.
permissions (List[str]): The permissions required to moderate the target. permissions (List[str]): The permissions required to moderate the target.
moderation_type (Type): The moderation type (handler) to use. See `aurora.models.moderation_types` for some examples. moderation_type (Type): The moderation type (handler) to use. See `aurora.models.moderation_types` for some examples.
@ -742,7 +742,7 @@ class Aurora(commands.Cog):
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
await interaction.followup.send( await interaction.followup.send(
content=error( content=error(
"An error occured while exporting the moderation history.\nError:\n" "An error occurred while exporting the moderation history.\nError:\n"
) )
+ box(text=e, lang="py"), + box(text=e, lang="py"),
ephemeral=ephemeral, ephemeral=ephemeral,
@ -1196,7 +1196,7 @@ 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 overridable settings."""
msg = await ctx.send(embed=await overrides_embed(ctx)) msg = await ctx.send(embed=await overrides_embed(ctx))
await msg.edit(view=Overrides(ctx, msg, 60)) await msg.edit(view=Overrides(ctx, msg, 60))
@ -1355,7 +1355,7 @@ class Aurora(commands.Cog):
embed.set_thumbnail(url=self.bot.user.avatar.url) embed.set_thumbnail(url=self.bot.user.avatar.url)
embed.add_field( embed.add_field(
name="Version", name="Version",
value=f"[{self.__version__}](https://www.coastalcommits.com/cswimr/SeaCogs)" value=f"[{self.__version__}]({self.__git__})"
) )
embed.add_field( embed.add_field(
name="Author", name="Author",

View file

@ -1,5 +1,5 @@
{ {
"author" : ["Seaswimmer (seasw.)"], "author" : ["Seaswimmer (cswimr)"],
"install_msg" : "Thank you for installing Aurora!\nMost of this cog's functionality requires enabling slash commands.\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).", "install_msg" : "Thank you for installing Aurora!\nMost of this cog's functionality requires enabling slash commands.\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).",
"name" : "Aurora", "name" : "Aurora",
"short" : "A full replacement for Red's core Mod cogs.", "short" : "A full replacement for Red's core Mod cogs.",
@ -9,7 +9,7 @@
"disabled": false, "disabled": false,
"min_bot_version": "3.5.0", "min_bot_version": "3.5.0",
"min_python_version": [3, 10, 0], "min_python_version": [3, 10, 0],
"requirements": ["pydantic", "aiosqlite", "phx-class-registry==4.1.0"], "requirements": ["pydantic", "aiosqlite", "phx-class-registry==5.0.0"],
"tags": [ "tags": [
"mod", "mod",
"moderate", "moderate",

View file

@ -1,14 +1,15 @@
from abc import abstractmethod from abc import ABC, abstractmethod
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
from class_registry import AutoRegister, ClassRegistry from class_registry import ClassRegistry
from class_registry.base import AutoRegister
from discord import Interaction, Member, User from discord import Interaction, Member, User
from discord.abc import Messageable from discord.abc import Messageable
from redbot.core import commands from redbot.core import commands
type_registry: Dict['str', 'Type'] = ClassRegistry(attr_name='key', unique=True) type_registry: Dict['str', 'Type'] = ClassRegistry(attr_name='key', unique=True)
class Type(metaclass=AutoRegister(type_registry)): class Type(AutoRegister(type_registry), ABC):
"""This is a base class for moderation types. """This is a base class for moderation types.
Attributes: Attributes:
@ -16,7 +17,7 @@ class Type(metaclass=AutoRegister(type_registry)):
string (str): The string to display for this type. string (str): The string to display for this type.
verb (str): The verb to use for this type. verb (str): The verb to use for this type.
embed_desc (str): The string to use for embed descriptions. embed_desc (str): The string to use for embed descriptions.
channel (bool): Whether this type targets channels or users. If this is `true` in a subclass, its overriden handler methods should be typed with `discord.abc.Messageable` instead of `discord.Member | discord.User`. channel (bool): Whether this type targets channels or users. If this is `true` in a subclass, its overridden handler methods should be typed with `discord.abc.Messageable` instead of `discord.Member | discord.User`.
removes_from_guild (bool): Whether this type's handler removes the target from the guild, or if the moderation is expected to occur whenever the user is not in the guild. This does not actually remove the target from the guild, the handler method is responsible for that. removes_from_guild (bool): Whether this type's handler removes the target from the guild, or if the moderation is expected to occur whenever the user is not in the guild. This does not actually remove the target from the guild, the handler method is responsible for that.
Properties: Properties:

1316
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@ colorthief = "^0.2.1"
beautifulsoup4 = "^4.12.3" beautifulsoup4 = "^4.12.3"
markdownify = "^0.12.1" markdownify = "^0.12.1"
aiosqlite = "^0.20.0" aiosqlite = "^0.20.0"
phx-class-registry = "^4.1.0" phx-class-registry = "^5.0.0"
[tool.poetry.group.dev] [tool.poetry.group.dev]
optional = true optional = true