misc(aurora): less restrictive type requirements for some utils functions

This commit is contained in:
Seaswimmer 2024-02-13 23:18:44 +00:00
parent db7c06b044
commit f7d2f1a564
Signed by: cswimr
GPG key ID: AB39CBC5A4135AB8
3 changed files with 26 additions and 26 deletions

View file

@ -1023,11 +1023,11 @@ class Aurora(commands.Cog):
if case["target_id"] not in memory_dict:
if case["target_type"] == "USER":
memory_dict[str(case["target_id"])] = await fetch_user_dict(
interaction, case["target_id"]
interaction.client, case["target_id"]
)
elif case["target_type"] == "CHANNEL":
memory_dict[str(case["target_id"])] = await fetch_channel_dict(
interaction, case["target_id"]
interaction.guild, case["target_id"]
)
target_user = memory_dict[str(case["target_id"])]
@ -1042,7 +1042,7 @@ class Aurora(commands.Cog):
if case["moderator_id"] not in memory_dict:
memory_dict[str(case["moderator_id"])] = await fetch_user_dict(
interaction, case["moderator_id"]
interaction.client, case["moderator_id"]
)
moderator_user = memory_dict[str(case["moderator_id"])]
moderator_name = (

View file

@ -116,20 +116,20 @@ async def log_factory(
"""
if resolved:
if case_dict["target_type"] == "USER":
target_user = await fetch_user_dict(interaction, case_dict["target_id"])
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
target_user = await fetch_channel_dict(interaction.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, case_dict["moderator_id"])
moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"])
moderator_name = (
f"`{moderator_user['name']}`"
if moderator_user["discriminator"] == "0"
@ -165,7 +165,7 @@ async def log_factory(
embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
resolved_user = await fetch_user_dict(interaction, case_dict["resolved_by"])
resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"])
resolved_name = (
resolved_user["name"]
if resolved_user["discriminator"] == "0"
@ -179,20 +179,20 @@ async def log_factory(
)
else:
if case_dict["target_type"] == "USER":
target_user = await fetch_user_dict(interaction, case_dict["target_id"])
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"])
if target_user["mention"]:
target_name = target_user["mention"]
else:
target_name = f"`{target_user['name']}`"
moderator_user = await fetch_user_dict(interaction, case_dict["moderator_id"])
moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"])
moderator_name = (
f"`{moderator_user['name']}`"
if moderator_user["discriminator"] == "0"
@ -232,20 +232,20 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
case_dict (dict): The case dictionary.
"""
if case_dict["target_type"] == "USER":
target_user = await fetch_user_dict(interaction, case_dict["target_id"])
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
target_user = await fetch_channel_dict(interaction.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, case_dict["moderator_id"])
moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"])
moderator_name = (
f"`{moderator_user['name']}`"
if moderator_user["discriminator"] == "0"
@ -289,7 +289,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, case_dict["resolved_by"])
resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"])
resolved_name = (
f"`{resolved_user['name']}`"
if resolved_user["discriminator"] == "0"
@ -322,7 +322,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, change["user_id"]
interaction.client, change["user_id"]
)
user = memory_dict[str(change["user_id"])]
@ -369,7 +369,7 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
case_dict (dict): The case dictionary.
"""
if case_dict["target_type"] == "USER":
target_user = await fetch_user_dict(interaction, case_dict["target_id"])
target_user = await fetch_user_dict(interaction.client, case_dict["target_id"])
target_name = (
target_user["name"]
if target_user["discriminator"] == "0"
@ -377,10 +377,10 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
)
elif case_dict["target_type"] == "CHANNEL":
target_user = await fetch_channel_dict(interaction, case_dict["target_id"])
target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"])
target_name = target_user["name"]
moderator_user = await fetch_user_dict(interaction, case_dict["moderator_id"])
moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"])
moderator_name = (
moderator_user["name"]
if moderator_user["discriminator"] == "0"

View file

@ -146,16 +146,16 @@ def generate_dict(result) -> dict:
return case
async def fetch_user_dict(interaction: Interaction, user_id: str) -> dict:
async def fetch_user_dict(client: commands.Bot, user_id: str) -> dict:
"""This function returns a dictionary containing either user information or a standard deleted user template."""
if user_id == "?":
user_dict = {"id": "?", "name": "Unknown User", "discriminator": "0"}
else:
try:
user = interaction.client.get_user(user_id)
user = client.get_user(int(user_id))
if user is None:
user = await interaction.client.fetch_user(user_id)
user_dict = {"id": user_id, "name": "Unknown User", "discriminator": "0"}
user_dict = {
"id": user.id,
@ -173,12 +173,12 @@ async def fetch_user_dict(interaction: Interaction, user_id: str) -> dict:
return user_dict
async def fetch_channel_dict(interaction: Interaction, channel_id: str) -> dict:
async def fetch_channel_dict(guild: Guild, channel_id: str) -> dict:
"""This function returns a dictionary containing either channel information or a standard deleted channel template."""
try:
channel = interaction.guild.get_channel(channel_id)
channel = guild.get_channel(channel_id)
if not channel:
channel = await interaction.guild.fetch_channel(channel_id)
channel = await guild.fetch_channel(channel_id)
channel_dict = {
"id": channel.id,
@ -192,9 +192,9 @@ async def fetch_channel_dict(interaction: Interaction, channel_id: str) -> dict:
return channel_dict
async def fetch_role_dict(interaction: Interaction, role_id: str) -> dict:
async def fetch_role_dict(guild: Guild, role_id: str) -> dict:
"""This function returns a dictionary containing either role information or a standard deleted role template."""
role = interaction.guild.get_role(role_id)
role = guild.get_role(role_id)
if not role:
role_dict = {"id": role_id, "name": "Deleted Role"}