WIP: Moderation type registry #26

Closed
cswimr wants to merge 146 commits from aurora-3rd-party into main
Showing only changes of commit 0386cb346e - Show all commits

View file

@ -1,6 +1,5 @@
import sqlite3
from datetime import datetime, timedelta
from itertools import chain
from time import time
from typing import Any, Dict, List, Literal, Optional, Union
@ -229,23 +228,25 @@ class Moderation(AuroraGuildModel):
}
case_safe = case.copy()
case_safe.pop("guild_id")
case_safe["timestamp"] = case_safe["timestamp"].timestamp()
case_safe["end_timestamp"] = case_safe["end_timestamp"].timestamp() if case_safe["end_timestamp"] else None
case_safe["changes"] = dumps(case_safe["changes"])
case_safe["metadata"] = dumps(case_safe["metadata"])
case_sql = case_safe.copy()
case_sql.pop("guild_id")
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(sql, tuple(case_safe.values()))
cursor.execute(sql, tuple(case_sql.values()))
cursor.close()
database.commit()
if close_db:
database.close()
case_safe.update({"guild_id": guild_id})
logger.debug(
"Row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
tuple(chain({"guild_id": guild_id}.values(), case_safe.values()))
tuple(case_safe.values())
)
return cls.from_dict(bot=bot, **case)