feat(aurora): changed a lot of stuff. THIS IS A BREAKING CHANGE! VERY BREAKING! TAKE DATABASE BACKUPS BEFORE UPDATING TO THIS

This commit is contained in:
Seaswimmer 2024-05-04 14:49:07 -04:00
parent e8ca0aeb1c
commit afed1d6a37
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F
3 changed files with 33 additions and 18 deletions

View file

@ -62,7 +62,12 @@ class ImportAuroraView(ui.View):
case["target_type"] = "USER" case["target_type"] = "USER"
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"] = None
else:
case["role_id"] = int(case["role_id"])
case["target_id"] = int(case["target_id"])
case["moderator_id"] = int(case["moderator_id"])
if "changes" not in case or not case["changes"]: if "changes" not in case or not case["changes"]:
case["changes"] = [] case["changes"] = []
@ -74,11 +79,11 @@ class ImportAuroraView(ui.View):
if not metadata.get("imported_from"): if not metadata.get("imported_from"):
metadata.update({"imported_from": "Aurora"}) metadata.update({"imported_from": "Aurora"})
if case["duration"] != "NULL": if case["duration"] != "NULL" and case["duration"] is not None:
hours, minutes, seconds = map(int, case["duration"].split(":")) hours, minutes, seconds = map(int, case["duration"].split(":"))
duration = timedelta(hours=hours, minutes=minutes, seconds=seconds) duration = timedelta(hours=hours, minutes=minutes, seconds=seconds)
else: else:
duration = "NULL" duration = None
await mysql_log( await mysql_log(
self.ctx.guild.id, self.ctx.guild.id,

View file

@ -75,4 +75,8 @@ class JSONEncoder(json.JSONEncoder):
return int(o.timestamp()) return int(o.timestamp())
if isinstance(o, timedelta): if isinstance(o, timedelta):
return str(o) return str(o)
if isinstance(o, Moderation):
return o.model_dump()
if isinstance(o, None):
return "NULL"
return super().default(o) return super().default(o)

View file

@ -8,8 +8,7 @@ from discord import Guild
from redbot.core import data_manager from redbot.core import data_manager
from .logger import logger from .logger import logger
from .utils import (convert_timedelta_to_str, generate_dict, from .utils import convert_timedelta_to_str, generate_dict, get_next_case_number
get_next_case_number)
def connect() -> sqlite3.Connection: def connect() -> sqlite3.Connection:
@ -42,9 +41,9 @@ async def create_guild_table(guild: Guild):
timestamp INTEGER NOT NULL, timestamp INTEGER NOT NULL,
moderation_type TEXT NOT NULL, moderation_type TEXT NOT NULL,
target_type TEXT NOT NULL, target_type TEXT NOT NULL,
target_id TEXT NOT NULL, target_id INTEGER NOT NULL,
moderator_id TEXT NOT NULL, moderator_id INTEGER NOT NULL,
role_id TEXT, role_id INTEGER,
duration TEXT, duration TEXT,
end_timestamp INTEGER, end_timestamp INTEGER,
reason TEXT, reason TEXT,
@ -52,8 +51,8 @@ async def create_guild_table(guild: Guild):
resolved_by TEXT, resolved_by TEXT,
resolve_reason TEXT, resolve_reason TEXT,
expired INTEGER NOT NULL, expired INTEGER NOT NULL,
changes TEXT NOT NULL, changes JSON NOT NULL,
metadata TEXT NOT NULL metadata JSON NOT NULL
) )
""" """
cursor.execute(query) cursor.execute(query)
@ -111,8 +110,8 @@ async def mysql_log(
target_type: str, target_type: str,
target_id: int, target_id: int,
role_id: int, role_id: int,
duration: timedelta, duration: timedelta = None,
reason: str, reason: str = None,
database: sqlite3.Connection = None, database: sqlite3.Connection = None,
timestamp: int = None, timestamp: int = None,
resolved: bool = False, resolved: bool = False,
@ -125,13 +124,14 @@ async def mysql_log(
if not timestamp: if not timestamp:
timestamp = int(time.time()) timestamp = int(time.time())
if duration != "NULL": if duration != "NULL" and duration is not None:
end_timedelta = datetime.fromtimestamp(timestamp) + duration end_timedelta = datetime.fromtimestamp(timestamp) + duration
end_timestamp = int(end_timedelta.timestamp()) end_timestamp = int(end_timedelta.timestamp())
duration = convert_timedelta_to_str(duration) duration = convert_timedelta_to_str(duration)
else: else:
end_timestamp = 0 duration = None
end_timestamp = None
if not expired: if not expired:
if int(time.time()) > end_timestamp: if int(time.time()) > end_timestamp:
@ -139,11 +139,17 @@ async def mysql_log(
else: else:
expired = 0 expired = 0
if resolved_by is None: if reason == "NULL":
resolved_by = "NULL" reason = None
if resolved_reason is None: if resolved_by == "NULL":
resolved_reason = "NULL" resolved_by = None
if resolved_reason == "NULL":
resolved_reason = None
if role_id == 0:
role_id = None
if not database: if not database:
database = connect() database = connect()