feat(aurora): renamed moderation cog to aurora, converted to sqlite3
Some checks failed
Pylint / Pylint (3.11) (push) Failing after 1m12s
Some checks failed
Pylint / Pylint (3.11) (push) Failing after 1m12s
This commit is contained in:
parent
9abbe12270
commit
ca50deedd5
14 changed files with 63 additions and 183 deletions
0
aurora/importers/__init__.py
Normal file
0
aurora/importers/__init__.py
Normal file
112
aurora/importers/aurora.py
Normal file
112
aurora/importers/aurora.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
import json
|
||||
from datetime import timedelta
|
||||
from typing import Dict
|
||||
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
|
||||
from ..utilities.database import connect, create_guild_table, mysql_log
|
||||
|
||||
|
||||
class ImportAuroraView(ui.View):
|
||||
def __init__(self, timeout, ctx, message):
|
||||
super().__init__()
|
||||
self.ctx: commands.Context = ctx
|
||||
self.message: Message = message
|
||||
|
||||
@ui.button(label="Yes", style=ButtonStyle.success)
|
||||
async def import_button_y(
|
||||
self, interaction: Interaction, button: ui.Button
|
||||
): # pylint: disable=unused-argument
|
||||
await self.message.delete()
|
||||
await interaction.response.send_message(
|
||||
"Deleting original table...", ephemeral=True
|
||||
)
|
||||
|
||||
database = connect()
|
||||
cursor = database.cursor()
|
||||
|
||||
query = f"DROP TABLE IF EXISTS moderation_{self.ctx.guild.id};"
|
||||
cursor.execute(query)
|
||||
|
||||
cursor.close()
|
||||
database.commit()
|
||||
|
||||
await interaction.edit_original_response(content="Creating new table...")
|
||||
|
||||
await create_guild_table(self.ctx.guild)
|
||||
|
||||
await interaction.edit_original_response(content="Importing moderations...")
|
||||
|
||||
file = await self.ctx.message.attachments[0].read()
|
||||
data: [dict] = sorted(json.loads(file), key=lambda x: x["moderation_id"])
|
||||
|
||||
user_mod_types = ["NOTE", "WARN", "MUTE", "UNMUTE", "KICK", "BAN", "UNBAN"]
|
||||
|
||||
channel_mod_types = ["SLOWMODE", "LOCKDOWN"]
|
||||
|
||||
failed_cases = []
|
||||
|
||||
for case in data:
|
||||
if case["moderation_id"] == 0:
|
||||
continue
|
||||
|
||||
if "target_type" not in case or not case["target_type"]:
|
||||
if case["moderation_type"] in user_mod_types:
|
||||
case["target_type"] = "USER"
|
||||
elif case["moderation_type"] in channel_mod_types:
|
||||
case["target_type"] = "CHANNEL"
|
||||
|
||||
if "role_id" not in case or not case["role_id"]:
|
||||
case["role_id"] = 0
|
||||
|
||||
if "changes" not in case or not case["changes"]:
|
||||
case["changes"] = []
|
||||
|
||||
if "metadata" not in case:
|
||||
metadata = {}
|
||||
else:
|
||||
metadata: Dict[str, any] = case["metadata"]
|
||||
if not metadata['imported_from']:
|
||||
metadata.update({
|
||||
'imported_from': 'Aurora'
|
||||
})
|
||||
|
||||
if case["duration"] != "NULL":
|
||||
hours, minutes, seconds = map(int, case["duration"].split(":"))
|
||||
duration = timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
||||
else:
|
||||
duration = "NULL"
|
||||
|
||||
await mysql_log(
|
||||
self.ctx.guild.id,
|
||||
case["moderator_id"],
|
||||
case["moderation_type"],
|
||||
case["target_type"],
|
||||
case["target_id"],
|
||||
case["role_id"],
|
||||
duration,
|
||||
case["reason"],
|
||||
timestamp=case["timestamp"],
|
||||
resolved=case["resolved"],
|
||||
resolved_by=case["resolved_by"],
|
||||
resolved_reason=case["resolve_reason"],
|
||||
expired=case["expired"],
|
||||
changes=case["changes"],
|
||||
metadata=metadata,
|
||||
database=database,
|
||||
)
|
||||
|
||||
await interaction.edit_original_response(content="Import complete.")
|
||||
if 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)
|
||||
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.delete(10)
|
||||
await self.ctx.message.delete(10)
|
145
aurora/importers/galacticbot.py
Normal file
145
aurora/importers/galacticbot.py
Normal file
|
@ -0,0 +1,145 @@
|
|||
import json
|
||||
from datetime import timedelta
|
||||
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
|
||||
from ..utilities.database import connect, create_guild_table, mysql_log
|
||||
|
||||
|
||||
class ImportGalacticBotView(ui.View):
|
||||
def __init__(self, timeout, ctx, message):
|
||||
super().__init__()
|
||||
self.ctx: commands.Context = ctx
|
||||
self.message: Message = message
|
||||
|
||||
@ui.button(label="Yes", style=ButtonStyle.success)
|
||||
async def import_button_y(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||
await self.message.delete()
|
||||
await interaction.response.send_message("Deleting original table...", ephemeral=True)
|
||||
|
||||
database = connect()
|
||||
cursor = database.cursor()
|
||||
|
||||
query = f"DROP TABLE IF EXISTS moderation_{self.ctx.guild.id};"
|
||||
cursor.execute(query)
|
||||
|
||||
cursor.close()
|
||||
database.commit()
|
||||
|
||||
await interaction.edit_original_response(content="Creating new table...")
|
||||
|
||||
await create_guild_table(self.ctx.guild)
|
||||
|
||||
await interaction.edit_original_response(content="Importing moderations...")
|
||||
|
||||
accepted_types = [
|
||||
'NOTE',
|
||||
'WARN',
|
||||
'MUTE',
|
||||
'UNMUTE',
|
||||
'KICK',
|
||||
'SOFTBAN',
|
||||
'BAN',
|
||||
'UNBAN',
|
||||
'SLOWMODE',
|
||||
'LOCKDOWN'
|
||||
]
|
||||
|
||||
file = await self.ctx.message.attachments[0].read()
|
||||
data = sorted(json.loads(file), key=lambda x: x['case'])
|
||||
|
||||
failed_cases = []
|
||||
|
||||
for case in data:
|
||||
if case['type'] not in accepted_types:
|
||||
continue
|
||||
|
||||
timestamp = round(case['timestamp'] / 1000)
|
||||
|
||||
try:
|
||||
if case['duration'] is not None and float(case['duration']) != 0:
|
||||
duration = timedelta(seconds=round(float(case['duration']) / 1000))
|
||||
else:
|
||||
duration = 'NULL'
|
||||
except OverflowError:
|
||||
failed_cases.append(case['case'])
|
||||
continue
|
||||
|
||||
metadata = {
|
||||
'imported_from': 'GalacticBot'
|
||||
}
|
||||
|
||||
if case['type'] == 'SLOWMODE':
|
||||
metadata['seconds'] = case['data']['seconds']
|
||||
|
||||
if case['resolved']:
|
||||
resolved = 1
|
||||
resolved_by = None
|
||||
resolved_reason = None
|
||||
resolved_timestamp = None
|
||||
if case['changes']:
|
||||
for change in case['changes']:
|
||||
if change['type'] == 'RESOLVE':
|
||||
resolved_by = change['staff']
|
||||
resolved_reason = change['reason']
|
||||
resolved_timestamp = round(change['timestamp'] / 1000)
|
||||
break
|
||||
if resolved_by is None:
|
||||
resolved_by = '?'
|
||||
if resolved_reason is None:
|
||||
resolved_reason = 'Could not get resolve reason during moderation import.'
|
||||
if resolved_timestamp is None:
|
||||
resolved_timestamp = timestamp
|
||||
changes = [
|
||||
{
|
||||
'type': "ORIGINAL",
|
||||
'reason': case['reason'],
|
||||
'user_id': case['executor'],
|
||||
'timestamp': timestamp
|
||||
},
|
||||
{
|
||||
'type': "RESOLVE",
|
||||
'reason': resolved_reason,
|
||||
'user_id': resolved_by,
|
||||
'timestamp': resolved_timestamp
|
||||
}
|
||||
]
|
||||
else:
|
||||
resolved = 0
|
||||
resolved_by = 'NULL'
|
||||
resolved_reason = 'NULL'
|
||||
changes = []
|
||||
|
||||
if case['reason'] and case['reason'] != "N/A":
|
||||
reason = case['reason']
|
||||
else:
|
||||
reason = "NULL"
|
||||
|
||||
await mysql_log(
|
||||
self.ctx.guild.id,
|
||||
case['executor'],
|
||||
case['type'],
|
||||
case['targetType'],
|
||||
case['target'],
|
||||
0,
|
||||
duration,
|
||||
reason,
|
||||
timestamp=timestamp,
|
||||
resolved=resolved,
|
||||
resolved_by=resolved_by,
|
||||
resolved_reason=resolved_reason,
|
||||
changes=changes,
|
||||
metadata=metadata,
|
||||
database=database
|
||||
)
|
||||
|
||||
await interaction.edit_original_response(content="Import complete.")
|
||||
if 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)
|
||||
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.delete(10)
|
||||
await self.ctx.message.delete(10)
|
Loading…
Add table
Add a link
Reference in a new issue