From 5c21c4b441e31a35eb95315cc6880cc357cf3b8d Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sat, 29 Feb 2020 11:36:25 -0800 Subject: Add ability to broadcast a thread message to the rest of the channel. This adds an optional -broadcast parameter to /reply and a /slack broadcast command. Also update completions for /reply. --- wee_slack.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 2239ccd..c72b22c 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2263,7 +2263,7 @@ class SlackThreadChannel(SlackChannelCommon): def main_message_keys_reversed(self): return (message.ts for message in reversed(self.parent_message.submessages)) - def send_message(self, message, subtype=None): + def send_message(self, message, subtype=None, request_dict_ext={}): if subtype == 'me_message': w.prnt("", "ERROR: /me is not supported in threads") return w.WEECHAT_RC_ERROR @@ -2273,6 +2273,7 @@ class SlackThreadChannel(SlackChannelCommon): "channel": self.parent_message.channel.identifier, "thread_ts": str(self.parent_message.ts), "user": self.team.myidentifier} + request.update(request_dict_ext) self.team.send_to_websocket(request) def open(self, update_remote=True): @@ -4000,19 +4001,39 @@ def command_thread(data, current_buffer, args): command_thread.completion = '%(threads)' + +@slack_buffer_required +@utf8_decode +def command_broadcast(data, current_buffer, args): + """ + /slack broadcast + When in a thread buffer, send a message while broadcasting to the rest of + the channel. + """ + channel = EVENTROUTER.weechat_controller.buffers[current_buffer] + + channel.send_message(args, request_dict_ext={'reply_broadcast': True}) + return w.WEECHAT_RC_OK_EAT + + @slack_buffer_required @utf8_decode def command_reply(data, current_buffer, args): """ - /reply + /reply [-broadcast] Reply in a thread on the message. Specify either the message id or a count upwards to the message from the last message. """ channel = EVENTROUTER.weechat_controller.buffers[current_buffer] try: msg_id, text = args.split(None, 1) + if msg_id == "-broadcast": + msg_id, text = text.split(None, 1) + broadcast = True + else: + broadcast = False except ValueError: - w.prnt('', 'Usage: /reply ') + w.prnt('', 'Usage: /reply [-broadcast] ') return w.WEECHAT_RC_OK_EAT msg = get_msg_from_id(channel, msg_id) @@ -4025,10 +4046,10 @@ def command_reply(data, current_buffer, args): w.prnt('', 'ERROR: Invalid id given, must be a number greater than 0 or an existing id') return w.WEECHAT_RC_OK_EAT - channel.send_message(text, request_dict_ext={'thread_ts': parent_id}) + channel.send_message(text, request_dict_ext={'thread_ts': parent_id, 'reply_broadcast': broadcast}) return w.WEECHAT_RC_OK_EAT -command_reply.completion = '%(threads)' +command_reply.completion = '-broadcast %(threads)||%(threads)' @slack_buffer_required -- cgit From bdf83ddf0b1842c26c9122603df342c96db87a7b Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sun, 1 Mar 2020 12:43:53 -0800 Subject: Change reply argument from -broadcast to -alsochannel, remove command_broadcast, and change reply to work without the id when in a thread buffer. --- wee_slack.py | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index c72b22c..8b411b6 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4002,41 +4002,37 @@ def command_thread(data, current_buffer, args): command_thread.completion = '%(threads)' -@slack_buffer_required -@utf8_decode -def command_broadcast(data, current_buffer, args): - """ - /slack broadcast - When in a thread buffer, send a message while broadcasting to the rest of - the channel. - """ - channel = EVENTROUTER.weechat_controller.buffers[current_buffer] - - channel.send_message(args, request_dict_ext={'reply_broadcast': True}) - return w.WEECHAT_RC_OK_EAT - - @slack_buffer_required @utf8_decode def command_reply(data, current_buffer, args): """ - /reply [-broadcast] - Reply in a thread on the message. Specify either the message id - or a count upwards to the message from the last message. + /reply [-alsochannel] + Reply in a thread on the message. Specify either the message id, a count + upwards to the message from the last message, or, if you are already in a + thread, nothing. """ channel = EVENTROUTER.weechat_controller.buffers[current_buffer] + parts = args.split(None, 1) + if parts[0] == "-alsochannel": + args = parts[1] + broadcast = True + else: + broadcast = False + try: - msg_id, text = args.split(None, 1) - if msg_id == "-broadcast": - msg_id, text = text.split(None, 1) - broadcast = True + if isinstance(channel, SlackThreadChannel): + text = args else: - broadcast = False + msg_id, text = args.split(None, 1) except ValueError: - w.prnt('', 'Usage: /reply [-broadcast] ') + w.prnt('', 'Usage: /reply [-alsochannel] ') return w.WEECHAT_RC_OK_EAT - msg = get_msg_from_id(channel, msg_id) + if isinstance(channel, SlackThreadChannel): + msg = channel.parent_message + else: + msg = get_msg_from_id(channel, msg_id) + if msg: parent_id = str(msg.ts) elif msg_id.isdigit() and int(msg_id) >= 1: @@ -4049,7 +4045,7 @@ def command_reply(data, current_buffer, args): channel.send_message(text, request_dict_ext={'thread_ts': parent_id, 'reply_broadcast': broadcast}) return w.WEECHAT_RC_OK_EAT -command_reply.completion = '-broadcast %(threads)||%(threads)' +command_reply.completion = '-alsochannel %(threads)||%(threads)' @slack_buffer_required -- cgit From 719eca612cf037a3ccf7e5b1fc99b6f1182af557 Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sun, 1 Mar 2020 13:42:10 -0800 Subject: Clarify documentation of /reply command, and refactor msg logic. --- wee_slack.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 8b411b6..7f01550 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4006,10 +4006,17 @@ command_thread.completion = '%(threads)' @utf8_decode def command_reply(data, current_buffer, args): """ + When in a channel buffer: /reply [-alsochannel] - Reply in a thread on the message. Specify either the message id, a count - upwards to the message from the last message, or, if you are already in a - thread, nothing. + Reply in a thread on the message. Specify either the message id or a count + upwards to the message from the last message. + + When in a thread buffer: + /reply [-alsochannel] + Reply to the current thread. This can be used to send the reply to the + rest of the channel. + + In either case, -alsochannel also sends the reply to the parent channel. """ channel = EVENTROUTER.weechat_controller.buffers[current_buffer] parts = args.split(None, 1) @@ -4019,18 +4026,15 @@ def command_reply(data, current_buffer, args): else: broadcast = False - try: - if isinstance(channel, SlackThreadChannel): - text = args - else: - msg_id, text = args.split(None, 1) - except ValueError: - w.prnt('', 'Usage: /reply [-alsochannel] ') - return w.WEECHAT_RC_OK_EAT - if isinstance(channel, SlackThreadChannel): + text = args msg = channel.parent_message else: + try: + msg_id, text = args.split(None, 1) + except ValueError: + w.prnt('', 'Usage (when in a channel buffer): /reply [-alsochannel] ') + return w.WEECHAT_RC_OK_EAT msg = get_msg_from_id(channel, msg_id) if msg: -- cgit From cf31ac6b9245e7b84ee26d6a65e978781a1b7b09 Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sun, 1 Mar 2020 14:42:44 -0800 Subject: Fix /help reply display. --- wee_slack.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 7f01550..e9f791d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4006,6 +4006,8 @@ command_thread.completion = '%(threads)' @utf8_decode def command_reply(data, current_buffer, args): """ + /reply [-alsochannel] [] + When in a channel buffer: /reply [-alsochannel] Reply in a thread on the message. Specify either the message id or a count -- cgit