diff options
-rw-r--r-- | _pytest/conftest.py | 2 | ||||
-rw-r--r-- | wee_slack.py | 46 |
2 files changed, 29 insertions, 19 deletions
diff --git a/_pytest/conftest.py b/_pytest/conftest.py index 0259ac2..7a6f39a 100644 --- a/_pytest/conftest.py +++ b/_pytest/conftest.py @@ -69,6 +69,8 @@ class FakeWeechat(): return "testuser" def buffer_new(*args): return "0x8a8a8a8b" + def prefix(self, type): + return "" def __getattr__(self, name): def method(*args): pass diff --git a/wee_slack.py b/wee_slack.py index e8b736c..3ad2b6a 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1631,18 +1631,15 @@ class SlackUser(object): self.color_name = color_name self.color = w.color(self.color_name) def update_color(self): - if config.colorize_nicks: - self.color_name = w.info_get('irc_nick_color_name', self.name.encode('utf-8')) - self.color = w.color(self.color_name) - else: - self.color = "" - self.color_name = "" + # This will automatically be none/"" if the user has disabled nick + # colourization. + self.color_name = w.info_get('nick_color_name', self.name.encode('utf-8')) + self.color = w.color(self.color_name) def formatted_name(self, prepend="", enable_color=True): - if config.colorize_nicks and enable_color: - print_color = self.color + if enable_color: + return self.color + prepend + self.name else: - print_color = "" - return print_color + prepend + self.name + return prepend + self.name class SlackBot(SlackUser): """ @@ -1675,6 +1672,13 @@ class SlackMessage(object): self.sender, self.sender_plain = senders[0], senders[1] self.suffix = '' self.ts = SlackTS(message_json['ts']) + text = self.message_json.get('text', '') + if text.startswith('_') and text.endswith('_') and not 'subtype' in message_json: + message_json['text'] = text[1:-1] + message_json['subtype'] = 'me_message' + if message_json.get('subtype') == 'me_message' and not message_json['text'].startswith(self.sender): + message_json['text'] = self.sender + ' ' + self.message_json['text'] + def __hash__(self): return hash(self.ts) def render(self, force=False): @@ -1951,6 +1955,7 @@ def process_message(message_json, eventrouter, store=True, **kwargs): ] if "thread_ts" in message_json and "reply_count" not in message_json: message_json["subtype"] = "thread_message" + subtype = message_json.get("subtype", None) if subtype and subtype in known_subtypes: f = eval('subprocess_' + subtype) @@ -1959,17 +1964,17 @@ def process_message(message_json, eventrouter, store=True, **kwargs): else: message = SlackMessage(message_json, team, channel) text = message.render() - dbg(text) + dbg("Rendered message: %s" % text) + dbg("Sender: %s (%s)" % (message.sender, message.sender_plain)) - # special case with actions. - if text.startswith("_") and text.endswith("_"): - text = text[1:-1] - if message.sender != channel.team.nick: - text = message.sender + " " + text + # Handle actions (/me). + # We don't use `subtype` here because creating the SlackMessage may + # have changed the subtype based on the detected message contents. + if message.message_json.get('subtype') == 'me_message': try: channel.unread_count_display += 1 except: - channel.unread_count_display += 1 + channel.unread_count_display = 1 channel.buffer_prnt(w.prefix("action").rstrip(), text, message.ts, tag_nick=message.sender_plain, **kwargs) else: @@ -2225,6 +2230,10 @@ def render(message_json, team, channel, force=False): text = text.replace("<", "<") text = text.replace(">", ">") text = text.replace("&", "&") + text = re.sub(r'(^| )\*([^*]+)\*([^a-zA-Z0-9_]|$)', + r'\1{}\2{}\3'.format(w.color('bold'), w.color('-bold')), text) + text = re.sub(r'(^| )_([^_]+)_([^a-zA-Z0-9_]|$)', + r'\1{}\2{}\3'.format(w.color('underline'), w.color('-underline')), text) if type(text) is not unicode: text = text.decode('UTF-8', 'replace') @@ -2245,7 +2254,7 @@ def linkify_text(message, team, channel): # function is only called on message send.. usernames = team.get_username_map() channels = team.get_channel_map() - message = message.split(' ') + message = message.replace('\x02', '*').replace('\x1F', '_').split(' ') for item in enumerate(message): targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1]) #print targets @@ -2910,7 +2919,6 @@ class PluginConfig(object): # TODO: setting descriptions. settings = { 'colorize_messages': 'false', - 'colorize_nicks': 'true', 'colorize_private_chats': 'false', 'debug_mode': 'false', 'debug_level': '3', |