From c783f4032ab77a216f0cde72e06c632e211b40f2 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 5 Oct 2023 12:58:57 -0400 Subject: [PATCH] feat(moderation): added case command --- moderation/moderation.py | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index a010998..c8158eb 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -185,7 +185,7 @@ 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 embed_factory(self, embed_type: str, guild: discord.Guild, reason: str, moderation_type: str, response: discord.InteractionMessage, duration: timedelta = None): + async def embed_factory(self, embed_type: str, guild: discord.Guild, reason: str, moderation_type: str, 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. Valid arguments for 'embed_type': @@ -350,6 +350,53 @@ class Moderation(commands.Cog): pass await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason) + @app_commands.command(name="case") + async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False): + """Check the details of a specific case.""" + database = await self.connect() + cursor = database.cursor() + query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;" + cursor.execute(query, (interaction.guild.id, case_number)) + result = cursor.fetchone() + cursor.close() + database.close() + if result: + case = { + "moderation_id": result[0], + "timestamp": result[1], + "moderation_type": result[2], + "target_id": result[3], + "moderator_id": result[4], + "duration": result[5], + "end_timestamp": result[6], + "reason": result[7], + "resolved": result[8], + "resolve_reason": result[9], + "expired": result[10] + } + try: + target = interaction.client.get_user(case["target_id"]) + except discord.errors.NotFound: + target = discord.User(id=case["target_id"], name="Deleted User", discriminator="0") + try: + moderator = interaction.client.get_user(case["moderator_id"]) + except discord.errors.NotFound: + moderator = discord.User(id=case["moderator_id"], name="Deleted User", discriminator="0") + target_name = target.name if target.discriminator == "0" else f"{target.name}#{target.discriminator}" + moderator_name = moderator.name if moderator.discriminator == "0" else f"{moderator.name}#{moderator.discriminator}" + embed = discord.Embed(title=f"📕 Case #{case['moderation_id']} - {str.title(case['moderation_type'])}", color=await self.bot.get_embed_color(None)) + embed.description = f"**Target:** {target_name} ({target.id})\n**Moderator:** {moderator_name} ({moderator.id})\n**Resolved:** {bool(case['resolved'])}\n**Timestamp:** <:t{case['timestamp']}> | " + if case['duration'] != 'NULL': + expired = True if case["end_timestamp"] <= time.time() else False + embed.description = embed.description + f"**Duration:** {humanize.naturaldelta(case['duration'])}\n**Expired:** {expired}" + embed.add_field(name='Reason', value=f"```{case['reason']}```") + if case['resolved'] == 1: + embed.add_field(name='Resolve Reason', value=f"```{case['resolve_reason']}```") + await interaction.response.send_message(embed=embed, ephemeral=ephemeral) + else: + await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) + + @commands.group(autohelp=True) @checks.admin() async def moderationset(self, ctx: commands.Context):