aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md35
-rw-r--r--wee_slack.py51
2 files changed, 54 insertions, 32 deletions
diff --git a/README.md b/README.md
index 6b1bd3b..472ca20 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,7 @@ weechat
```
/set plugins.var.python.slack_extension.slack_api_token [YOUR_SLACK_TOKEN]
```
-^^ (find this at https://api.slack.com/web)
+^^ (find this at https://api.slack.com/web behind the "Generate test tokens" button)
If you don't want to store your API token in plaintext you can use the secure features of weechat:
@@ -167,38 +167,43 @@ Add a reaction to the nth last message. The number can be omitted and defaults t
3+:smile:
```
-Turn off colorized nicks:
+Set all read markers to a specific time:
```
-/set plugins.var.python.slack_extension.colorize_nicks 0
+/slack setallreadmarkers (time in epoch)
```
-Turn on colorized messages (messages match nick color):
+Upload a file to the current slack buffer:
```
-/set plugins.var.python.slack_extension.colorize_nicks 1
+/slack upload [file_path]
```
-Set channel prefix to something other than my-slack-subdomain.slack.com (e.g. when using buffers.pl):
+Debug mode:
```
-/set plugins.var.python.slack_extension.server_alias.my-slack-subdomain "mysub"
+/slack debug
```
-Set all read markers to a specific time:
+Optional settings
+-----------------
+
+Turn off colorized nicks:
```
-/slack setallreadmarkers (time in epoch)
+/set plugins.var.python.slack_extension.colorize_nicks 0
```
-Upload a file to the current slack buffer:
+Turn on colorized messages (messages match nick color):
```
-/slack upload [file_path]
+/set plugins.var.python.slack_extension.colorize_nicks 1
```
-Debug mode:
+Set channel prefix to something other than my-slack-subdomain.slack.com (e.g. when using buffers.pl):
```
-/slack debug
+/set plugins.var.python.slack_extension.server_alias.my-slack-subdomain "mysub"
```
-Optional settings
-----------------
+Show who added each reaction. Makes reactions appear like `[:smile:(@nick1,@nick2)]` instead of `[:smile:2]`.
+```
+/set plugins.var.python.slack_extension.show_reaction_nicks on
+```
Show typing notification in main bar (slack_typing_notice):
```
diff --git a/wee_slack.py b/wee_slack.py
index a792d48..072b06c 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -32,7 +32,7 @@ SCRIPT_DESC = "Extends weechat for typing notification/search/etc on slack.com"
BACKLOG_SIZE = 200
SCROLLBACK_SIZE = 500
-CACHE_VERSION = "3"
+CACHE_VERSION = "4"
SLACK_API_TRANSLATOR = {
"channel": {
@@ -132,6 +132,7 @@ class SlackServer(object):
def __init__(self, token):
self.nick = None
self.name = None
+ self.team = None
self.domain = None
self.server_buffer_name = None
self.login_data = None
@@ -213,6 +214,7 @@ class SlackServer(object):
def connected_to_slack(self, login_data):
if login_data["ok"]:
+ self.team = login_data["team"]["domain"]
self.domain = login_data["team"]["domain"] + ".slack.com"
dbg("connected to {}".format(self.domain))
self.identifier = self.domain
@@ -339,6 +341,8 @@ class SlackServer(object):
def buffer_input_cb(b, buffer, data):
channel = channels.find(buffer)
+ if not channel:
+ return w.WEECHAT_RC_OK_EAT
reaction = re.match("(\d*)(\+|-):(.*):", data)
if not reaction and not data.startswith('s/'):
channel.send_message(data)
@@ -419,6 +423,11 @@ class Channel(object):
w.buffer_set(self.channel_buffer, "localvar_set_type", 'private')
else:
w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel')
+ if self.server.alias:
+ w.buffer_set(self.channel_buffer, "localvar_set_server", self.server.alias)
+ else:
+ w.buffer_set(self.channel_buffer, "localvar_set_server", self.server.team)
+ w.buffer_set(self.channel_buffer, "localvar_set_channel", self.name)
w.buffer_set(self.channel_buffer, "short_name", self.name)
buffer_list_update_next()
@@ -541,7 +550,7 @@ class Channel(object):
return " ".join(message)
def set_topic(self, topic):
- topic = topic.encode('ascii', 'ignore')
+ topic = topic.encode('utf-8')
w.buffer_set(self.channel_buffer, "title", topic)
def open(self, update_remote=True):
@@ -711,17 +720,17 @@ class Channel(object):
self.buffer_redraw()
return True
- def add_reaction(self, ts, reaction):
+ def add_reaction(self, ts, reaction, user):
if self.has_message(ts):
message_index = self.messages.index(ts)
- self.messages[message_index].add_reaction(reaction)
+ self.messages[message_index].add_reaction(reaction, user)
self.change_message(ts)
return True
- def remove_reaction(self, ts, reaction):
+ def remove_reaction(self, ts, reaction, user):
if self.has_message(ts):
message_index = self.messages.index(ts)
- self.messages[message_index].remove_reaction(reaction)
+ self.messages[message_index].remove_reaction(reaction, user)
self.change_message(ts)
return True
@@ -933,23 +942,23 @@ class Message(object):
new_text = unicode(new_text, 'utf-8')
self.message_json["text"] = new_text
- def add_reaction(self, reaction):
+ def add_reaction(self, reaction, user):
if "reactions" in self.message_json:
found = False
for r in self.message_json["reactions"]:
if r["name"] == reaction:
- r["count"] += 1
+ r["users"].add(user)
found = True
if not found:
- self.message_json["reactions"].append({u"count": 1, u"name": reaction})
+ self.message_json["reactions"].append({u"name": reaction, u"users": {user}})
else:
- self.message_json["reactions"] = [{u"count": 1, u"name": reaction}]
+ self.message_json["reactions"] = [{u"name": reaction, u"users": {user}}]
- def remove_reaction(self, reaction):
+ def remove_reaction(self, reaction, user):
if "reactions" in self.message_json:
for r in self.message_json["reactions"]:
if r["name"] == reaction:
- r["count"] -= 1
+ r["users"].remove(user)
else:
pass
@@ -1571,14 +1580,14 @@ def process_error(message_json):
def process_reaction_added(message_json):
if message_json["item"].get("type") == "message":
channel = channels.find(message_json["item"]["channel"])
- channel.add_reaction(message_json["item"]["ts"], message_json["reaction"])
+ channel.add_reaction(message_json["item"]["ts"], message_json["reaction"], message_json["user"])
else:
dbg("Reaction to item type not supported: " + str(message_json))
def process_reaction_removed(message_json):
if message_json["item"].get("type") == "message":
channel = channels.find(message_json["item"]["channel"])
- channel.remove_reaction(message_json["item"]["ts"], message_json["reaction"])
+ channel.remove_reaction(message_json["item"]["ts"], message_json["reaction"], message_json["user"])
else:
dbg("Reaction to item type not supported: " + str(message_json))
@@ -1589,9 +1598,14 @@ def create_reaction_string(reactions):
else:
reaction_string = ' ['
for r in reactions:
- if r["count"] > 0:
+ if len(r["users"]) > 0:
count += 1
- reaction_string += ":{}:{} ".format(r["name"], r["count"])
+ if show_reaction_nicks:
+ nicks = [resolve_ref("@{}".format(user)) for user in r["users"]]
+ users = "({})".format(",".join(nicks))
+ else:
+ users = len(r["users"])
+ reaction_string += ":{}:{} ".format(r["name"], users)
reaction_string = reaction_string[:-1] + ']'
if count == 0:
reaction_string = ''
@@ -2165,7 +2179,7 @@ def create_slack_debug_buffer():
def config_changed_cb(data, option, value):
global slack_api_token, distracting_channels, colorize_nicks, colorize_private_chats, slack_debug, debug_mode, \
- unfurl_ignore_alt_text, colorize_messages
+ unfurl_ignore_alt_text, colorize_messages, show_reaction_nicks
slack_api_token = w.config_get_plugin("slack_api_token")
@@ -2179,6 +2193,7 @@ def config_changed_cb(data, option, value):
if debug_mode != '' and debug_mode != 'false':
create_slack_debug_buffer()
colorize_private_chats = w.config_string_to_boolean(w.config_get_plugin("colorize_private_chats"))
+ show_reaction_nicks = w.config_string_to_boolean(w.config_get_plugin("show_reaction_nicks"))
unfurl_ignore_alt_text = False
if w.config_get_plugin('unfurl_ignore_alt_text') != "0":
@@ -2249,6 +2264,8 @@ if __name__ == "__main__":
w.config_set_plugin('unfurl_ignore_alt_text', "0")
if not w.config_get_plugin('switch_buffer_on_join'):
w.config_set_plugin('switch_buffer_on_join', "1")
+ if not w.config_get_plugin('show_reaction_nicks'):
+ w.config_set_plugin('show_reaction_nicks', "0")
if w.config_get_plugin('channels_not_on_current_server_color'):
w.config_option_unset('channels_not_on_current_server_color')