diff --git a/moderation/moderation.py b/moderation/moderation.py index 08cb353..d0f2516 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -123,6 +123,22 @@ class Moderation(commands.Cog): logging.fatal("Unable to access the MySQL database!\nError:\n%s", e.msg) raise ConnectionRefusedError(f"Unable to access the MySQL Database!\n{e.msg}") from e + def generate_dict(self, result): + case: dict = { + "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] + } + return case + async def create_guild_table(self, guild: discord.Guild): database = await self.connect() cursor = database.cursor() @@ -396,9 +412,25 @@ class Moderation(commands.Cog): if result_2 is None: await interaction.response.send_message(content=f"This moderation has already been resolved!\nUse `/case {case_number}` for more information.", ephemeral=True) return + case = self.generate_dict(result_2) if reason is None: reason = "No reason given." - resolve_query = f"UPDATE moderation_{interaction.guild.id} SET resolved = 1, resolve_reason = %s WHERE moderation_id = %s" + if case['moderation_type'] in ['mute', 'tempban']: + if case['moderation_type'] == 'mute': + try: + member = await interaction.guild.fetch_member(case['target_id']) + await member.timeout(None, reason=f"Case #{case_number} resolved by {interaction.user.id}") + except: + pass + if case['moderation_type'] == 'tempban': + try: + user = await interaction.client.fetch_user(case['target_id']) + await interaction.guild.unban(user, reason=f"Case #{case_number} resolved by {interaction.user.id}") + except: + pass + resolve_query = f"UPDATE moderation_{interaction.guild.id} SET resolved = 1, expired = 1, resolve_reason = %s WHERE moderation_id = %s" + else: + resolve_query = f"UPDATE moderation_{interaction.guild.id} SET resolved = 1, resolve_reason = %s WHERE moderation_id = %s" cursor.execute(resolve_query, (reason, case_number)) await interaction.response.send_message(content=f"✅ Moderation #{case_number} resolved!")