SeaCogs/aurora/utilities/encoder.py

16 lines
399 B
Python
Raw Normal View History

import json
from datetime import datetime, timedelta
from aurora.models import Moderation
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
return int(o.timestamp())
if isinstance(o, timedelta):
return str(o)
if isinstance(o, Moderation):
return o.model_dump()
return super().default(o)