aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/commands.py30
-rw-r--r--slack/slack_buffer.py18
-rw-r--r--slack/slack_conversation.py18
-rw-r--r--slack/slack_thread.py20
4 files changed, 80 insertions, 6 deletions
diff --git a/slack/commands.py b/slack/commands.py
index 67c214a..f9dcec2 100644
--- a/slack/commands.py
+++ b/slack/commands.py
@@ -448,6 +448,23 @@ def completion_irc_channels_cb(
return weechat.WEECHAT_RC_OK
+def completion_nicks_cb(
+ data: str, completion_item: str, buffer: str, completion: str
+) -> int:
+ slack_buffer = shared.buffers.get(buffer)
+ if slack_buffer is None:
+ return weechat.WEECHAT_RC_OK
+
+ for user in slack_buffer.members:
+ weechat.completion_list_add(
+ completion,
+ f"@{user.nick(only_nick=True)}",
+ 1,
+ weechat.WEECHAT_LIST_POS_SORT,
+ )
+ return weechat.WEECHAT_RC_OK
+
+
def completion_thread_hashes_cb(
data: str, completion_item: str, buffer: str, completion: str
) -> int:
@@ -577,9 +594,10 @@ def register_commands():
weechat.hook_command_run(
"/input set_unread_current_buffer", get_callback_name(buffer_set_unread_cb), ""
)
- weechat.hook_command_run(
- "/input complete_*", get_callback_name(input_complete_cb), ""
- )
+ # Disable until working properly
+ # weechat.hook_command_run(
+ # "/input complete_*", get_callback_name(input_complete_cb), ""
+ # )
weechat.hook_completion(
"slack_workspaces",
"Slack workspaces (internal names)",
@@ -599,6 +617,12 @@ def register_commands():
"",
)
weechat.hook_completion(
+ "nicks",
+ "nicks in the current Slack buffer",
+ get_callback_name(completion_nicks_cb),
+ "",
+ )
+ weechat.hook_completion(
"threads",
"complete thread ids for slack",
get_callback_name(completion_thread_hashes_cb),
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py
index a3155e6..addd2be 100644
--- a/slack/slack_buffer.py
+++ b/slack/slack_buffer.py
@@ -4,13 +4,24 @@ import re
import time
from abc import ABC, abstractmethod
from contextlib import contextmanager
-from typing import TYPE_CHECKING, Dict, List, Mapping, Match, Optional, Set, Tuple
+from typing import (
+ TYPE_CHECKING,
+ Dict,
+ Generator,
+ List,
+ Mapping,
+ Match,
+ Optional,
+ Set,
+ Tuple,
+)
import weechat
from slack.log import print_error
from slack.shared import shared
from slack.slack_message import SlackMessage, SlackTs
+from slack.slack_user import SlackUser
from slack.task import gather, run_async
from slack.util import get_callback_name, htmlescape
@@ -196,6 +207,11 @@ class SlackBuffer(ABC):
@property
@abstractmethod
+ def members(self) -> Generator[SlackUser, None, None]:
+ raise NotImplementedError()
+
+ @property
+ @abstractmethod
def messages(self) -> Mapping[SlackTs, SlackMessage]:
raise NotImplementedError()
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index e415dd4..a7a6928 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -2,7 +2,17 @@ from __future__ import annotations
import hashlib
from collections import OrderedDict
-from typing import TYPE_CHECKING, Dict, List, Mapping, NoReturn, Optional, Tuple, Union
+from typing import (
+ TYPE_CHECKING,
+ Dict,
+ Generator,
+ List,
+ Mapping,
+ NoReturn,
+ Optional,
+ Tuple,
+ Union,
+)
import weechat
@@ -157,6 +167,12 @@ class SlackConversation(SlackBuffer):
return "conversation"
@property
+ def members(self) -> Generator[SlackUser, None, None]:
+ for user_or_bot in self._nicklist:
+ if isinstance(user_or_bot, SlackUser):
+ yield user_or_bot
+
+ @property
def messages(self) -> Mapping[SlackTs, SlackMessage]:
return self._messages
diff --git a/slack/slack_thread.py b/slack/slack_thread.py
index 8033ff1..3a96789 100644
--- a/slack/slack_thread.py
+++ b/slack/slack_thread.py
@@ -1,10 +1,12 @@
from __future__ import annotations
from itertools import chain
-from typing import TYPE_CHECKING, Dict, Mapping, Optional, Tuple
+from typing import TYPE_CHECKING, Dict, Generator, Mapping, Optional, Set, Tuple
+from slack.log import print_exception_once
from slack.slack_buffer import SlackBuffer
from slack.slack_message import SlackMessage, SlackTs
+from slack.slack_user import SlackUser
from slack.task import gather
if TYPE_CHECKING:
@@ -18,6 +20,7 @@ class SlackThread(SlackBuffer):
def __init__(self, parent: SlackMessage) -> None:
super().__init__()
self.parent = parent
+ self._reply_users: Set[SlackUser] = set()
@property
def workspace(self) -> SlackWorkspace:
@@ -32,6 +35,11 @@ class SlackThread(SlackBuffer):
return "thread"
@property
+ def members(self) -> Generator[SlackUser, None, None]:
+ for user in self._reply_users:
+ yield user
+
+ @property
def messages(self) -> Mapping[SlackTs, SlackMessage]:
return self.parent.replies
@@ -107,6 +115,16 @@ class SlackThread(SlackBuffer):
self.history_needs_refresh = False
self.history_pending = False
+ async def print_message(self, message: SlackMessage):
+ await super().print_message(message)
+ sender_user_id = message.sender_user_id
+ if sender_user_id is not None:
+ try:
+ sender_user = await self.workspace.users[sender_user_id]
+ self._reply_users.add(sender_user)
+ except Exception as e:
+ print_exception_once(e)
+
async def mark_read(self):
# subscriptions.thread.mark is only available for session tokens
if self.workspace.token_type != "session":