misc(aurora): less restrictive type requirements for some utils functions
This commit is contained in:
parent
db7c06b044
commit
f7d2f1a564
3 changed files with 26 additions and 26 deletions
|
@ -1023,11 +1023,11 @@ class Aurora(commands.Cog):
|
||||||
if case["target_id"] not in memory_dict:
|
if case["target_id"] not in memory_dict:
|
||||||
if case["target_type"] == "USER":
|
if case["target_type"] == "USER":
|
||||||
memory_dict[str(case["target_id"])] = await fetch_user_dict(
|
memory_dict[str(case["target_id"])] = await fetch_user_dict(
|
||||||
interaction, case["target_id"]
|
interaction.client, case["target_id"]
|
||||||
)
|
)
|
||||||
elif case["target_type"] == "CHANNEL":
|
elif case["target_type"] == "CHANNEL":
|
||||||
memory_dict[str(case["target_id"])] = await fetch_channel_dict(
|
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"])]
|
target_user = memory_dict[str(case["target_id"])]
|
||||||
|
|
||||||
|
@ -1042,7 +1042,7 @@ class Aurora(commands.Cog):
|
||||||
|
|
||||||
if case["moderator_id"] not in memory_dict:
|
if case["moderator_id"] not in memory_dict:
|
||||||
memory_dict[str(case["moderator_id"])] = await fetch_user_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_user = memory_dict[str(case["moderator_id"])]
|
||||||
moderator_name = (
|
moderator_name = (
|
||||||
|
|
|
@ -116,20 +116,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, case_dict["target_id"])
|
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
|
target_user = await fetch_channel_dict(interaction.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, case_dict["moderator_id"])
|
moderator_user = await fetch_user_dict(interaction.client, 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"
|
||||||
|
@ -165,7 +165,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, case_dict["resolved_by"])
|
resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"])
|
||||||
resolved_name = (
|
resolved_name = (
|
||||||
resolved_user["name"]
|
resolved_user["name"]
|
||||||
if resolved_user["discriminator"] == "0"
|
if resolved_user["discriminator"] == "0"
|
||||||
|
@ -179,20 +179,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, case_dict["target_id"])
|
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
|
target_user = await fetch_channel_dict(interaction.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, case_dict["moderator_id"])
|
moderator_user = await fetch_user_dict(interaction.client, 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"
|
||||||
|
@ -232,20 +232,20 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
||||||
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, case_dict["target_id"])
|
target_user = await fetch_user_dict(interaction.client, 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, case_dict["target_id"])
|
target_user = await fetch_channel_dict(interaction.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, case_dict["moderator_id"])
|
moderator_user = await fetch_user_dict(interaction.client, 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"
|
||||||
|
@ -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)
|
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, case_dict["resolved_by"])
|
resolved_user = await fetch_user_dict(interaction.client, 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"
|
||||||
|
@ -322,7 +322,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, change["user_id"]
|
interaction.client, change["user_id"]
|
||||||
)
|
)
|
||||||
|
|
||||||
user = memory_dict[str(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.
|
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, case_dict["target_id"])
|
target_user = await fetch_user_dict(interaction.client, case_dict["target_id"])
|
||||||
target_name = (
|
target_name = (
|
||||||
target_user["name"]
|
target_user["name"]
|
||||||
if target_user["discriminator"] == "0"
|
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":
|
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"]
|
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_name = (
|
||||||
moderator_user["name"]
|
moderator_user["name"]
|
||||||
if moderator_user["discriminator"] == "0"
|
if moderator_user["discriminator"] == "0"
|
||||||
|
|
|
@ -146,16 +146,16 @@ def generate_dict(result) -> dict:
|
||||||
return case
|
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."""
|
"""This function returns a dictionary containing either user information or a standard deleted user template."""
|
||||||
if user_id == "?":
|
if user_id == "?":
|
||||||
user_dict = {"id": "?", "name": "Unknown User", "discriminator": "0"}
|
user_dict = {"id": "?", "name": "Unknown User", "discriminator": "0"}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
user = interaction.client.get_user(user_id)
|
user = client.get_user(int(user_id))
|
||||||
if user is None:
|
if user is None:
|
||||||
user = await interaction.client.fetch_user(user_id)
|
user_dict = {"id": user_id, "name": "Unknown User", "discriminator": "0"}
|
||||||
|
|
||||||
user_dict = {
|
user_dict = {
|
||||||
"id": user.id,
|
"id": user.id,
|
||||||
|
@ -173,12 +173,12 @@ async def fetch_user_dict(interaction: Interaction, user_id: str) -> dict:
|
||||||
return user_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."""
|
"""This function returns a dictionary containing either channel information or a standard deleted channel template."""
|
||||||
try:
|
try:
|
||||||
channel = interaction.guild.get_channel(channel_id)
|
channel = guild.get_channel(channel_id)
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = await interaction.guild.fetch_channel(channel_id)
|
channel = await guild.fetch_channel(channel_id)
|
||||||
|
|
||||||
channel_dict = {
|
channel_dict = {
|
||||||
"id": channel.id,
|
"id": channel.id,
|
||||||
|
@ -192,9 +192,9 @@ async def fetch_channel_dict(interaction: Interaction, channel_id: str) -> dict:
|
||||||
return channel_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."""
|
"""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:
|
if not role:
|
||||||
role_dict = {"id": role_id, "name": "Deleted Role"}
|
role_dict = {"id": role_id, "name": "Deleted Role"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue