diff options
author | Aidan Epstein <aidan@jmad.org> | 2020-03-25 20:15:13 -0700 |
---|---|---|
committer | Aidan Epstein <aidan@jmad.org> | 2020-03-25 20:15:13 -0700 |
commit | 8a2125389dcb8239072313b00d609d7233336328 (patch) | |
tree | 5933ba9b038d03459ce8f455f2d475903f1c735a | |
parent | b61955f0000654e20173c3d77ca5c8ce37c004d6 (diff) | |
download | wee-slack-8a2125389dcb8239072313b00d609d7233336328.tar.gz |
Refactor command_(un)subscribe.
-rw-r--r-- | wee_slack.py | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/wee_slack.py b/wee_slack.py index 83ba3e3..494e964 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4130,14 +4130,7 @@ def command_thread(data, current_buffer, args): command_thread.completion = '%(threads)' -@slack_buffer_required -@utf8_decode -def command_subscribe(data, current_buffer, args): - """ - /slack subscribe <thread> - Subscribe to a thread, so that you are alerted to new messages. When in a - thread buffer, you can omit the thread id. - """ +def subscribe_helper(current_buffer, args, usage, api): channel = EVENTROUTER.weechat_controller.buffers[current_buffer] team = channel.team @@ -4146,14 +4139,25 @@ def command_subscribe(data, current_buffer, args): elif isinstance(channel, SlackThreadChannel): msg = channel.parent_message else: - w.prnt('', 'Usage: /slack subscribe <thread>') + w.prnt('', usage) return w.WEECHAT_RC_ERROR - s = SlackRequest(team, "subscriptions.thread.add", + s = SlackRequest(team, api, {"channel": channel.identifier, "thread_ts": msg.ts}, channel=channel) EVENTROUTER.receive(s) return w.WEECHAT_RC_OK_EAT + +@slack_buffer_required +@utf8_decode +def command_subscribe(data, current_buffer, args): + """ + /slack subscribe <thread> + Subscribe to a thread, so that you are alerted to new messages. When in a + thread buffer, you can omit the thread id. + """ + return subscribe_helper(current_buffer, args, 'Usage: /slack subscribe <thread>', "subscriptions.thread.add") + command_subscribe.completion = '%(threads)' @@ -4166,23 +4170,9 @@ def command_unsubscribe(data, current_buffer, args): you are not alerted to new messages. When in a thread buffer, you can omit the thread id. """ - channel = EVENTROUTER.weechat_controller.buffers[current_buffer] - team = channel.team - - if args: - msg = get_msg_from_id(channel, args) - elif isinstance(channel, SlackThreadChannel): - msg = channel.parent_message - else: - w.prnt('', 'Usage: /slack subscribe <thread>') - return w.WEECHAT_RC_ERROR - - s = SlackRequest(team, "subscriptions.thread.remove", - {"channel": channel.identifier, "thread_ts": msg.ts}, channel=channel) - EVENTROUTER.receive(s) - return w.WEECHAT_RC_OK_EAT + return subscribe_helper(current_buffer, args, 'Usage: /slack unsubscribe <thread>', "subscriptions.thread.remove") -command_subscribe.completion = '%(threads)' +command_unsubscribe.completion = '%(threads)' def handle_subscriptionsthreadmark(json, eventrouter, team, channel, metadata): |