feat(aurora): finishing up moderation handlers
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Failing after 28s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 46s

This commit is contained in:
Seaswimmer 2024-07-12 15:22:24 -04:00
parent 9d0f2e3887
commit e2b0fc999a
Signed by: cswimr
GPG key ID: 3813315477F26F82
9 changed files with 995 additions and 720 deletions

View file

@ -24,6 +24,7 @@ async def message_factory(
duration: timedelta | None = None,
response: Message | None = None,
role: Role | None = None,
case: bool = True,
) -> Embed:
"""This function creates a message from set parameters, meant for contacting the moderated user.
@ -37,6 +38,7 @@ async def message_factory(
duration (timedelta, optional): The duration of the moderation. Defaults to None.
response (Message, optional): The response message. Defaults to None.
role (Role, optional): The role that was added or removed. Defaults to None.
case (bool, optional): Whether the message is for a moderation case. Defaults to True.
Returns:
@ -57,22 +59,9 @@ async def message_factory(
else:
embed_duration = ""
# if moderation_type.type == "note":
# embed_desc = "received a"
# elif moderation_type.type == "addrole":
# embed_desc = f"received the {role.name} role"
# title = "Role Added"
# verb = ""
# elif moderation_type.type == "removerole":
# embed_desc = f"lost the {role.name} role"
# title = "Role Removed"
# verb = ""
# else:
# embed_desc = "been"
embed = Embed(
title=str.title(moderation_type.verb),
description=f"You have {moderation_type.embed_desc} {moderation_type.verb}{embed_duration} in {guild_name}.",
description=f"You have {moderation_type.embed_desc}{moderation_type.verb}{embed_duration} in {guild_name}.",
color=color,
timestamp=datetime.now(),
)
@ -89,14 +78,43 @@ async def message_factory(
else:
embed.set_author(name=guild.name)
if case:
embed.set_footer(
text=f"Case #{await Moderation.get_next_case_number(bot=bot, guild_id=guild.id):,}",
icon_url="attachment://arrow.png",
)
return embed
async def resolve_factory(moderation: Moderation, reason: str) -> Embed:
"""This function creates a resolved embed from set parameters, meant for contacting the moderated user.
Args:
moderation (aurora.models.Moderation): The moderation object.
reason (str): The reason for resolving the moderation.
Returns: `discord.Embed`
"""
embed = Embed(
title=str.title(moderation.type.name) + " Resolved",
description=f"Your {moderation.type.name} in {moderation.guild.name} has been resolved.",
color=await moderation.bot.get_embed_color(moderation.guild.channels[0]),
timestamp=datetime.now(),
)
embed.add_field(name="Reason", value=f"`{reason}`", inline=False)
if moderation.guild.icon.url is not None:
embed.set_author(name=moderation.guild.name, icon_url=moderation.guild.icon.url)
else:
embed.set_author(name=moderation.guild.name)
embed.set_footer(
text=f"Case #{await Moderation.get_next_case_number(bot=bot, guild_id=guild.id):,}",
text=f"Case #{moderation.id:,}",
icon_url="attachment://arrow.png",
)
return embed
async def log_factory(
ctx: commands.Context, moderation: Moderation, resolved: bool = False
) -> Embed:

View file

@ -3,9 +3,8 @@ from typing import List, Union
import discord
from redbot.core import app_commands, commands
from ..models.moderation_types import Type
from ..models.type import Type, type_registry
from .config import config
from .registry import type_registry
from .utils import check_moddable

View file

@ -1,3 +0,0 @@
from class_registry import ClassRegistry
type_registry = ClassRegistry()