diff options
Diffstat (limited to 'slack/slack_workspace.py')
-rw-r--r-- | slack/slack_workspace.py | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 0f9ddfb..d059b04 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -5,18 +5,7 @@ import socket import ssl import time from abc import ABC, abstractmethod -from typing import ( - TYPE_CHECKING, - Dict, - Generic, - Iterable, - List, - Optional, - Set, - Tuple, - Type, - TypeVar, -) +from typing import TYPE_CHECKING, Dict, Generic, Iterable, Optional, Set, Type, TypeVar import weechat from websocket import ( @@ -32,7 +21,7 @@ from slack.error import ( SlackRtmError, store_and_format_exception, ) -from slack.log import print_error +from slack.log import DebugMessageType, LogLevel, log, print_error from slack.proxy import Proxy from slack.shared import shared from slack.slack_api import SlackApi @@ -187,7 +176,6 @@ class SlackWorkspace: self._connect_task: Optional[Task[None]] = None self._ws: Optional[WebSocket] = None self._hook_ws_fd: Optional[str] = None - self._ws_messages: List[Tuple[float, SlackRtmMessage]] = [] self._debug_ws_buffer_pointer: Optional[str] = None self.conversations = SlackConversations(self) self.open_conversations: Dict[str, SlackConversation] = {} @@ -329,10 +317,8 @@ class SlackWorkspace: run_async(self._ws_recv(json.loads(recv_data.decode()))) async def _ws_recv(self, data: SlackRtmMessage): - epoch = time.time() # TODO: Remove old messages - self._ws_messages.append((epoch, data)) - self.print_debug_ws_buffer(epoch, data) + log(LogLevel.DEBUG, DebugMessageType.WEBSOCKET_RECV, json.dumps(data)) try: if data["type"] == "hello": @@ -453,33 +439,6 @@ class SlackWorkspace: msg["thread_ts"] = buffer.parent.ts self._ws.send(json.dumps(msg)) - def _close_debug_ws_buffer_cb(self, data: str, buffer: str): - self._debug_ws_buffer_pointer = None - return weechat.WEECHAT_RC_OK - - def open_debug_ws_buffer(self): - if self._debug_ws_buffer_pointer: - weechat.buffer_set(self._debug_ws_buffer_pointer, "display", "1") - return - - name = f"{shared.SCRIPT_NAME}.debug.ws.{self.name}" - self._debug_ws_buffer_pointer = weechat.buffer_new_props( - name, - {"display": "1"}, - "", - "", - get_callback_name(self._close_debug_ws_buffer_cb), - "", - ) - for epoch, message in self._ws_messages: - self.print_debug_ws_buffer(epoch, message) - - def print_debug_ws_buffer(self, epoch: float, message: SlackRtmMessage): - if self._debug_ws_buffer_pointer: - weechat.prnt_date_tags( - self._debug_ws_buffer_pointer, int(epoch), "", json.dumps(message) - ) - async def reconnect(self): self.disconnect() await self.connect() |