diff options
-rw-r--r-- | slack/commands.py | 10 | ||||
-rw-r--r-- | slack/slack_buffer.py | 16 | ||||
-rw-r--r-- | slack/slack_conversation.py | 3 | ||||
-rw-r--r-- | slack/slack_thread.py | 9 |
4 files changed, 21 insertions, 17 deletions
diff --git a/slack/commands.py b/slack/commands.py index 4fc3ce7..7638b0d 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -273,9 +273,9 @@ def command_slack_thread(buffer: str, args: List[str], options: Options): @weechat_command("-alsochannel|%(threads)", min_args=1) def command_slack_reply(buffer: str, args: List[str], options: Options): slack_buffer = shared.buffers.get(buffer) + broadcast = bool(options.get("alsochannel")) if isinstance(slack_buffer, SlackThread): - broadcast = bool(options.get("alsochannel")) - run_async(slack_buffer.post_message(args[0], broadcast)) + run_async(slack_buffer.post_message(args[0], broadcast=broadcast)) elif isinstance(slack_buffer, SlackConversation): split_args = args[0].split(" ", 1) if len(split_args) < 2: @@ -284,11 +284,7 @@ def command_slack_reply(buffer: str, args: List[str], options: Options): ) return thread_ts = slack_buffer.ts_from_hash_or_index(split_args[0]) - run_async( - slack_buffer.workspace.api.chat_post_message( - slack_buffer, split_args[1], thread_ts - ) - ) + run_async(slack_buffer.post_message(split_args[1], thread_ts, broadcast)) def print_uncaught_error(error: UncaughtError, detailed: bool, options: Options): diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py index 63aa07c..eb6f676 100644 --- a/slack/slack_buffer.py +++ b/slack/slack_buffer.py @@ -386,9 +386,16 @@ class SlackBuffer(ABC): else: return self.ts_from_hash(hash_or_index) - @abstractmethod - async def post_message(self, text: str) -> None: - raise NotImplementedError() + async def post_message( + self, + text: str, + thread_ts: Optional[SlackTs] = None, + broadcast: bool = False, + ): + linkified_text = await self.linkify_text(text) + await self._api.chat_post_message( + self.conversation, linkified_text, thread_ts, broadcast + ) async def send_change_reaction( self, ts: SlackTs, emoji_char: str, change_type: Literal["+", "-"] @@ -476,8 +483,7 @@ class SlackBuffer(ABC): else: if input_data.startswith(("//", " ")): input_data = input_data[1:] - text = await self.linkify_text(input_data) - await self.post_message(text) + await self.post_message(input_data) def _buffer_input_cb(self, data: str, buffer: str, input_data: str) -> int: run_async(self.process_input(input_data)) diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 79a3f49..ee23303 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -749,9 +749,6 @@ class SlackConversation(SlackBuffer): if last_read_line_ts and last_read_line_ts != self.last_read: await self._api.conversations_mark(self, last_read_line_ts) - async def post_message(self, text: str) -> None: - await self._api.chat_post_message(self.conversation, text) - async def _buffer_closed(self): if self.id in self.workspace.open_conversations: del self.workspace.open_conversations[self.id] diff --git a/slack/slack_thread.py b/slack/slack_thread.py index 6063fd2..947a47c 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -141,5 +141,10 @@ class SlackThread(SlackBuffer): self.parent.conversation, self.parent.ts, last_read_line_ts ) - async def post_message(self, text: str, broadcast: bool = False) -> None: - await self._api.chat_post_message(self.conversation, text, self.parent.ts) + async def post_message( + self, + text: str, + thread_ts: Optional[SlackTs] = None, + broadcast: bool = False, + ): + await super().post_message(text, thread_ts or self.parent.ts, broadcast) |