WIP: Make Aurora commands hybrid commands #17

Closed
cswimr wants to merge 11 commits from aurora-hybrid into main
Showing only changes of commit cfa95118ae - Show all commits

View file

@ -2,14 +2,13 @@ from datetime import datetime, timedelta
from typing import Union from typing import Union
import humanize 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 import commands
from redbot.core.utils.chat_formatting import bold, box, error, warning from redbot.core.utils.chat_formatting import bold, box, error, warning
from aurora.utilities.config import config 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 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( async def message_factory(
color: Color, color: Color,
guild: Guild, guild: Guild,
@ -17,7 +16,7 @@ async def message_factory(
moderation_type: str, moderation_type: str,
moderator: Union[Member, User] = None, moderator: Union[Member, User] = None,
duration: timedelta = None, duration: timedelta = None,
response: InteractionMessage = None, response: Message = None,
role: Role = None, role: Role = None,
) -> Embed: ) -> Embed:
"""This function creates a message from set parameters, meant for contacting the moderated user. """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. moderation_type (str): The type of moderation.
moderator (Union[Member, User], optional): The moderator who performed the moderation. Defaults to None. 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. 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. role (Role, optional): The role that was added or removed. Defaults to None.
Returns: Returns:
embed: The message embed. embed: The message embed.
""" """
@ -207,28 +205,28 @@ async def log_factory(
return embed 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. """This function creates a case embed from set parameters.
Args: Args:
interaction (Interaction): The interaction object. ctx (commands.Context): The context object.
case_dict (dict): The case dictionary. case_dict (dict): The case dictionary.
""" """
if case_dict["target_type"] == "USER": 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 = ( target_name = (
f"`{target_user['name']}`" f"`{target_user['name']}`"
if target_user["discriminator"] == "0" if target_user["discriminator"] == "0"
else f"`{target_user['name']}#{target_user['discriminator']}`" else f"`{target_user['name']}#{target_user['discriminator']}`"
) )
elif case_dict["target_type"] == "CHANNEL": 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"]: if target_user["mention"]:
target_name = f"{target_user['mention']}" target_name = f"{target_user['mention']}"
else: else:
target_name = f"`{target_user['name']}`" 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 = ( moderator_name = (
f"`{moderator_user['name']}`" f"`{moderator_user['name']}`"
if moderator_user["discriminator"] == "0" if moderator_user["discriminator"] == "0"
@ -237,7 +235,7 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
embed = Embed( embed = Embed(
title=f"📕 Case #{case_dict['moderation_id']:,}", 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>" 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) embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
if case_dict["resolved"] == 1: 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 = ( resolved_name = (
f"`{resolved_user['name']}`" f"`{resolved_user['name']}`"
if resolved_user["discriminator"] == "0" if resolved_user["discriminator"] == "0"
@ -287,16 +285,16 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
return 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. """This function creates a changes embed from set parameters.
Args: Args:
interaction (Interaction): The interaction object. ctx (commands.Context): The context object.
case_dict (dict): The case dictionary. case_dict (dict): The case dictionary.
""" """
embed = Embed( embed = Embed(
title=f"📕 Case #{case_dict['moderation_id']:,} Changes", 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 = {} memory_dict = {}
@ -305,7 +303,7 @@ async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed:
for change in case_dict["changes"]: for change in case_dict["changes"]:
if change["user_id"] not in memory_dict: if change["user_id"] not in memory_dict:
memory_dict[str(change["user_id"])] = await fetch_user_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"])] user = memory_dict[str(change["user_id"])]