aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py
index b1e0820..cff2c01 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -284,7 +284,7 @@ class SlackServer(object):
def create_slack_mappings(self, data):
for item in data["users"]:
- self.add_user(User(self, item["name"], item["id"], item["presence"], item["deleted"]))
+ self.add_user(User(self, item["name"], item["id"], item["presence"], item["deleted"], is_bot=item.get('is_bot', False)))
for item in data["bots"]:
self.add_bot(Bot(self, item["name"], item["id"], item["deleted"]))
@@ -635,7 +635,10 @@ class Channel(object):
if self.channel_buffer:
prefix_same_nick = w.config_string(w.config_get('weechat.look.prefix_same_nick'))
if user == self.last_active_user and prefix_same_nick != "":
- name = prefix_same_nick
+ if colorize_nicks and self.server.users.find(user):
+ name = self.server.users.find(user).color + prefix_same_nick
+ else:
+ name = prefix_same_nick
else:
nick_prefix = w.config_string(w.config_get('weechat.look.nick_prefix'))
nick_suffix = w.config_string(w.config_get('weechat.look.nick_suffix'))
@@ -653,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)
@@ -796,7 +804,7 @@ class DmChannel(Channel):
class User(object):
- def __init__(self, server, name, identifier, presence="away", deleted=False):
+ def __init__(self, server, name, identifier, presence="away", deleted=False, is_bot=False):
self.server = server
self.name = name
self.identifier = identifier
@@ -806,6 +814,7 @@ class User(object):
self.channel_buffer = w.info_get("irc_buffer", "{}.{}".format(domain, self.name))
self.update_color()
self.name_regex = re.compile(r"([\W]|\A)(@{0,1})" + self.name + "('s|[^'\w]|\Z)")
+ self.is_bot = is_bot
if deleted:
return
@@ -1787,7 +1796,11 @@ def get_user(message_json, server):
if 'bot_id' in message_json and message_json['bot_id'] is not None:
name = u"{} :]".format(server.bots.find(message_json["bot_id"]).formatted_name())
elif 'user' in message_json:
- name = server.users.find(message_json['user']).name
+ u = server.users.find(message_json['user'])
+ if u.is_bot:
+ name = u"{} :]".format(u.formatted_name())
+ else:
+ name = u.name
elif 'username' in message_json:
name = u"-{}-".format(message_json["username"])
elif 'service_name' in message_json:
@@ -2117,7 +2130,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")
@@ -2126,6 +2139,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()
@@ -2190,6 +2204,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'):