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,15 +8,17 @@ 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:
|
||||||
|
case datetime():
|
||||||
return int(o.timestamp())
|
return int(o.timestamp())
|
||||||
if isinstance(o, timedelta):
|
case timedelta():
|
||||||
return str(o)
|
return str(o)
|
||||||
if isinstance(o, AuroraBaseModel):
|
case AuroraBaseModel():
|
||||||
return o.dump()
|
return o.dump()
|
||||||
if isinstance(o, Red):
|
case Red():
|
||||||
return None
|
return None
|
||||||
|
case _:
|
||||||
return super().default(o)
|
return super().default(o)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue