feat(moderation): improving resolve command
Some checks failed
Pylint / Pylint (push) Failing after 1m13s

This commit is contained in:
Seaswimmer 2023-10-05 22:36:42 -04:00
parent 7c88f98a28
commit 4960d40ac9
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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,8 +412,24 @@ 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."
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!")