diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2016-03-05 12:13:48 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2016-03-05 15:46:49 +0100 |
commit | 90bb2f09b494469284276e95dc76607c6f853a22 (patch) | |
tree | 34d2440c9ea082b43a97dcbe4c90a37d69c01a76 /wee_slack.py | |
parent | 5946a4a109dcc1474ab53ccc9e2025cb6ed88867 (diff) | |
download | wee-slack-90bb2f09b494469284276e95dc76607c6f853a22.tar.gz |
Add support for sending a reaction
A reaction can be added to the last message in the channel by writing
+:reaction:
Where reaction is the name of the reaction. This is the same syntax that
Slacks web interface uses.
Additionally, it supports sending a reaction to an earlier message by
prefixing the text with a number. The number is the number of the
message to add a reaction to, counting from the bottom. E.g. 1 is the
last message (same as without a number), 2 is the one before etc.
This fixes #155.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index e3df8af..c43f55d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -324,10 +324,14 @@ class SlackServer(object): #w.prnt("", "%s\t%s" % (user, message)) def buffer_input_cb(b, buffer, data): - if not data.startswith('s/') or data.startswith('+'): + reaction = re.match("(\d*)\+:(.*):", data) + if not reaction and not data.startswith('s/'): channel = channels.find(buffer) channel.send_message(data) #channel.buffer_prnt(channel.server.nick, data) + elif reaction: + channel = channels.find(buffer) + channel.send_reaction(int(reaction.group(1) or 1), reaction.group(2)) elif data.count('/') == 3: old, new = data.split('/')[1:3] channel = channels.find(buffer) @@ -694,6 +698,12 @@ class Channel(object): self.change_message(ts) return True + def send_reaction(self, msg_number, reaction): + if 0 < msg_number < len(self.messages): + timestamp = self.messages[-msg_number].message_json["ts"] + data = {"channel": self.identifier, "timestamp": timestamp, "name": reaction} + async_slack_api_request(self.server.domain, self.server.token, 'reactions.add', data) + def change_previous_message(self, old, new): message = self.my_last_message() if new == "" and old == "": |