WIP: Refactor Aurora (3.0.0) #29
1 changed files with 13 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
|
||||||
|
@ -7,16 +8,18 @@ from ..models.base import AuroraBaseModel
|
||||||
|
|
||||||
|
|
||||||
class JSONEncoder(json.JSONEncoder):
|
class JSONEncoder(json.JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o) -> Any:
|
||||||
if isinstance(o, datetime):
|
match o:
|
||||||
return int(o.timestamp())
|
case datetime():
|
||||||
if isinstance(o, timedelta):
|
return int(o.timestamp())
|
||||||
return str(o)
|
case timedelta():
|
||||||
if isinstance(o, AuroraBaseModel):
|
return str(o)
|
||||||
return o.dump()
|
case AuroraBaseModel():
|
||||||
if isinstance(o, Red):
|
return o.dump()
|
||||||
return None
|
case Red():
|
||||||
return super().default(o)
|
return None
|
||||||
|
case _:
|
||||||
|
return super().default(o)
|
||||||
|
|
||||||
|
|
||||||
# This is a wrapper around the json module's dumps function that uses our custom JSONEncoder class
|
# This is a wrapper around the json module's dumps function that uses our custom JSONEncoder class
|
||||||
|
|
Loading…
Reference in a new issue