diff options
-rw-r--r-- | slack/commands.py | 15 | ||||
-rw-r--r-- | slack/slack_workspace.py | 5 | ||||
-rw-r--r-- | typings/websocket.pyi | 5 |
3 files changed, 25 insertions, 0 deletions
diff --git a/slack/commands.py b/slack/commands.py index bcdeb69..cd25456 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -130,6 +130,21 @@ def command_slack_connect( create_task(connect()) +@weechat_command("%(slack_workspaces)|-all") +def command_slack_disconnect( + buffer: str, args: List[str], options: Dict[str, Optional[str]] +): + if args and args[0]: + workspace = shared.workspaces.get(args[0]) + if workspace: + workspace.disconnect() + else: + print_error(f'workspace "{args[0]}" not found') + elif options.get("all", False) is None: + for workspace in shared.workspaces.values(): + workspace.disconnect() + + @weechat_command() def command_slack_workspace( buffer: str, args: List[str], options: Dict[str, Optional[str]] diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index ac2b1e7..0e16920 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -249,3 +249,8 @@ class SlackWorkspace: def ws_recv(self, data: object): print(f"received: {data}") + + def disconnect(self): + self.is_connected = False + weechat.unhook(self.hook) + self.ws.close() diff --git a/typings/websocket.pyi b/typings/websocket.pyi index e7ed83b..0eaeda7 100644 --- a/typings/websocket.pyi +++ b/typings/websocket.pyi @@ -1,6 +1,8 @@ from socket import socket from typing import Any, Dict, Optional, Tuple +STATUS_NORMAL = 1000 + class ABNF: """ ABNF frame class. @@ -51,6 +53,9 @@ class WebSocket: def recv_data( self, control_frame: bool ) -> Tuple[int, Any,]: ... + def close( + self, status: int = STATUS_NORMAL, reason: bytes = b"", timeout: int = 3 + ) -> None: ... def create_connection( url: str, timeout: Optional[int] = ..., **options: Dict[str, Any] |