diff options
-rw-r--r-- | LICENSE | 21 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | wee_slack.py | 52 |
3 files changed, 64 insertions, 20 deletions
@@ -0,0 +1,21 @@ +Copyright (c) 2014-2016 Ryan Huber <rhuber@gmail.com> +Copyright (c) 2015-2016 Tollef Fog Heen <tfheen@err.no> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -44,7 +44,7 @@ In Development Dependencies ------------ - * WeeChat 1.3+ http://weechat.org/ + * WeeChat 1.3+ http://weechat.org/ * websocket-client https://pypi.python.org/pypi/websocket-client/ Setup @@ -101,7 +101,7 @@ If you don't want to store your API token in plaintext you can use the secure fe ``` ##### Optional: If you would like to connect to multiple groups, use the above command with multiple tokens separated by commas. (NO SPACES) - + ``` /set plugins.var.python.slack_extension.slack_api_token [token1],[token2],[token3] ``` @@ -170,6 +170,11 @@ Turn off colorized nicks: /set plugins.var.python.slack_extension.colorize_nicks 0 ``` +Turn on colorized messages (messages match nick color): +``` +/set plugins.var.python.slack_extension.colorize_nicks 1 +``` + Set channel prefix to something other than my-slack-subdomain.slack.com (e.g. when using buffers.pl): ``` /set plugins.var.python.slack_extension.server_alias.my-slack-subdomain "mysub" @@ -211,4 +216,4 @@ wee-slack is provided without any warranty whatsoever, but you are welcome to as - + diff --git a/wee_slack.py b/wee_slack.py index cd37f59..dfa2315 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -329,6 +329,8 @@ class SlackServer(object): tags = "no_highlight,notify_none,logger_backlog_end" else: tags = "" + if user == "SYSTEM": + user = w.config_string(w.config_get('weechat.look.prefix_network')) if self.buffer: w.prnt_date_tags(self.buffer, 0, tags, "{}\t{}".format(user, message)) else: @@ -612,19 +614,21 @@ class Channel(object): """ set_read_marker = False time_float = float(time) + tags = "nick_" + user + # XXX: we should not set log1 for robots. if time_float != 0 and self.last_read >= time_float: - tags = "no_highlight,notify_none,logger_backlog_end" + tags += ",no_highlight,notify_none,logger_backlog_end" set_read_marker = True elif message.find(self.server.nick.encode('utf-8')) > -1: - tags = "notify_highlight" + tags = ",notify_highlight,log1" elif user != self.server.nick and self.name in self.server.users: - tags = "notify_private,notify_message" + tags = ",notify_private,notify_message,log1" elif self.muted: - tags = "no_highlight,notify_none,logger_backlog_end" + tags = ",no_highlight,notify_none,logger_backlog_end" elif user in [x.strip() for x in w.prefix("join"), w.prefix("quit")]: - tags = "irc_smart_filter" + tags = ",irc_smart_filter" else: - tags = "notify_message" + tags = ",notify_message,log1" #don't write these to local log files #tags += ",no_log" time_int = int(time_float) @@ -652,11 +656,16 @@ class Channel(object): chat_color = w.config_string(w.config_get('weechat.color.chat')) if type(message) is not unicode: message = message.decode('UTF-8', 'replace') + curr_color = w.color(chat_color) + if colorize_nicks and colorize_messages and self.server.users.find(user): + curr_color = self.server.users.find(user).color + message = curr_color + message for user in self.server.users: if user.name in message: message = user.name_regex.sub( - r'\1\2{}\3'.format(user.formatted_name() + w.color(chat_color)), + r'\1\2{}\3'.format(user.formatted_name() + curr_color), message) + message = HTMLParser.HTMLParser().unescape(message) data = u"{}\t{}".format(name, message).encode('utf-8') w.prnt_date_tags(self.channel_buffer, time_int, tags, data) @@ -1382,7 +1391,7 @@ def process_team_join(message_json): server = servers.find(message_json["_server"]) item = message_json["user"] server.add_user(User(server, item["name"], item["id"], item["presence"])) - server.buffer_prnt(server.buffer, "New user joined: {}".format(item["name"])) + server.buffer_prnt("New user joined: {}".format(item["name"])) def process_manual_presence_change(message_json): process_presence_change(message_json) @@ -1415,7 +1424,7 @@ def process_channel_created(message_json): server.channels.find(message_json["channel"]["name"]).open(False) else: item = message_json["channel"] - server.add_channel(Channel(server, item["name"], item["id"], False)) + server.add_channel(Channel(server, item["name"], item["id"], False, prepend_name="#")) server.buffer_prnt("New channel created: {}".format(item["name"])) @@ -1508,7 +1517,7 @@ def process_im_created(message_json): else: item = message_json["channel"] server.add_channel(DmChannel(server, channel_name, item["id"], item["is_open"], item["last_read"])) - server.buffer_prnt("New channel created: {}".format(item["name"])) + server.buffer_prnt("New direct message channel created: {}".format(item["name"])) def process_user_typing(message_json): @@ -1699,22 +1708,27 @@ def unwrap_attachments(message_json, text_before): # Attachments should be rendered roughly like: # # $pretext - # $title ($title_link) OR $from_url - # $text + # $author: (if rest of line is non-empty) $title ($title_link) OR $from_url + # $author: (if no $author on previous line) $text # $fields t = [] + prepend_title_text = '' + if 'author_name' in attachment: + prepend_title_text = attachment['author_name'] + ": " if 'pretext' in attachment: t.append(attachment['pretext']) if "title" in attachment: if 'title_link' in attachment: - t.append('%s (%s)' % (attachment["title"], attachment["title_link"],)) + t.append('%s%s (%s)' % (prepend_title_text, attachment["title"], attachment["title_link"],)) else: - t.append(attachment["title"]) + t.append(prepend_title_text + attachment["title"]) + prepend_title_text = '' elif "from_url" in attachment: t.append(attachment["from_url"]) if "text" in attachment: tx = re.sub(r' *\n[\n ]+', '\n', attachment["text"]) - t.append(tx) + t.append(prepend_title_text + tx) + prepend_title_text = '' if 'fields' in attachment: for f in attachment['fields']: if f['title'] != '': @@ -2111,7 +2125,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 + unfurl_ignore_alt_text, colorize_messages slack_api_token = w.config_get_plugin("slack_api_token") @@ -2120,6 +2134,7 @@ def config_changed_cb(data, option, value): distracting_channels = [x.strip() for x in w.config_get_plugin("distracting_channels").split(',')] colorize_nicks = w.config_get_plugin('colorize_nicks') == "1" + colorize_messages = w.config_get_plugin("colorize_messages") == "1" debug_mode = w.config_get_plugin("debug_mode").lower() if debug_mode != '' and debug_mode != 'false': create_slack_debug_buffer() @@ -2184,6 +2199,8 @@ if __name__ == "__main__": w.config_set_plugin('debug_mode', "") if not w.config_get_plugin('colorize_nicks'): w.config_set_plugin('colorize_nicks', "1") + if not w.config_get_plugin('colorize_messages'): + w.config_set_plugin('colorize_messages', "0") if not w.config_get_plugin('colorize_private_chats'): w.config_set_plugin('colorize_private_chats', "0") if not w.config_get_plugin('trigger_value'): @@ -2193,7 +2210,8 @@ if __name__ == "__main__": if not w.config_get_plugin('switch_buffer_on_join'): w.config_set_plugin('switch_buffer_on_join', "1") - w.config_option_unset('channels_not_on_current_server_color') + if w.config_get_plugin('channels_not_on_current_server_color'): + w.config_option_unset('channels_not_on_current_server_color') # Global var section slack_debug = None |