forked from blizzthewolf/SeaCogs
fix(moderation): actually fixed duration importing, again
This commit is contained in:
parent
2fba89787a
commit
b05e6f575f
1 changed files with 46 additions and 52 deletions
|
@ -4,6 +4,7 @@ from redbot.core import commands
|
||||||
from discord import Message, ButtonStyle, Interaction, ui
|
from discord import Message, ButtonStyle, Interaction, ui
|
||||||
from ..database import connect, create_guild_table, mysql_log
|
from ..database import connect, create_guild_table, mysql_log
|
||||||
|
|
||||||
|
|
||||||
class ImportModerationView(ui.View):
|
class ImportModerationView(ui.View):
|
||||||
def __init__(self, timeout, ctx, message):
|
def __init__(self, timeout, ctx, message):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -11,9 +12,13 @@ class ImportModerationView(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
|
||||||
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 = await connect()
|
database = await connect()
|
||||||
cursor = database.cursor()
|
cursor = database.cursor()
|
||||||
|
@ -31,79 +36,68 @@ class ImportModerationView(ui.View):
|
||||||
await interaction.edit_original_response(content="Importing moderations...")
|
await interaction.edit_original_response(content="Importing moderations...")
|
||||||
|
|
||||||
file = await self.ctx.message.attachments[0].read()
|
file = await self.ctx.message.attachments[0].read()
|
||||||
data: [dict] = sorted(json.loads(file), key=lambda x: x['moderation_id'])
|
data: [dict] = sorted(json.loads(file), key=lambda x: x["moderation_id"])
|
||||||
|
|
||||||
user_mod_types = [
|
user_mod_types = ["NOTE", "WARN", "MUTE", "UNMUTE", "KICK", "BAN", "UNBAN"]
|
||||||
'NOTE',
|
|
||||||
'WARN',
|
|
||||||
'MUTE',
|
|
||||||
'UNMUTE',
|
|
||||||
'KICK',
|
|
||||||
'BAN',
|
|
||||||
'UNBAN'
|
|
||||||
]
|
|
||||||
|
|
||||||
channel_mod_types = [
|
channel_mod_types = ["SLOWMODE", "LOCKDOWN"]
|
||||||
'SLOWMODE',
|
|
||||||
'LOCKDOWN'
|
|
||||||
]
|
|
||||||
|
|
||||||
failed_cases = []
|
failed_cases = []
|
||||||
|
|
||||||
for case in data:
|
for case in data:
|
||||||
if case['moderation_id'] == 0:
|
if case["moderation_id"] == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 'target_type' not in case or not case['target_type']:
|
if "target_type" not in case or not case["target_type"]:
|
||||||
if case['moderation_type'] in user_mod_types:
|
if case["moderation_type"] in user_mod_types:
|
||||||
case['target_type'] = 'USER'
|
case["target_type"] = "USER"
|
||||||
elif case['moderation_type'] in channel_mod_types:
|
elif case["moderation_type"] in channel_mod_types:
|
||||||
case['target_type'] = 'CHANNEL'
|
case["target_type"] = "CHANNEL"
|
||||||
|
|
||||||
if 'role_id' not in case or not case['role_id']:
|
if "role_id" not in case or not case["role_id"]:
|
||||||
case['role_id'] = 0
|
case["role_id"] = 0
|
||||||
|
|
||||||
if 'changes' not in case or not case['changes']:
|
if "changes" not in case or not case["changes"]:
|
||||||
case['changes'] = []
|
case["changes"] = []
|
||||||
|
|
||||||
if 'metadata' not in case or not case['metadata']:
|
if "metadata" not in case or not case["metadata"]:
|
||||||
case['metadata'] = {}
|
case["metadata"] = {}
|
||||||
|
|
||||||
if case['duration'] != 'NULL':
|
if case["duration"] != "NULL":
|
||||||
duration_t = datetime.strptime(case['duration'], "%H:%M:%S")
|
hours, minutes, seconds = map(int, case["duration"].split(":"))
|
||||||
duration = timedelta(
|
duration = timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
||||||
hours=duration_t.hours,
|
|
||||||
minutes=duration_t.minutes,
|
|
||||||
seconds=duration_t.seconds
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
duration = 'NULL'
|
duration = "NULL"
|
||||||
|
|
||||||
await mysql_log(
|
await mysql_log(
|
||||||
self.ctx.guild.id,
|
self.ctx.guild.id,
|
||||||
case['moderator_id'],
|
case["moderator_id"],
|
||||||
case['moderation_type'],
|
case["moderation_type"],
|
||||||
case['target_type'],
|
case["target_type"],
|
||||||
case['target_id'],
|
case["target_id"],
|
||||||
case['role_id'],
|
case["role_id"],
|
||||||
duration,
|
duration,
|
||||||
case['reason'],
|
case["reason"],
|
||||||
timestamp=case['timestamp'],
|
timestamp=case["timestamp"],
|
||||||
resolved=case['resolved'],
|
resolved=case["resolved"],
|
||||||
resolved_by=case['resolved_by'],
|
resolved_by=case["resolved_by"],
|
||||||
resolved_reason=case['resolve_reason'],
|
resolved_reason=case["resolve_reason"],
|
||||||
expired=case['expired'],
|
expired=case["expired"],
|
||||||
changes=case['changes'],
|
changes=case["changes"],
|
||||||
metadata=case['metadata'],
|
metadata=case["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=f"Import complete.\n*Failed to import the following cases:*\n```{failed_cases}```")
|
await interaction.edit_original_response(
|
||||||
|
content=f"Import complete.\n*Failed to import the following cases:*\n```{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("Import cancelled.", view=None)
|
await self.message.edit("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)
|
||||||
|
|
Loading…
Reference in a new issue