misc(moderation): removed checking channels' moderations history, will add back later on if I decide to add lockdown/slowmode/etc
All checks were successful
Pylint / Pylint (push) Successful in 1m13s

This commit is contained in:
Seaswimmer 2023-10-06 13:40:57 -04:00
parent 4a628cfc1d
commit 0925753404
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

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