From c3767d919b7f5d34103abe0da3e4673ba0ef5f8a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 18 Dec 2023 17:41:58 -0500 Subject: [PATCH] feat(moderation): added evidenceformat --- moderation/moderation.py | 10 ++++++++-- moderation/utilities/embed_factory.py | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 2775064..d750a07 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -773,7 +773,7 @@ class Moderation(commands.Cog): Choice(name='Export as File', value='file'), Choice(name='Export as Codeblock', value='codeblock') ]) - async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, changes: bool = False, export: Choice[str] = None): + async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, evidenceformat: bool = False, changes: bool = False, export: Choice[str] = None): """Check the details of a specific case. Parameters @@ -799,6 +799,8 @@ class Moderation(commands.Cog): if case != 0: case_dict = await fetch_case(case, interaction.guild.id) if case_dict: + if evidenceformat: + await interaction.response.edit_message(content=f"```Case #{case_dict['moderation_id']:,} ({str.title(case_dict['moderation_type'])})\nTarget: ```", ephemeral=ephemeral) if export: if export.value == 'file' or len(str(case_dict)) > 1800: filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case}.json" @@ -819,9 +821,13 @@ class Moderation(commands.Cog): return if changes: embed = await embed_factory('changes', await self.bot.get_embed_color(None), interaction=interaction, case_dict=case_dict) + await interaction.response.send_message(embed=embed, ephemeral=ephemeral) + elif evidenceformat: + content = await embed_factory('evidenceformat', await self.bot.get_embed_color(None), interaction=interaction, case_dict=case_dict) + await interaction.response.send_message(content=content, ephemeral=ephemeral) else: embed = await embed_factory('case', await self.bot.get_embed_color(None), interaction=interaction, case_dict=case_dict) - await interaction.response.send_message(embed=embed, ephemeral=ephemeral) + await interaction.response.send_message(embed=embed, ephemeral=ephemeral) return await interaction.response.send_message(content=f"No case with case number `{case}` found.", ephemeral=True) diff --git a/moderation/utilities/embed_factory.py b/moderation/utilities/embed_factory.py index b05c4d3..f22c14f 100644 --- a/moderation/utilities/embed_factory.py +++ b/moderation/utilities/embed_factory.py @@ -29,7 +29,7 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact - case_dict - resolved (optional) - Required arguments for 'case' & 'changes': + Required arguments for 'case', 'changes', and `evidenceformat`: - interaction - case_dict""" if embed_type == 'message': @@ -122,6 +122,24 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact return embed + if embed_type == 'evidenceformat': + if case_dict['target_type'] == 'USER': + target_user = await fetch_user_dict(interaction, case_dict['target_id']) + target_name = {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_name = target_user['name'] + + content = f"```Case #{case_dict['moderation_id']:,} ({str.title(case_dict['moderation_type'])})\n\nTarget: {target_name} ({target_user['id']})\nModerator: {moderator_name} ({moderator_user['id']})" + + if case_dict['duration'] != 'NULL': + content += f"**Duration:** {humanize.precisedelta(td)}" + + content += f"\nReason: {case_dict['reason']}```" + + return content + if embed_type == 'log': if resolved: if case_dict['target_type'] == 'USER':