Add base class. Make to_json available to all of the existing models.

This commit is contained in:
thecosmos
2019-05-22 23:52:17 +05:30
parent ca36e3ce03
commit d975547968
4 changed files with 24 additions and 13 deletions

View File

@@ -0,0 +1,15 @@
from abc import ABC
class DiscordModelsBase(ABC):
def to_json(self):
"""A utility method which returns raw payload object as it was received from discord.
Returns
-------
dict
A dict representing raw payload object received from discord.
"""
return self._payload

View File

@@ -1,7 +1,9 @@
from .base import DiscordModelsBase
from .user import User from .user import User
class Integration(object): class Integration(DiscordModelsBase):
""""Class representing discord server integrations. """"Class representing discord server integrations.
Attributes Attributes

View File

@@ -1,7 +1,9 @@
from .base import DiscordModelsBase
from .. import configs from .. import configs
class Guild(object): class Guild(DiscordModelsBase):
"""Class representing discord Guild the user is part of. """Class representing discord Guild the user is part of.
Attributes Attributes

View File

@@ -1,7 +1,9 @@
from .base import DiscordModelsBase
from .. import configs from .. import configs
class User(object): class User(DiscordModelsBase):
"""Class representing Discord User. """Class representing Discord User.
Attributes Attributes
@@ -65,16 +67,6 @@ class User(object):
"""A boolean representing if avatar of user is animated. Meaning user has GIF avatar.""" """A boolean representing if avatar of user is animated. Meaning user has GIF avatar."""
return self.avatar_hash.startswith("a_") return self.avatar_hash.startswith("a_")
def to_json(self):
"""A utility method which returns raw user object as it was returned from discord.
Returns
-------
dict
A dict of user's document.
"""
return self._payload
class Bot(User): class Bot(User):
"""Class representing the client user itself. """Class representing the client user itself.