Base
attrs
class
ClientObject (DictSerializationMixin)
¶
Serializable object that requires client reference.
Attr attributes:
Name | Type | Description |
---|
Source code in naff/models/discord/base.py
@define(slots=False)
class ClientObject(DictSerializationMixin):
"""Serializable object that requires client reference."""
_client: "Client" = field(metadata=no_export_meta)
@classmethod
def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
return super()._process_dict(data)
@classmethod
def from_dict(cls: Type[T], data: Dict[str, Any], client: "Client") -> T:
data = cls._process_dict(data, client)
return cls(client=client, **cls._filter_kwargs(data, cls._get_init_keys()))
@classmethod
def from_list(cls: Type[T], datas: List[Dict[str, Any]], client: "Client") -> List[T]:
return [cls.from_dict(data, client) for data in datas]
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
classmethod
method
from_dict(data, client)
¶
Process and converts dictionary data received from discord api to object class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any] |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The object class instance. |
Source code in naff/models/discord/base.py
@classmethod
def from_dict(cls: Type[T], data: Dict[str, Any], client: "Client") -> T:
data = cls._process_dict(data, client)
return cls(client=client, **cls._filter_kwargs(data, cls._get_init_keys()))
classmethod
method
from_list(datas, client)
¶
Process and converts list data received from discord api to object class instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
List[~T] |
List of object class instances. |
Source code in naff/models/discord/base.py
@classmethod
def from_list(cls: Type[T], datas: List[Dict[str, Any]], client: "Client") -> List[T]:
return [cls.from_dict(data, client) for data in datas]
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/base.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/base.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
DiscordObject (SnowflakeObject, ClientObject)
¶
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
Source code in naff/models/discord/base.py
@define(slots=False)
class DiscordObject(SnowflakeObject, ClientObject):
pass
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/base.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/base.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)