From e7ed02dee0998722e025b0b24c8f85e5b4812da5 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Tue, 27 Jun 2023 16:24:03 +0300 Subject: [PATCH] docs for websockets --- boticordpy/websocket.py | 15 ++++++++++++++- docs/source/index.rst | 1 + docs/source/websocket.rst | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 docs/source/websocket.rst diff --git a/boticordpy/websocket.py b/boticordpy/websocket.py index 5692f41..7c890dd 100644 --- a/boticordpy/websocket.py +++ b/boticordpy/websocket.py @@ -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) diff --git a/docs/source/index.rst b/docs/source/index.rst index c903f84..1d2dd05 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -11,6 +11,7 @@ This is a documentation for wrapper for BotiCord API. quickstart api + websocket Links ===== diff --git a/docs/source/websocket.rst b/docs/source/websocket.rst new file mode 100644 index 0000000..5fcc5ec --- /dev/null +++ b/docs/source/websocket.rst @@ -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. \ No newline at end of file