misc(moderation): added a seperate method for retrieving a user's information, instead of doing it twice in embed_factory
All checks were successful
Pylint / Pylint (push) Successful in 1m12s

This commit is contained in:
Seaswimmer 2023-10-06 09:45:32 -04:00
parent 2fb7fd2d0c
commit bd17b6e88a
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -209,6 +209,23 @@ class Moderation(commands.Cog):
cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1")
return cursor.fetchone()[0] + 1
async def fetch_user_dict(self, interaction: discord.Interaction, user_id: str):
"""This method returns a dictionary containing either user information or a standard deleted user template."""
try:
user = await interaction.client.fetch_user(user_id)
user_dict = {
'id': user.id,
'name': user.name,
'discriminator': user.discriminator
}
except discord.errors.NotFound:
user_dict = {
'id': user_id,
'name': 'Deleted User',
'discriminator': '0'
}
return user_dict
async def embed_factory(self, embed_type: str, /, interaction: discord.Interaction = None, case_dict: dict = None, guild: discord.Guild = None, reason: str = None, moderation_type: str = None, response: discord.InteractionMessage = None, duration: timedelta = None):
"""This method creates an embed from set parameters, meant for either moderation logging or contacting the moderated user.
@ -245,35 +262,10 @@ class Moderation(commands.Cog):
embed.set_author(name=guild.name, icon_url=guild.icon.url)
embed.set_footer(text=f"Case #{await self.get_next_case_number(guild.id)}", icon_url="https://cdn.discordapp.com/attachments/1070822161389994054/1159469476773904414/arrow-right-circle-icon-512x512-2p1e2aaw.png?ex=65312319&is=651eae19&hm=3cebdd28e805c13a79ec48ef87c32ca532ffa6b9ede2e48d0cf8e5e81f3a6818&")
return embed
if embed_type == 'case':
try:
target = await interaction.client.fetch_user(case_dict["target_id"])
target_user = {
'id': target.id,
'name': target.name,
'discriminator': target.discriminator
}
except discord.errors.NotFound:
target = discord.User(id=case_dict["target_id"], name="Deleted User", discriminator="0") # pylint: disable=unexpected-keyword-arg, missing-kwoa
target_user = {
'id': case_dict['target_id'],
'name': 'Deleted User',
'discriminator': '0'
}
try:
moderator = await interaction.client.fetch_user(case_dict["moderator_id"])
moderator_user = {
'id': moderator.id,
'name': moderator.name,
'discriminator': moderator.discriminator
}
except discord.errors.NotFound:
moderator = discord.User(id=case_dict["moderator_id"], name="Deleted User", discriminator="0") # pylint: disable=unexpected-keyword-arg, missing-kwoa
moderator_user = {
'id': case_dict['moderator_id'],
'name': 'Deleted User',
'discriminator': '0'
}
target_user = await self.fetch_user_dict(interaction, case_dict['target_id'])
moderator_user = await self.fetch_user_dict(interaction, case_dict['moderator_id'])
target_name = target_user['name'] if target_user['discriminator'] == "0" else f"{target_user['name']}#{target_user['discriminator']}"
moderator_name = moderator_user['name'] if moderator_user['discriminator'] == "0" else f"{moderator_user['name']}#{moderator_user['discriminator']}"
embed = discord.Embed(title=f"📕 Case #{case_dict['moderation_id']}", color=await self.bot.get_embed_color(None))
@ -286,6 +278,7 @@ class Moderation(commands.Cog):
if case_dict['resolved'] == 1:
embed.add_field(name='Resolve Reason', value=f"```{case_dict['resolve_reason']}```", inline=False)
return embed
raise(TypeError("'type' argument is invalid!"))
@app_commands.command(name="note")