aboutsummaryrefslogtreecommitdiffstats
path: root/slack/commands.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-21 22:54:35 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit9e99c1d54eec2ab49a1a6a749bec1def8d182927 (patch)
treedd770a44568a0dff2ee7b5b005ff6b2fe3baa04a /slack/commands.py
parenta48c2ae60ea785a9c710833ed93f935ea5fdaff1 (diff)
downloadwee-slack-9e99c1d54eec2ab49a1a6a749bec1def8d182927.tar.gz
Support completing @nicks in current buffer
Adds all known nicks in the current buffer with an @ prefix to the nicks completion. Disables the API search based nick completion for now until it's working properly. It currently doesn't have any context of which conversation/thread you are in, so you often get other nicks than the one you want to complete first. Additionally, it doesn't work with OAuth tokens.
Diffstat (limited to 'slack/commands.py')
-rw-r--r--slack/commands.py30
1 files changed, 27 insertions, 3 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),