diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-31 01:15:29 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | c47aeb31b5f6f1843c0505e539fdff3352c76f80 (patch) | |
tree | 4e84b08b38549549fb0ba9f50baddb8a68d0ceb4 /slack/commands.py | |
parent | 994e2d246fc09ed942a871696ccae1bdc3002217 (diff) | |
download | wee-slack-c47aeb31b5f6f1843c0505e539fdff3352c76f80.tar.gz |
Support thread hash completion
Diffstat (limited to 'slack/commands.py')
-rw-r--r-- | slack/commands.py | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/slack/commands.py b/slack/commands.py index 8e807e1..a08799a 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -271,7 +271,7 @@ def command_slack_workspace_del( ) -@weechat_command(min_args=1) +@weechat_command("%(threads)", min_args=1) def command_slack_thread( buffer: str, args: List[str], options: Dict[str, Optional[str]] ): @@ -392,9 +392,13 @@ def command_cb(data: str, buffer: str, args: str) -> int: return weechat.WEECHAT_RC_OK -def completion_list_add(completion: str, word: str, nick_completion: int, where: str): +def completion_list_add( + completion: str, word: str, nick_completion: int, where: str, buffer: str +): if word == "%(slack_workspaces)": - completion_slack_workspaces_cb("", "slack_workspaces", "", completion) + completion_slack_workspaces_cb("", "slack_workspaces", buffer, completion) + elif word == "%(threads)": + completion_thread_hashes_cb("", "threads", buffer, completion) else: # TODO: Consider WeeChat verison support, in < 2.9 one must use hook_completion_list_add weechat.completion_list_add(completion, word, nick_completion, where) @@ -421,11 +425,13 @@ def completion_slack_workspace_commands_cb( for match in matching_cmds: cmd_arg = match.split(" ") completion_list_add( - completion, cmd_arg[0], 0, weechat.WEECHAT_LIST_POS_SORT + completion, cmd_arg[0], 0, weechat.WEECHAT_LIST_POS_SORT, buffer ) else: for arg in command.completion.split("|"): - completion_list_add(completion, arg, 0, weechat.WEECHAT_LIST_POS_SORT) + completion_list_add( + completion, arg, 0, weechat.WEECHAT_LIST_POS_SORT, buffer + ) return weechat.WEECHAT_RC_OK @@ -440,6 +446,31 @@ def completion_irc_channels_cb( return weechat.WEECHAT_RC_OK +def completion_thread_hashes_cb( + data: str, completion_item: str, buffer: str, completion: str +) -> int: + slack_buffer = shared.buffers.get(buffer) + if not isinstance(slack_buffer, SlackConversation): + return weechat.WEECHAT_RC_OK + + message_tss = sorted(slack_buffer.message_hashes.keys()) + messages = [slack_buffer.messages.get(ts) for ts in message_tss] + thread_messages = [ + message + for message in messages + if message is not None and message.is_thread_parent + ] + for message in thread_messages: + weechat.completion_list_add( + completion, message.hash, 0, weechat.WEECHAT_LIST_POS_BEGINNING + ) + for message in thread_messages: + weechat.completion_list_add( + completion, f"${message.hash}", 0, weechat.WEECHAT_LIST_POS_BEGINNING + ) + return weechat.WEECHAT_RC_OK + + def complete_input(slack_buffer: SlackBuffer, query: str): if ( slack_buffer.completion_context == "ACTIVE_COMPLETION" @@ -543,6 +574,12 @@ def register_commands(): get_callback_name(completion_irc_channels_cb), "", ) + weechat.hook_completion( + "threads", + "complete thread ids for slack", + get_callback_name(completion_thread_hashes_cb), + "", + ) for cmd, command in commands.items(): if command.top_level: |