WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
6 changed files with 27 additions and 29 deletions
Showing only changes of commit ac8cefd779 - Show all commits

View file

@ -20,7 +20,8 @@ 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.bot import Red
from redbot.core.commands.converter import parse_relativedelta, parse_timedelta from redbot.core.commands.converter import parse_relativedelta, parse_timedelta
from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning from redbot.core.utils.chat_formatting import (box, error, humanize_list,
humanize_timedelta, warning)
from aurora.importers.aurora import ImportAuroraView from aurora.importers.aurora import ImportAuroraView
from aurora.importers.galacticbot import ImportGalacticBotView from aurora.importers.galacticbot import ImportGalacticBotView
@ -31,10 +32,17 @@ from aurora.menus.overrides import Overrides
from aurora.models import Change, Moderation from aurora.models import Change, Moderation
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 from aurora.utilities.database import connect, create_guild_table
from aurora.utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, message_factory, overrides_embed from aurora.utilities.factory import (addrole_embed, case_factory,
changes_factory, evidenceformat_factory,
guild_embed, immune_embed,
message_factory, overrides_embed)
from aurora.utilities.json import dump from aurora.utilities.json import dump
from aurora.utilities.logger import logger from aurora.utilities.logger import logger
from aurora.utilities.utils import check_moddable, check_permissions, get_footer_image, log, send_evidenceformat, timedelta_from_relativedelta from aurora.utilities.utils import (check_moddable, check_permissions,
get_footer_image, log, send_evidenceformat,
timedelta_from_relativedelta)
class Aurora(commands.Cog): class Aurora(commands.Cog):
"""Aurora is a fully-featured moderation system. """Aurora is a fully-featured moderation system.
@ -1327,9 +1335,7 @@ class Aurora(commands.Cog):
embed=embed, ephemeral=ephemeral embed=embed, ephemeral=ephemeral
) )
elif evidenceformat: elif evidenceformat:
content = await evidenceformat_factory( content = await evidenceformat_factory(moderation=mod)
interaction=interaction, moderation=mod
)
await interaction.response.send_message( await interaction.response.send_message(
content=content, ephemeral=ephemeral content=content, ephemeral=ephemeral
) )

View file

@ -100,13 +100,13 @@ class ImportGalacticBotView(ui.View):
if resolved_timestamp is None: if resolved_timestamp is None:
resolved_timestamp = timestamp resolved_timestamp = timestamp
changes = [ changes = [
Change.from_dict({ Change.from_dict(interaction.client, {
"type": "ORIGINAL", "type": "ORIGINAL",
"reason": case["reason"], "reason": case["reason"],
"user_id": case["executor"], "user_id": case["executor"],
"timestamp": timestamp, "timestamp": timestamp,
}), }),
Change.from_dict({ Change.from_dict(interaction.client, {
"type": "RESOLVE", "type": "RESOLVE",
"reason": resolved_reason, "reason": resolved_reason,
"user_id": resolved_by, "user_id": resolved_by,

View file

@ -19,7 +19,7 @@ class AuroraBaseModel(BaseModel):
bot: Red bot: Red
def to_json(self, indent: int = None, file: Any = None, **kwargs): def to_json(self, indent: int = None, file: Any = None, **kwargs):
from aurora.utilities.json import dump, dumps from aurora.utilities.json import dump, dumps # pylint: disable=cyclic-import
return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs) return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs)
class AuroraGuildModel(AuroraBaseModel): class AuroraGuildModel(AuroraBaseModel):
@ -27,7 +27,7 @@ class AuroraGuildModel(AuroraBaseModel):
guild_id: int guild_id: int
def to_json(self, indent: int = None, file: Any = None, **kwargs): def to_json(self, indent: int = None, file: Any = None, **kwargs):
from aurora.utilities.json import dump, dumps from aurora.utilities.json import dump, dumps # pylint: disable=cyclic-import
return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs) return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs)
class Moderation(AuroraGuildModel): class Moderation(AuroraGuildModel):
@ -66,8 +66,7 @@ class Moderation(AuroraGuildModel):
async def get_target(self) -> Union["PartialUser", "PartialChannel"]: async def get_target(self) -> Union["PartialUser", "PartialChannel"]:
if self.target_type == "USER": if self.target_type == "USER":
return await PartialUser.from_id(self.bot, self.target_id) return await PartialUser.from_id(self.bot, self.target_id)
else: return await PartialChannel.from_id(self.bot, self.target_id)
return await PartialChannel.from_id(self.bot, self.target_id)
async def get_resolved_by(self) -> Optional["PartialUser"]: async def get_resolved_by(self) -> Optional["PartialUser"]:
if self.resolved_by: if self.resolved_by:
@ -264,10 +263,7 @@ class Moderation(AuroraGuildModel):
end_timestamp = None end_timestamp = None
if not expired: if not expired:
if timestamp > end_timestamp: expired = bool(timestamp > end_timestamp)
expired = True
else:
expired = False
if reason == "NULL": if reason == "NULL":
reason = None reason = None
@ -422,7 +418,7 @@ class PartialChannel(AuroraGuildModel):
@property @property
def mention(self): def mention(self):
if self.name == "Deleted Channel" or self.name == "Forbidden Channel": if self.name in ["Deleted Channel", "Forbidden Channel"]:
return self.name return self.name
return f"<#{self.id}>" return f"<#{self.id}>"
@ -448,7 +444,7 @@ class PartialRole(AuroraGuildModel):
@property @property
def mention(self): def mention(self):
if self.name == "Deleted Role" or self.name == "Forbidden Role": if self.name in ["Deleted Role", "Forbidden Role"]:
return self.name return self.name
return f"<@&{self.id}>" return f"<@&{self.id}>"

View file

@ -2,16 +2,13 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Union from typing import Union
from discord import (Color, Embed, Guild, Interaction, InteractionMessage, from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User
Member, Role, User)
from redbot.core import commands from redbot.core import commands
from redbot.core.utils.chat_formatting import (bold, box, error, from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning
humanize_timedelta, warning)
from aurora.models import Moderation, PartialUser from aurora.models import Moderation, PartialUser
from aurora.utilities.config import config from aurora.utilities.config import config
from aurora.utilities.utils import (get_bool_emoji, get_next_case_number, from aurora.utilities.utils import get_bool_emoji, get_next_case_number, get_pagesize_str
get_pagesize_str)
async def message_factory( async def message_factory(
@ -261,7 +258,7 @@ async def changes_factory(interaction: Interaction, moderation: Moderation) -> E
return embed return embed
async def evidenceformat_factory(interaction: Interaction, moderation: Moderation) -> str: async def evidenceformat_factory(moderation: Moderation) -> str:
"""This function creates a codeblock in evidence format from set parameters. """This function creates a codeblock in evidence format from set parameters.
Args: Args:

View file

@ -3,7 +3,6 @@ from datetime import datetime, timedelta
from redbot.core.bot import Red from redbot.core.bot import Red
from aurora.models import AuroraBaseModel from aurora.models import AuroraBaseModel

View file

@ -133,7 +133,7 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal
logging_channel = interaction.guild.get_channel(logging_channel_id) logging_channel = interaction.guild.get_channel(logging_channel_id)
try: try:
moderation = Moderation.from_sql(interaction.client, moderation_id) moderation = Moderation.from_sql(interaction.client, moderation_id, interaction.guild_id)
embed = await log_factory( embed = await log_factory(
interaction=interaction, moderation=moderation, resolved=resolved interaction=interaction, moderation=moderation, resolved=resolved
) )
@ -158,8 +158,8 @@ async def send_evidenceformat(interaction: Interaction, moderation_id: int) -> N
if send_evidence_bool is False: if send_evidence_bool is False:
return return
moderation = Moderation.from_sql(interaction.client, moderation_id) moderation = Moderation.from_sql(interaction.client, moderation_id, interaction.guild.id)
content = await evidenceformat_factory(interaction=interaction, moderation=moderation) content = await evidenceformat_factory(moderation=moderation)
await interaction.followup.send(content=content, ephemeral=True) await interaction.followup.send(content=content, ephemeral=True)