diff --git a/moderation/moderation.py b/moderation/moderation.py index f9e8821..05b8902 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -446,7 +446,7 @@ class Moderation(commands.Cog): await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason) @app_commands.command(name="history") - async def history(self, interaction: discord.Interaction, target: discord.Member = None, moderator: discord.Member = None, channel: discord.abc.GuildChannel = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1): + async def history(self, interaction: discord.Interaction, target: discord.Member = None, moderator: discord.Member = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1): """List previous infractions.""" database = await self.connect() cursor = database.cursor() @@ -462,40 +462,33 @@ class Moderation(commands.Cog): WHERE moderator_id = %s ORDER BY moderation_id DESC;""" cursor.execute(query, (interaction.guild.id, moderator.id)) - elif channel: - query = """SELECT * - FROM moderation_%s - WHERE target_id = %s - ORDER BY moderation_id DESC;""" - cursor.execute(query, (interaction.guild.id, channel.id)) - if target or moderator: - results = cursor.fetchall() - result_dict_list = [] - for result in results: - case_dict = self.generate_dict(result) - result_dict_list.append(case_dict) - case_quantity = len(result_dict_list) - page_quantity = round(case_quantity / pagesize) - start_index = (page - 1) * pagesize - end_index = page * pagesize - embed = discord.Embed(color= await self.bot.get_embed_color(None)) - embed.set_author(url=interaction.guild.icon.url, name='Infraction History') - embed.set_footer(text=f"Page {page}/{page_quantity} | {case_quantity} Results") - for case in result_dict_list[start_index:end_index]: - target_user = await self.fetch_user_dict(interaction, case['target_id']) - moderator_user = await self.fetch_user_dict(interaction, case['moderator_id']) - target_name = f"`{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']}" - field_name = f"Case #{case['moderation_id']} ({str.title(case['moderation_type'])})" - field_value = f"**Target:** `{target_name}` ({target_user['id']})\n**Moderator:** `{moderator_name}` ({moderator_user['id']})\n**Reason:** `{str(case['reason'])[:150]}`" - if case['duration'] != 'NULL': - td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case["duration"].split(":"))}) - duration_embed = f"{humanize.precisedelta(td)} | " if case["expired"] == '0' else f"{humanize.precisedelta(td)} | Expired" - field_value = field_value + f"\n**Duration:** {duration_embed}" - if bool(case['resolved']): - field_value = field_value + "\n**Resolved:** True" - embed.add_field(name=field_name, value=field_value, inline=False) - await interaction.response.send_message(embed=embed) + results = cursor.fetchall() + result_dict_list = [] + for result in results: + case_dict = self.generate_dict(result) + result_dict_list.append(case_dict) + case_quantity = len(result_dict_list) + page_quantity = round(case_quantity / pagesize) + start_index = (page - 1) * pagesize + end_index = page * pagesize + embed = discord.Embed(color= await self.bot.get_embed_color(None)) + embed.set_author(url=interaction.guild.icon.url, name='Infraction History') + embed.set_footer(text=f"Page {page}/{page_quantity} | {case_quantity} Results") + for case in result_dict_list[start_index:end_index]: + target_user = await self.fetch_user_dict(interaction, case['target_id']) + moderator_user = await self.fetch_user_dict(interaction, case['moderator_id']) + target_name = f"`{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']}" + field_name = f"Case #{case['moderation_id']} ({str.title(case['moderation_type'])})" + field_value = f"**Target:** `{target_name}` ({target_user['id']})\n**Moderator:** `{moderator_name}` ({moderator_user['id']})\n**Reason:** `{str(case['reason'])[:150]}`" + if case['duration'] != 'NULL': + td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case["duration"].split(":"))}) + duration_embed = f"{humanize.precisedelta(td)} | " if case["expired"] == '0' else f"{humanize.precisedelta(td)} | Expired" + field_value = field_value + f"\n**Duration:** {duration_embed}" + if bool(case['resolved']): + field_value = field_value + "\n**Resolved:** True" + embed.add_field(name=field_name, value=field_value, inline=False) + await interaction.response.send_message(embed=embed) @app_commands.command(name="resolve") async def resolve(self, interaction: discord.Interaction, case_number: int, reason: str = None):