You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, a developer must manually serialise and deserialise packets from or to a serialised JSON str of s. This leads towards writing unnecessary boilerplate such as this. I would very much appreciate the additional layer of abstraction being requested here if I could simply have send_message() taken dict as an acceptable type for its needed argument, and a way to specify receive_message(content_type=dict).
Instead, I have to resort to these utility methods. Courtesy of the retux repository.
asyncdef_send(self, payload: _GatewayPayload):
""" Sends a payload to the Gateway. Parameters ---------- payload : `_GatewayPayload` The payload to send. """try:
# Please note that asdict() is an attrs-specific method. dumps() is from the json dep.json=dumps(asdict(payload))
resp=awaitself._conn.send_message(json) # noqaexceptConnectionClosed:
logger.warning("The connection to Discord's Gateway has closed.")
awaitself._conn.aclose()
awaitself.reconnect()
asyncdef_receive(self) ->_GatewayPayload:
""" Receives the next incoming payload from the Gateway. Returns ------- `_GatewayPayload` A class of the payload data. """try:
resp=awaitself._conn.get_message()
json=loads(resp)
# structure_attrs_fromdict() is from the cattrs dep but# essentially acts as _GatewayPayload(**json)returnstructure_attrs_fromdict(json, _GatewayPayload)
exceptConnectionClosed:
logger.warning("The connection to Discord's Gateway has closed.")
self._closed=Trueawaitself.reconnect()
The text was updated successfully, but these errors were encountered:
Right now, a developer must manually serialise and deserialise packets from or to a serialised JSON str of
s
. This leads towards writing unnecessary boilerplate such as this. I would very much appreciate the additional layer of abstraction being requested here if I could simply havesend_message()
takendict
as an acceptable type for its needed argument, and a way to specifyreceive_message(content_type=dict)
.Instead, I have to resort to these utility methods. Courtesy of the retux repository.
The text was updated successfully, but these errors were encountered: