diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-12-14 15:09:11 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | aafcb6472607dfae714a025435e1f8081ac8299d (patch) | |
tree | 546f3fabf4faaeca599480a17c3bc701398dd4d7 | |
parent | 57ad5138dc9bb5aa85ae4f58ee022f2ea2003b5d (diff) | |
download | wee-slack-aafcb6472607dfae714a025435e1f8081ac8299d.tar.gz |
Add command /slack reply
-rw-r--r-- | slack/commands.py | 21 | ||||
-rw-r--r-- | slack/slack_api.py | 2 | ||||
-rw-r--r-- | slack/slack_thread.py | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/slack/commands.py b/slack/commands.py index f9d6919..58f464c 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -271,6 +271,27 @@ def command_slack_thread(buffer: str, args: List[str], options: Options): run_async(slack_buffer.open_thread(args[0], switch=True)) +@weechat_command("-alsochannel|%(threads)", min_args=1) +def command_slack_reply(buffer: str, args: List[str], options: Options): + slack_buffer = shared.buffers.get(buffer) + if isinstance(slack_buffer, SlackThread): + broadcast = bool(options.get("alsochannel")) + run_async(slack_buffer.post_message(args[0], broadcast)) + elif isinstance(slack_buffer, SlackConversation): + split_args = args[0].split(" ", 1) + if len(split_args) < 2: + print_error( + 'Too few arguments for command "/slack reply" (help on command: /help slack reply)' + ) + 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 + ) + ) + + def print_uncaught_error(error: UncaughtError, detailed: bool, options: Options): weechat.prnt("", f" {error.id} ({error.time}): {error.exception}") if detailed: diff --git a/slack/slack_api.py b/slack/slack_api.py index 7ce919f..0f315a8 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -333,6 +333,7 @@ class SlackApi(SlackApiCommon): conversation: SlackConversation, text: str, thread_ts: Optional[SlackTs] = None, + broadcast: bool = False, ): method = "chat.postMessage" params: Params = { @@ -343,6 +344,7 @@ class SlackApi(SlackApiCommon): } if thread_ts is not None: params["thread_ts"] = thread_ts + params["reply_broadcast"] = broadcast response: SlackGenericResponse = await self._fetch(method, params) if response["ok"] is False: raise SlackApiError(self.workspace, method, response, params) diff --git a/slack/slack_thread.py b/slack/slack_thread.py index 9f1cda5..6063fd2 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -141,5 +141,5 @@ class SlackThread(SlackBuffer): self.parent.conversation, self.parent.ts, last_read_line_ts ) - async def post_message(self, text: str) -> None: + async def post_message(self, text: str, broadcast: bool = False) -> None: await self._api.chat_post_message(self.conversation, text, self.parent.ts) |