aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan Epstein <aidan@jmad.org>2020-02-29 11:36:25 -0800
committerAidan Epstein <aidan@jmad.org>2020-02-29 12:08:08 -0800
commit5c21c4b441e31a35eb95315cc6880cc357cf3b8d (patch)
treec43a8c3bc2849cba3c985691fce9233dcf3f81c2
parent5c4fc0b9e9a00f46bb8d069b5f584c69108b1828 (diff)
downloadwee-slack-5c21c4b441e31a35eb95315cc6880cc357cf3b8d.tar.gz
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.
-rw-r--r--wee_slack.py31
1 files changed, 26 insertions, 5 deletions
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 <text>
+ 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 <count/message_id> <text>
+ /reply [-broadcast] <count/message_id> <text>
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 <count/id> <message>')
+ w.prnt('', 'Usage: /reply [-broadcast] <count/id> <message>')
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