forked from cswimr/SeaCogs
feat(aurora): factory functions now support hybrid commands (in theory, UNTESTED)
This commit is contained in:
parent
67d7e04956
commit
cfa95118ae
1 changed files with 14 additions and 16 deletions
|
@ -2,14 +2,13 @@ from datetime import datetime, timedelta
|
|||
from typing import Union
|
||||
|
||||
import humanize
|
||||
from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User
|
||||
from discord import Color, Embed, Guild, Member, Message, Role, User
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, warning
|
||||
|
||||
from aurora.utilities.config import config
|
||||
from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str
|
||||
|
||||
|
||||
async def message_factory(
|
||||
color: Color,
|
||||
guild: Guild,
|
||||
|
@ -17,7 +16,7 @@ async def message_factory(
|
|||
moderation_type: str,
|
||||
moderator: Union[Member, User] = None,
|
||||
duration: timedelta = None,
|
||||
response: InteractionMessage = None,
|
||||
response: Message = None,
|
||||
role: Role = None,
|
||||
) -> Embed:
|
||||
"""This function creates a message from set parameters, meant for contacting the moderated user.
|
||||
|
@ -29,10 +28,9 @@ async def message_factory(
|
|||
moderation_type (str): The type of moderation.
|
||||
moderator (Union[Member, User], optional): The moderator who performed the moderation. Defaults to None.
|
||||
duration (timedelta, optional): The duration of the moderation. Defaults to None.
|
||||
response (InteractionMessage, optional): The response message. 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.
|
||||
|
||||
|
||||
Returns:
|
||||
embed: The message embed.
|
||||
"""
|
||||
|
@ -207,28 +205,28 @@ async def log_factory(
|
|||
return embed
|
||||
|
||||
|
||||
async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
||||
async def case_factory(ctx: commands.Context, case_dict: dict) -> Embed:
|
||||
"""This function creates a case embed from set parameters.
|
||||
|
||||
Args:
|
||||
interaction (Interaction): The interaction object.
|
||||
ctx (commands.Context): The context object.
|
||||
case_dict (dict): The case dictionary.
|
||||
"""
|
||||
if case_dict["target_type"] == "USER":
|
||||
target_user = await fetch_user_dict(interaction.client, case_dict["target_id"])
|
||||
target_user = await fetch_user_dict(ctx.bot, case_dict["target_id"])
|
||||
target_name = (
|
||||
f"`{target_user['name']}`"
|
||||
if target_user["discriminator"] == "0"
|
||||
else f"`{target_user['name']}#{target_user['discriminator']}`"
|
||||
)
|
||||
elif case_dict["target_type"] == "CHANNEL":
|
||||
target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"])
|
||||
target_user = await fetch_channel_dict(ctx.guild, case_dict["target_id"])
|
||||
if target_user["mention"]:
|
||||
target_name = f"{target_user['mention']}"
|
||||
else:
|
||||
target_name = f"`{target_user['name']}`"
|
||||
|
||||
moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"])
|
||||
moderator_user = await fetch_user_dict(ctx.bot, case_dict["moderator_id"])
|
||||
moderator_name = (
|
||||
f"`{moderator_user['name']}`"
|
||||
if moderator_user["discriminator"] == "0"
|
||||
|
@ -237,7 +235,7 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
|
||||
embed = Embed(
|
||||
title=f"📕 Case #{case_dict['moderation_id']:,}",
|
||||
color=await interaction.client.get_embed_color(interaction.channel),
|
||||
color=await ctx.bot.get_embed_color(ctx.channel),
|
||||
)
|
||||
embed.description = f"**Type:** {str.title(case_dict['moderation_type'])}\n**Target:** {target_name} ({target_user['id']})\n**Moderator:** {moderator_name} ({moderator_user['id']})\n**Resolved:** {bool(case_dict['resolved'])}\n**Timestamp:** <t:{case_dict['timestamp']}> | <t:{case_dict['timestamp']}:R>"
|
||||
|
||||
|
@ -272,7 +270,7 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
|
||||
|
||||
if case_dict["resolved"] == 1:
|
||||
resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"])
|
||||
resolved_user = await fetch_user_dict(ctx.bot, case_dict["resolved_by"])
|
||||
resolved_name = (
|
||||
f"`{resolved_user['name']}`"
|
||||
if resolved_user["discriminator"] == "0"
|
||||
|
@ -287,16 +285,16 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
return embed
|
||||
|
||||
|
||||
async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
||||
async def changes_factory(ctx: commands.Context, case_dict: dict) -> Embed:
|
||||
"""This function creates a changes embed from set parameters.
|
||||
|
||||
Args:
|
||||
interaction (Interaction): The interaction object.
|
||||
ctx (commands.Context): The context object.
|
||||
case_dict (dict): The case dictionary.
|
||||
"""
|
||||
embed = Embed(
|
||||
title=f"📕 Case #{case_dict['moderation_id']:,} Changes",
|
||||
color=await interaction.client.get_embed_color(interaction.channel),
|
||||
color=await ctx.bot.get_embed_color(ctx.channel),
|
||||
)
|
||||
|
||||
memory_dict = {}
|
||||
|
@ -305,7 +303,7 @@ async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
for change in case_dict["changes"]:
|
||||
if change["user_id"] not in memory_dict:
|
||||
memory_dict[str(change["user_id"])] = await fetch_user_dict(
|
||||
interaction.client, change["user_id"]
|
||||
ctx.bot, change["user_id"]
|
||||
)
|
||||
|
||||
user = memory_dict[str(change["user_id"])]
|
||||
|
|
Loading…
Reference in a new issue