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"
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"]:
case["changes"] = []
@ -74,11 +79,11 @@ class ImportAuroraView(ui.View):
if not metadata.get("imported_from"):
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(":"))
duration = timedelta(hours=hours, minutes=minutes, seconds=seconds)
else:
duration = "NULL"
duration = None
await mysql_log(
self.ctx.guild.id,

View file

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

View file

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