forked from blizzthewolf/SeaCogs
feat(aurora): updated all of the utils functions (and connected factory functions) to work with hybrid commands (UNTESTED)
This commit is contained in:
parent
57c7bce6cd
commit
67d7e04956
2 changed files with 38 additions and 38 deletions
|
@ -88,7 +88,7 @@ async def message_factory(
|
||||||
|
|
||||||
|
|
||||||
async def log_factory(
|
async def log_factory(
|
||||||
interaction: Interaction, case_dict: dict, resolved: bool = False
|
ctx: commands.Context, case_dict: dict, resolved: bool = False
|
||||||
) -> Embed:
|
) -> Embed:
|
||||||
"""This function creates a log embed from set parameters, meant for moderation logging.
|
"""This function creates a log embed from set parameters, meant for moderation logging.
|
||||||
|
|
||||||
|
@ -99,20 +99,20 @@ async def log_factory(
|
||||||
"""
|
"""
|
||||||
if resolved:
|
if resolved:
|
||||||
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"
|
||||||
|
@ -121,7 +121,7 @@ async def log_factory(
|
||||||
|
|
||||||
embed = Embed(
|
embed = Embed(
|
||||||
title=f"📕 Case #{case_dict['moderation_id']:,} Resolved",
|
title=f"📕 Case #{case_dict['moderation_id']:,} Resolved",
|
||||||
color=await interaction.client.get_embed_color(interaction.channel),
|
color=await ctx.client.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**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**Timestamp:** <t:{case_dict['timestamp']}> | <t:{case_dict['timestamp']}:R>"
|
||||||
|
@ -148,7 +148,7 @@ async def log_factory(
|
||||||
|
|
||||||
embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
|
embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
|
||||||
|
|
||||||
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 = (
|
||||||
resolved_user["name"]
|
resolved_user["name"]
|
||||||
if resolved_user["discriminator"] == "0"
|
if resolved_user["discriminator"] == "0"
|
||||||
|
@ -162,20 +162,20 @@ async def log_factory(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
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 = target_user["mention"]
|
target_name = 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"
|
||||||
|
@ -184,7 +184,7 @@ async def log_factory(
|
||||||
|
|
||||||
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**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**Timestamp:** <t:{case_dict['timestamp']}> | <t:{case_dict['timestamp']}:R>"
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> str:
|
async def evidenceformat_factory(ctx: commands.Context, case_dict: dict) -> 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:
|
||||||
|
@ -352,7 +352,7 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
|
||||||
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 = (
|
||||||
target_user["name"]
|
target_user["name"]
|
||||||
if target_user["discriminator"] == "0"
|
if target_user["discriminator"] == "0"
|
||||||
|
@ -360,10 +360,10 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
|
||||||
)
|
)
|
||||||
|
|
||||||
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"])
|
||||||
target_name = target_user["name"]
|
target_name = 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 = (
|
||||||
moderator_user["name"]
|
moderator_user["name"]
|
||||||
if moderator_user["discriminator"] == "0"
|
if moderator_user["discriminator"] == "0"
|
||||||
|
|
|
@ -39,11 +39,11 @@ def check_permissions(
|
||||||
|
|
||||||
|
|
||||||
async def check_moddable(
|
async def check_moddable(
|
||||||
target: Union[User, Member], interaction: Interaction, permissions: list
|
target: Union[User, Member], ctx: Union[commands.Context, Interaction], permissions: list
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Checks if a moderator can moderate a target."""
|
"""Checks if a moderator can moderate a target."""
|
||||||
if check_permissions(interaction.client.user, permissions, guild=interaction.guild):
|
if check_permissions(ctx.bot.user, permissions, guild=ctx.guild):
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
error(
|
error(
|
||||||
f"I do not have the `{permissions}` permission, required for this action."
|
f"I do not have the `{permissions}` permission, required for this action."
|
||||||
),
|
),
|
||||||
|
@ -51,9 +51,9 @@ async def check_moddable(
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if await config.guild(interaction.guild).use_discord_permissions() is True:
|
if await config.guild(ctx.guild).use_discord_permissions() is True:
|
||||||
if check_permissions(interaction.user, permissions, guild=interaction.guild):
|
if check_permissions(ctx.author, permissions, guild=ctx.guild):
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
error(
|
error(
|
||||||
f"You do not have the `{permissions}` permission, required for this action."
|
f"You do not have the `{permissions}` permission, required for this action."
|
||||||
),
|
),
|
||||||
|
@ -61,21 +61,21 @@ async def check_moddable(
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if interaction.user.id == target.id:
|
if ctx.author.id == target.id:
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
content="You cannot moderate yourself!", ephemeral=True
|
content="You cannot moderate yourself!", ephemeral=True
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if target.bot:
|
if target.bot:
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
content="You cannot moderate bots!", ephemeral=True
|
content="You cannot moderate bots!", ephemeral=True
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if isinstance(target, Member):
|
if isinstance(target, Member):
|
||||||
if interaction.user.top_role <= target.top_role:
|
if ctx.author.top_role <= target.top_role:
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
content=error(
|
content=error(
|
||||||
"You cannot moderate members with a higher role than you!"
|
"You cannot moderate members with a higher role than you!"
|
||||||
),
|
),
|
||||||
|
@ -84,10 +84,10 @@ async def check_moddable(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (
|
if (
|
||||||
interaction.guild.get_member(interaction.client.user.id).top_role
|
ctx.guild.get_member(ctx.bot.user.id).top_role
|
||||||
<= target.top_role
|
<= target.top_role
|
||||||
):
|
):
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
content=error(
|
content=error(
|
||||||
"You cannot moderate members with a role higher than the bot!"
|
"You cannot moderate members with a role higher than the bot!"
|
||||||
),
|
),
|
||||||
|
@ -99,7 +99,7 @@ async def check_moddable(
|
||||||
|
|
||||||
for role in target.roles:
|
for role in target.roles:
|
||||||
if role.id in immune_roles:
|
if role.id in immune_roles:
|
||||||
await interaction.response.send_message(
|
await ctx.send(
|
||||||
content=error("You cannot moderate members with an immune role!"),
|
content=error("You cannot moderate members with an immune role!"),
|
||||||
ephemeral=True,
|
ephemeral=True,
|
||||||
)
|
)
|
||||||
|
@ -202,19 +202,19 @@ async def fetch_role_dict(guild: Guild, role_id: int) -> dict:
|
||||||
return role_dict
|
return role_dict
|
||||||
|
|
||||||
|
|
||||||
async def log(interaction: Interaction, moderation_id: int, resolved: bool = False) -> None:
|
async def log(ctx: Union[commands.Context, Interaction], moderation_id: int, resolved: bool = False) -> None:
|
||||||
"""This function sends a message to the guild's configured logging channel when an infraction takes place."""
|
"""This function sends a message to the guild's configured logging channel when an infraction takes place."""
|
||||||
from .database import fetch_case
|
from .database import fetch_case
|
||||||
from .factory import log_factory
|
from .factory import log_factory
|
||||||
|
|
||||||
logging_channel_id = await config.guild(interaction.guild).log_channel()
|
logging_channel_id = await config.guild(ctx.guild).log_channel()
|
||||||
if logging_channel_id != " ":
|
if logging_channel_id != " ":
|
||||||
logging_channel = interaction.guild.get_channel(logging_channel_id)
|
logging_channel = ctx.guild.get_channel(logging_channel_id)
|
||||||
|
|
||||||
case = await fetch_case(moderation_id, interaction.guild.id)
|
case = await fetch_case(moderation_id, ctx.guild.id)
|
||||||
if case:
|
if case:
|
||||||
embed = await log_factory(
|
embed = await log_factory(
|
||||||
interaction=interaction, case_dict=case, resolved=resolved
|
ctx=ctx, case_dict=case, resolved=resolved
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await logging_channel.send(embed=embed)
|
await logging_channel.send(embed=embed)
|
||||||
|
@ -222,20 +222,20 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def send_evidenceformat(interaction: Interaction, case_dict: dict) -> None:
|
async def send_evidenceformat(ctx: commands.Context, case_dict: dict) -> None:
|
||||||
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
|
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
|
||||||
from .factory import evidenceformat_factory
|
from .factory import evidenceformat_factory
|
||||||
|
|
||||||
send_evidence_bool = (
|
send_evidence_bool = (
|
||||||
await config.user(interaction.user).auto_evidenceformat()
|
await config.user(ctx.author).auto_evidenceformat()
|
||||||
or await config.guild(interaction.guild).auto_evidenceformat()
|
or await config.guild(ctx.guild).auto_evidenceformat()
|
||||||
or False
|
or False
|
||||||
)
|
)
|
||||||
if send_evidence_bool is False:
|
if send_evidence_bool is False:
|
||||||
return
|
return
|
||||||
|
|
||||||
content = await evidenceformat_factory(interaction=interaction, case_dict=case_dict)
|
content = await evidenceformat_factory(ctx=ctx, case_dict=case_dict)
|
||||||
await interaction.followup.send(content=content, ephemeral=True)
|
await ctx.send(content=content, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
def convert_timedelta_to_str(timedelta: td) -> str:
|
def convert_timedelta_to_str(timedelta: td) -> str:
|
||||||
|
|
Loading…
Reference in a new issue