diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-20 21:09:10 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | f3f97e5cbb97ed7a04bc3e40a110805ff0ae53c8 (patch) | |
tree | d6abf2212800d82e3e845a4ec5f70dd031fa5f94 /slack/slack_workspace.py | |
parent | 9a92344a77731f443d19dfdb24a6a47a1b7dc9ce (diff) | |
download | wee-slack-f3f97e5cbb97ed7a04bc3e40a110805ff0ae53c8.tar.gz |
Render reactions after messages
Diffstat (limited to 'slack/slack_workspace.py')
-rw-r--r-- | slack/slack_workspace.py | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 28b9b4b..f721bda 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -26,7 +26,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_message import SlackMessage, SlackTs 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 @@ -273,13 +273,25 @@ class SlackWorkspace: async def _ws_recv(self, data: SlackRtmMessage): try: - channel_id = "channel" in data and data["channel"] - if channel_id in self.open_conversations: - channel = self.open_conversations[channel_id] + if data["type"] == "hello": + return + elif data["type"] == "reaction_added" or data["type"] == "reaction_removed": + channel_id = data["item"]["channel"] + elif "channel" in data and type(data["channel"]) == str: + channel_id = data["channel"] else: - channel = None + weechat.prnt("", f"\t{self.name} received: {json.dumps(data)}") + return + + channel = self.open_conversations.get(channel_id) + if channel is None: + weechat.prnt( + "", + f"\t{self.name} received for not open conversation, discarding: {json.dumps(data)}", + ) + return - if data["type"] == "message" and channel is not None: + if data["type"] == "message": if "subtype" in data and data["subtype"] == "message_changed": await channel.change_message(data) elif "subtype" in data and data["subtype"] == "message_deleted": @@ -289,7 +301,17 @@ class SlackWorkspace: else: message = SlackMessage(channel, data) await channel.add_message(message) - elif data["type"] == "user_typing" and channel is not None: + elif data["type"] == "reaction_added" and data["item"]["type"] == "message": + await channel.reaction_add( + SlackTs(data["item"]["ts"]), data["reaction"], data["user"] + ) + elif ( + data["type"] == "reaction_removed" and data["item"]["type"] == "message" + ): + await channel.reaction_remove( + SlackTs(data["item"]["ts"]), data["reaction"], data["user"] + ) + elif data["type"] == "user_typing": await channel.typing_add_user(data["user"], data.get("thread_ts")) else: weechat.prnt("", f"\t{self.name} received: {json.dumps(data)}") |