fix(aurora): pylint fix

This commit is contained in:
Seaswimmer 2024-02-03 13:41:57 -05:00
parent 21d5266bb6
commit 09ce2c7d73
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063
2 changed files with 70 additions and 58 deletions

View file

@ -19,6 +19,7 @@ class ImportAuroraView(ui.View):
async def import_button_y( async def import_button_y(
self, interaction: Interaction, button: ui.Button self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument ): # pylint: disable=unused-argument
# pylint: disable=duplicate-code
await self.message.delete() await self.message.delete()
await interaction.response.send_message( await interaction.response.send_message(
"Deleting original table...", ephemeral=True "Deleting original table...", ephemeral=True
@ -68,10 +69,8 @@ class ImportAuroraView(ui.View):
metadata = {} metadata = {}
else: else:
metadata: Dict[str, any] = json.loads(case["metadata"]) metadata: Dict[str, any] = json.loads(case["metadata"])
if not metadata.get('imported_from'): if not metadata.get("imported_from"):
metadata.update({ metadata.update({"imported_from": "Aurora"})
'imported_from': 'Aurora'
})
if case["duration"] != "NULL": if case["duration"] != "NULL":
hours, minutes, seconds = map(int, case["duration"].split(":")) hours, minutes, seconds = map(int, case["duration"].split(":"))
@ -101,7 +100,9 @@ class ImportAuroraView(ui.View):
await interaction.edit_original_response(content="Import complete.") await interaction.edit_original_response(content="Import complete.")
if failed_cases: if failed_cases:
await interaction.edit_original_response( await interaction.edit_original_response(
content="Import complete.\n" + warning("Failed to import the following cases:\n") + box(failed_cases) content="Import complete.\n"
+ warning("Failed to import the following cases:\n")
+ box(failed_cases)
) )
@ui.button(label="No", style=ButtonStyle.danger) @ui.button(label="No", style=ButtonStyle.danger)

View file

@ -15,9 +15,14 @@ class ImportGalacticBotView(ui.View):
self.message: Message = message self.message: Message = message
@ui.button(label="Yes", style=ButtonStyle.success) @ui.button(label="Yes", style=ButtonStyle.success)
async def import_button_y(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def import_button_y(
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
# pylint: disable=duplicate-code
await self.message.delete() await self.message.delete()
await interaction.response.send_message("Deleting original table...", ephemeral=True) await interaction.response.send_message(
"Deleting original table...", ephemeral=True
)
database = connect() database = connect()
cursor = database.cursor() cursor = database.cursor()
@ -35,94 +40,94 @@ class ImportGalacticBotView(ui.View):
await interaction.edit_original_response(content="Importing moderations...") await interaction.edit_original_response(content="Importing moderations...")
accepted_types = [ accepted_types = [
'NOTE', "NOTE",
'WARN', "WARN",
'MUTE', "MUTE",
'UNMUTE', "UNMUTE",
'KICK', "KICK",
'SOFTBAN', "SOFTBAN",
'BAN', "BAN",
'UNBAN', "UNBAN",
'SLOWMODE', "SLOWMODE",
'LOCKDOWN' "LOCKDOWN",
] ]
file = await self.ctx.message.attachments[0].read() file = await self.ctx.message.attachments[0].read()
data = sorted(json.loads(file), key=lambda x: x['case']) data = sorted(json.loads(file), key=lambda x: x["case"])
failed_cases = [] failed_cases = []
for case in data: for case in data:
if case['type'] not in accepted_types: if case["type"] not in accepted_types:
continue continue
timestamp = round(case['timestamp'] / 1000) timestamp = round(case["timestamp"] / 1000)
try: try:
if case['duration'] is not None and float(case['duration']) != 0: if case["duration"] is not None and float(case["duration"]) != 0:
duration = timedelta(seconds=round(float(case['duration']) / 1000)) duration = timedelta(seconds=round(float(case["duration"]) / 1000))
else: else:
duration = 'NULL' duration = "NULL"
except OverflowError: except OverflowError:
failed_cases.append(case['case']) failed_cases.append(case["case"])
continue continue
metadata = { metadata = {"imported_from": "GalacticBot"}
'imported_from': 'GalacticBot'
}
if case['type'] == 'SLOWMODE': if case["type"] == "SLOWMODE":
metadata['seconds'] = case['data']['seconds'] metadata["seconds"] = case["data"]["seconds"]
if case['resolved']: if case["resolved"]:
resolved = 1 resolved = 1
resolved_by = None resolved_by = None
resolved_reason = None resolved_reason = None
resolved_timestamp = None resolved_timestamp = None
if case['changes']: if case["changes"]:
for change in case['changes']: for change in case["changes"]:
if change['type'] == 'RESOLVE': if change["type"] == "RESOLVE":
resolved_by = change['staff'] resolved_by = change["staff"]
resolved_reason = change['reason'] resolved_reason = change["reason"]
resolved_timestamp = round(change['timestamp'] / 1000) resolved_timestamp = round(change["timestamp"] / 1000)
break break
if resolved_by is None: if resolved_by is None:
resolved_by = '?' resolved_by = "?"
if resolved_reason is None: if resolved_reason is None:
resolved_reason = 'Could not get resolve reason during moderation import.' resolved_reason = (
"Could not get resolve reason during moderation import."
)
if resolved_timestamp is None: if resolved_timestamp is None:
resolved_timestamp = timestamp resolved_timestamp = timestamp
changes = [ changes = [
{ {
'type': "ORIGINAL", "type": "ORIGINAL",
'reason': case['reason'], "reason": case["reason"],
'user_id': case['executor'], "user_id": case["executor"],
'timestamp': timestamp "timestamp": timestamp,
}, },
{ {
'type': "RESOLVE", "type": "RESOLVE",
'reason': resolved_reason, "reason": resolved_reason,
'user_id': resolved_by, "user_id": resolved_by,
'timestamp': resolved_timestamp "timestamp": resolved_timestamp,
} },
] ]
else: else:
resolved = 0 resolved = 0
resolved_by = 'NULL' resolved_by = "NULL"
resolved_reason = 'NULL' resolved_reason = "NULL"
changes = [] changes = []
if case['reason'] and case['reason'] != "N/A": if case["reason"] and case["reason"] != "N/A":
reason = case['reason'] reason = case["reason"]
else: else:
reason = "NULL" reason = "NULL"
await mysql_log( await mysql_log(
self.ctx.guild.id, self.ctx.guild.id,
case['executor'], case["executor"],
case['type'], case["type"],
case['targetType'], case["targetType"],
case['target'], case["target"],
0, 0,
duration, duration,
reason, reason,
@ -132,15 +137,21 @@ class ImportGalacticBotView(ui.View):
resolved_reason=resolved_reason, resolved_reason=resolved_reason,
changes=changes, changes=changes,
metadata=metadata, metadata=metadata,
database=database database=database,
) )
await interaction.edit_original_response(content="Import complete.") await interaction.edit_original_response(content="Import complete.")
if failed_cases: if failed_cases:
await interaction.edit_original_response(content="Import complete.\n" + warning("Failed to import the following cases:\n") + box(failed_cases)) await interaction.edit_original_response(
content="Import complete.\n"
+ warning("Failed to import the following cases:\n")
+ box(failed_cases)
)
@ui.button(label="No", style=ButtonStyle.danger) @ui.button(label="No", style=ButtonStyle.danger)
async def import_button_n(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def import_button_n(
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
await self.message.edit(content="Import cancelled.", view=None) await self.message.edit(content="Import cancelled.", view=None)
await self.message.delete(10) await self.message.delete(10)
await self.ctx.message.delete(10) await self.ctx.message.delete(10)