misc(moderation): changed all case_number arguments to case
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 47s

This commit is contained in:
Seaswimmer 2023-12-14 20:16:25 -05:00
parent ea9d8fb201
commit 5f5fe459cb
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -1007,12 +1007,12 @@ class Moderation(commands.Cog):
await interaction.followup.send(embed=embed, ephemeral=ephemeral) await interaction.followup.send(embed=embed, ephemeral=ephemeral)
@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: int, reason: str = None):
"""Resolve a specific case. """Resolve a specific case.
Parameters Parameters
----------- -----------
case_number: int case: int
Case number of the case you're trying to resolve Case number of the case you're trying to resolve
reason: str reason: str
Reason for resolving case""" Reason for resolving case"""
@ -1030,24 +1030,24 @@ class Moderation(commands.Cog):
db = await self.config.mysql_database() db = await self.config.mysql_database()
query_1 = "SELECT * FROM moderation_%s WHERE moderation_id = %s;" query_1 = "SELECT * FROM moderation_%s WHERE moderation_id = %s;"
cursor.execute(query_1, (interaction.guild.id, case_number)) cursor.execute(query_1, (interaction.guild.id, case))
result_1 = cursor.fetchone() result_1 = cursor.fetchone()
if result_1 is None or case_number == 0: if result_1 is None or case == 0:
await interaction.response.send_message(content=f"There is no moderation with a case number of {case_number}.", ephemeral=True) await interaction.response.send_message(content=f"There is no moderation with a case number of {case}.", ephemeral=True)
return return
query_2 = "SELECT * FROM moderation_%s WHERE moderation_id = %s AND resolved = 0;" query_2 = "SELECT * FROM moderation_%s WHERE moderation_id = %s AND resolved = 0;"
cursor.execute(query_2, (interaction.guild.id, case_number)) cursor.execute(query_2, (interaction.guild.id, case))
result_2 = cursor.fetchone() result_2 = cursor.fetchone()
if result_2 is None: 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) await interaction.response.send_message(content=f"This moderation has already been resolved!\nUse `/case {case}` for more information.", ephemeral=True)
return return
case = self.generate_dict(result_2) case_dict = self.generate_dict(result_2)
if reason is None: if reason is None:
reason = "No reason given." reason = "No reason given."
changes: list = case['changes'] changes: list = case_dict['changes']
if len(changes) > 25: if len(changes) > 25:
await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True) await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True)
return return
@ -1055,9 +1055,9 @@ class Moderation(commands.Cog):
changes.append( changes.append(
{ {
'type': "ORIGINAL", 'type': "ORIGINAL",
'timestamp': case['timestamp'], 'timestamp': case_dict['timestamp'],
'reason': case['reason'], 'reason': case_dict['reason'],
'user_id': case['moderator_id'] 'user_id': case_dict['moderator_id']
} }
) )
changes.append( changes.append(
@ -1069,23 +1069,23 @@ class Moderation(commands.Cog):
} }
) )
if case['moderation_type'] in ['UNMUTE', 'UNBAN']: if case_dict['moderation_type'] in ['UNMUTE', 'UNBAN']:
await interaction.response.send_message(content="You cannot resolve this type of moderation!", ephemeral=True) await interaction.response.send_message(content="You cannot resolve this type of moderation!", ephemeral=True)
if case['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']: if case_dict['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']:
if case['moderation_type'] == 'MUTE': if case_dict['moderation_type'] == 'MUTE':
try: try:
member = await interaction.guild.fetch_member(case['target_id']) member = await interaction.guild.fetch_member(case_dict['target_id'])
await member.timeout(None, reason=f"Case #{case_number} resolved by {interaction.user.id}") await member.timeout(None, reason=f"Case #{case} resolved by {interaction.user.id}")
except discord.NotFound: except discord.NotFound:
pass pass
if case['moderation_type'] in ['TEMPBAN', 'BAN']: if case_dict['moderation_type'] in ['TEMPBAN', 'BAN']:
try: try:
user = await interaction.client.fetch_user(case['target_id']) user = await interaction.client.fetch_user(case_dict['target_id'])
await interaction.guild.unban(user, reason=f"Case #{case_number} resolved by {interaction.user.id}") await interaction.guild.unban(user, reason=f"Case #{case} resolved by {interaction.user.id}")
except discord.NotFound: except discord.NotFound:
pass pass
@ -1093,26 +1093,32 @@ class Moderation(commands.Cog):
else: else:
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, changes = %s, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s" resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, changes = %s, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s"
cursor.execute(resolve_query, (json.dumps(changes), interaction.user.id, reason, case_number)) cursor.execute(resolve_query, (json.dumps(changes), interaction.user.id, reason, classmethod))
database.commit() database.commit()
embed = await self.embed_factory('case', interaction=interaction, case_dict=await self.fetch_case(case_number, interaction.guild.id)) embed = await self.embed_factory('case', interaction=interaction, case_dict=await self.fetch_case(case, interaction.guild.id))
await interaction.response.send_message(content=f"✅ Moderation #{case_number} resolved!", embed=embed) await interaction.response.send_message(content=f"✅ Moderation #{case} resolved!", embed=embed)
await self.log(interaction, case_number, True) await self.log(interaction, case, True)
cursor.close() cursor.close()
database.close() database.close()
@app_commands.command(name="case") @app_commands.command(name="case")
async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False, changes: bool = False, export: bool = False): @app_commands.choices(export=[
Choice(name="Export as File", value='file'),
Choice(name='Export as Codeblock', value='codeblock')
])
async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = False, changes: bool = False, export: Choice[str] = None):
"""Check the details of a specific case. """Check the details of a specific case.
Parameters Parameters
----------- -----------
case_number: int case: int
What case are you looking up? What case are you looking up?
ephemeral: bool ephemeral: bool
Hide the command response Hide the command response
changes: bool
List the changes made to the case
export: bool export: bool
Export the case to a JSON file""" Export the case to a JSON file"""
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction) permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
@ -1120,38 +1126,43 @@ class Moderation(commands.Cog):
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True) await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
return return
if case_number != 0: if case != 0:
case = await self.fetch_case(case_number, interaction.guild.id) case_dict = await self.fetch_case(case, interaction.guild.id)
if case: if case_dict:
if export: if export:
if len(str(case)) > 1800: if len(str(case)) > 1800 or export == 'file':
filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case_number}.json" filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case}.json"
with open(filename, "w", encoding="utf-8") as f: with open(filename, "w", encoding="utf-8") as f:
json.dump(case, f, indent=2) json.dump(case_dict, f, indent=2)
await interaction.response.send_message(file=discord.File(filename, f"moderation_{interaction.guild.id}_case_{case_number}.json"), ephemeral=ephemeral) if export == 'codeblock':
content = f"Case #{case} exported.\n*Case was too large to export as codeblock, so it has been uploaded as a `.json` file.*"
else:
content = f"Case #{case} exported."
await interaction.response.send_message(content=content, file=discord.File(filename, f"moderation_{interaction.guild.id}_case_{case}.json"), ephemeral=ephemeral)
os.remove(filename) os.remove(filename)
return return
else: else:
await interaction.response.send_message(content=f"```json\n{json.dumps(case, indent=2)}```", ephemeral=ephemeral) await interaction.response.send_message(content=f"```json\n{json.dumps(case_dict, indent=2)}```", ephemeral=ephemeral)
return return
if changes: if changes:
embed = await self.embed_factory('changes', interaction=interaction, case_dict=case) embed = await self.embed_factory('changes', interaction=interaction, case_dict=case_dict)
else: else:
embed = await self.embed_factory('case', interaction=interaction, case_dict=case) embed = await self.embed_factory('case', interaction=interaction, case_dict=case_dict)
await interaction.response.send_message(embed=embed, ephemeral=ephemeral) await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
return return
await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) await interaction.response.send_message(content=f"No case with case number `{case}` found.", ephemeral=True)
@app_commands.command(name="edit") @app_commands.command(name="edit")
async def edit(self, interaction: discord.Interaction, case_number: int, reason: str): async def edit(self, interaction: discord.Interaction, case: int, reason: str):
"""Edit the reason of a specific case. """Edit the reason of a specific case.
Parameters Parameters
----------- -----------
case_number: int case: int
What case are you editing? What case are you editing?
reason: str reason: str
What is the new reason?""" What is the new reason?"""
@ -1160,14 +1171,14 @@ class Moderation(commands.Cog):
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True) await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
return return
if case_number != 0: if case != 0:
case = await self.fetch_case(case_number, interaction.guild.id) case_dict = await self.fetch_case(case, interaction.guild.id)
if case: if case_dict:
conf = await self.check_conf(['mysql_database']) conf = await self.check_conf(['mysql_database'])
if conf: if conf:
raise(LookupError) raise(LookupError)
changes: list = case['changes'] changes: list = case_dict['changes']
if len(changes) > 25: if len(changes) > 25:
await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True) await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True)
return return
@ -1175,9 +1186,9 @@ class Moderation(commands.Cog):
changes.append( changes.append(
{ {
'type': "ORIGINAL", 'type': "ORIGINAL",
'timestamp': case['timestamp'], 'timestamp': case_dict['timestamp'],
'reason': case['reason'], 'reason': case_dict['reason'],
'user_id': case['moderator_id'] 'user_id': case_dict['moderator_id']
} }
) )
changes.append( changes.append(
@ -1194,19 +1205,19 @@ class Moderation(commands.Cog):
db = await self.config.mysql_database() db = await self.config.mysql_database()
update_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET changes = %s, reason = %s WHERE moderation_id = %s" update_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET changes = %s, reason = %s WHERE moderation_id = %s"
cursor.execute(update_query, (json.dumps(changes), reason, case_number)) cursor.execute(update_query, (json.dumps(changes), reason, case))
database.commit() database.commit()
new_case = await self.fetch_case(case_number, interaction.guild.id) new_case = await self.fetch_case(case, interaction.guild.id)
embed = await self.embed_factory('case', interaction=interaction, case_dict=new_case) embed = await self.embed_factory('case', interaction=interaction, case_dict=new_case)
await interaction.response.send_message(content=f"✅ Moderation #{case_number} edited!", embed=embed, ephemeral=True) await interaction.response.send_message(content=f"✅ Moderation #{case} edited!", embed=embed, ephemeral=True)
await self.log(interaction, case_number) await self.log(interaction, case)
cursor.close() cursor.close()
database.close() database.close()
return return
await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) await interaction.response.send_message(content=f"No case with case number `{case}` found.", ephemeral=True)
@tasks.loop(minutes=1) @tasks.loop(minutes=1)
async def handle_expiry(self): async def handle_expiry(self):