aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2016-03-11 15:52:11 +0000
committerRyan Huber <rhuber@gmail.com>2016-03-11 15:52:11 +0000
commit9c724c32173152101d2276a0ffff42803ec29180 (patch)
treebee617a52252c07bf54346b1b7e2aeeba835db9c /wee_slack.py
parentd5bb96beb3c3c00d3bc8230c4927e176c69c9771 (diff)
parent2c741e41b219bdaaecf78399933d15418f49fd7f (diff)
downloadwee-slack-9c724c32173152101d2276a0ffff42803ec29180.tar.gz
Merge pull request #175 from trygveaa/feature/send-reactions
Support adding and removing reactions
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 46643ec..4593e65 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -336,13 +336,18 @@ 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('+'):
- channel = channels.find(buffer)
+ channel = channels.find(buffer)
+ reaction = re.match("(\d*)(\+|-):(.*):", data)
+ if not reaction and not data.startswith('s/'):
channel.send_message(data)
#channel.buffer_prnt(channel.server.nick, data)
+ elif reaction:
+ if reaction.group(2) == "+":
+ channel.send_add_reaction(int(reaction.group(1) or 1), reaction.group(3))
+ elif reaction.group(2) == "-":
+ channel.send_remove_reaction(int(reaction.group(1) or 1), reaction.group(3))
elif data.count('/') == 3:
old, new = data.split('/')[1:3]
- channel = channels.find(buffer)
channel.change_previous_message(old.decode("utf-8"), new.decode("utf-8"))
channel.mark_read(True)
return w.WEECHAT_RC_ERROR
@@ -706,6 +711,18 @@ class Channel(object):
self.change_message(ts)
return True
+ def send_add_reaction(self, msg_number, reaction):
+ self.send_change_reaction("reactions.add", msg_number, reaction)
+
+ def send_remove_reaction(self, msg_number, reaction):
+ self.send_change_reaction("reactions.remove", msg_number, reaction)
+
+ def send_change_reaction(self, method, 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, method, data)
+
def change_previous_message(self, old, new):
message = self.my_last_message()
if new == "" and old == "":