mirror of
https://github.com/boticord/boticordpy.git
synced 2024-09-22 19:32:01 +03:00
docs for websockets
This commit is contained in:
parent
0ad0180f7e
commit
e7ed02dee0
3 changed files with 37 additions and 1 deletions
|
@ -12,6 +12,8 @@ _logger = logging.getLogger("boticord.websocket")
|
|||
|
||||
|
||||
class BotiCordWebsocket:
|
||||
"""Represents a client that can be used to interact with the BotiCord by websocket connection."""
|
||||
|
||||
def __init__(self, token: str):
|
||||
self.__session = None
|
||||
self.loop = asyncio.get_event_loop()
|
||||
|
@ -22,7 +24,16 @@ class BotiCordWebsocket:
|
|||
self._token = token
|
||||
|
||||
def listener(self):
|
||||
"""Decorator to set the listener."""
|
||||
"""Decorator to set the listener (must be a coroutine function).
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@websocket.listener()
|
||||
async def comment_removed(data):
|
||||
pass
|
||||
"""
|
||||
|
||||
def inner(func):
|
||||
if not asyncio.iscoroutinefunction(func):
|
||||
|
@ -34,6 +45,7 @@ class BotiCordWebsocket:
|
|||
|
||||
def register_listener(self, notification_type: str, callback: typing.Any):
|
||||
"""Method to set the listener.
|
||||
|
||||
Args:
|
||||
notify_type (:obj:`str`)
|
||||
Type of notification (Check reference page)
|
||||
|
@ -119,6 +131,7 @@ class BotiCordWebsocket:
|
|||
await self.ws.send_json({"event": "ping"})
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close websocket connection with BotiCord"""
|
||||
if self.ws:
|
||||
self.not_closed = False
|
||||
await self.ws.close(code=4000)
|
||||
|
|
|
@ -11,6 +11,7 @@ This is a documentation for wrapper for BotiCord API.
|
|||
|
||||
quickstart
|
||||
api
|
||||
websocket
|
||||
|
||||
Links
|
||||
=====
|
||||
|
|
22
docs/source/websocket.rst
Normal file
22
docs/source/websocket.rst
Normal file
|
@ -0,0 +1,22 @@
|
|||
.. currentmodule:: boticordpy.websocket
|
||||
|
||||
###########
|
||||
WebSocket
|
||||
###########
|
||||
|
||||
BotiCord Websocket
|
||||
-------------------
|
||||
|
||||
.. autoclass:: BotiCordWebsocket
|
||||
:exclude-members: listener
|
||||
:inherited-members:
|
||||
|
||||
.. automethod:: BotiCordWebsocket.listener()
|
||||
:decorator:
|
||||
|
||||
|
||||
Notification types
|
||||
-------------------
|
||||
.. function:: comment_removed(data)
|
||||
|
||||
Called when comment is deleted.
|
Loading…
Reference in a new issue