diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-14 22:26:54 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 17d928f8ce765229690afbc78a6a31cdf24da409 (patch) | |
tree | f31fae5f12f4bc82be86353e4e21b4e8d13b1694 /slack | |
parent | 1906b75a92fcdc441e891546cc9cc97a2e621495 (diff) | |
download | wee-slack-17d928f8ce765229690afbc78a6a31cdf24da409.tar.gz |
Call rtm.connect (doesn't connect to web socket yet)
Diffstat (limited to 'slack')
-rw-r--r-- | slack/commands.py | 2 | ||||
-rw-r--r-- | slack/slack_api.py | 4 | ||||
-rw-r--r-- | slack/slack_conversation.py | 4 | ||||
-rw-r--r-- | slack/slack_workspace.py | 10 |
4 files changed, 16 insertions, 4 deletions
diff --git a/slack/commands.py b/slack/commands.py index cc446d3..ffd833f 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -85,7 +85,7 @@ def display_workspace(workspace: SlackWorkspace, detailed_list: bool): f"{with_color('chat_delimiters', '[')}" f"connected" f"{with_color('chat_delimiters', ']')}" - f", nick: {workspace.nick}" + f", nick: {workspace.my_user.nick}" f", 0 channel(s), 0 pv", ) else: diff --git a/slack/slack_api.py b/slack/slack_api.py index ef15d81..70a3aaa 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -10,6 +10,7 @@ from slack.shared import shared if TYPE_CHECKING: from slack_api.slack_conversations_history import SlackConversationsHistoryResponse from slack_api.slack_conversations_info import SlackConversationsInfoResponse + from slack_api.slack_rtm_connect import SlackRtmConnectResponse from slack_api.slack_users_conversations import SlackUsersConversationsResponse from slack_api.slack_users_info import SlackUsersInfoResponse @@ -54,6 +55,9 @@ class SlackApi: return response return response + async def fetch_rtm_connect(self) -> SlackRtmConnectResponse: + return await self._fetch("rtm.connect") + async def fetch_conversations_history( self, conversation: SlackConversation ) -> SlackConversationsHistoryResponse: diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 9ab254d..3f801e0 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -74,7 +74,9 @@ class SlackConversation: self.buffer_pointer = weechat.buffer_new( self.name, get_callback_name(buffer_input_cb), "", "", "" ) - weechat.buffer_set(self.buffer_pointer, "localvar_set_nick", "nick") + weechat.buffer_set( + self.buffer_pointer, "localvar_set_nick", self.workspace.my_user.nick + ) async def fill_history(self): if self.history_filled or self.history_pending: diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index c5296c0..c95821c 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -32,12 +32,18 @@ class SlackWorkspace: self.config = shared.config.create_workspace_config(self.name) self.api = SlackApi(self) self.is_connected = False - self.nick = "TODO" self.users = SlackUsers(self) self.conversations: Dict[str, SlackConversation] = {} async def connect(self): - # rtm_connect = await self.api.fetch("rtm.connect") + rtm_connect = await self.api.fetch_rtm_connect() + if rtm_connect["ok"] is False: + # TODO: Handle error + raise Exception("Failed fetching rtm.connect") + + self.id = rtm_connect["team"]["id"] + self.my_user = await self.users[rtm_connect["self"]["id"]] + # "types": "public_channel,private_channel,im", user_channels_response = await self.api.fetch_users_conversations( "public_channel" |