diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-02-03 01:27:31 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 4de39f91d9d8942816b8967a115010c466b8f252 (patch) | |
tree | e019d0f6437f131ce3192991b17ef2263ee442e8 /slack/slack_workspace.py | |
parent | 684e7d701a4eb21c3b95954c3ca2e38d78ee451c (diff) | |
download | wee-slack-4de39f91d9d8942816b8967a115010c466b8f252.tar.gz |
Add messages received over rtm to channels
Diffstat (limited to 'slack/slack_workspace.py')
-rw-r--r-- | slack/slack_workspace.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 0d7e8c9..638a17b 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -20,6 +20,7 @@ from slack.proxy import Proxy from slack.shared import shared from slack.slack_api import SlackApi from slack.slack_conversation import SlackConversation +from slack.slack_message import SlackMessage from slack.slack_user import SlackBot, SlackUser, SlackUsergroup from slack.task import Future, Task, create_task, gather, run_async from slack.util import get_callback_name @@ -29,6 +30,7 @@ if TYPE_CHECKING: from slack_api.slack_conversations_info import SlackConversationsInfo from slack_api.slack_usergroups_info import SlackUsergroupInfo from slack_api.slack_users_info import SlackUserInfo + from slack_rtm.slack_rtm_message import SlackRtmMessage else: SlackBotInfo = object SlackConversationsInfo = object @@ -257,10 +259,24 @@ class SlackWorkspace: elif opcode != ABNF.OPCODE_TEXT: return weechat.WEECHAT_RC_OK - self._ws_recv(json.loads(recv_data.decode())) - - def _ws_recv(self, data: object): - print(f"received: {data}") + run_async(self._ws_recv(json.loads(recv_data.decode()))) + + async def _ws_recv(self, data: SlackRtmMessage): + if data["type"] == "message": + if "subtype" in data and data["subtype"] == "message_changed": + pass + elif "subtype" in data and data["subtype"] == "message_deleted": + pass + elif "subtype" in data and data["subtype"] == "message_replied": + pass + else: + channel_id = data["channel"] + if channel_id in self.open_conversations: + channel = self.open_conversations[channel_id] + message = SlackMessage(channel, data) + await channel.add_message(message) + else: + weechat.prnt("", f"\t{self.name} received: {json.dumps(data)}") def ping(self): if not self.is_connected: |