aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/conftest.py2
-rw-r--r--wee_slack.py28
2 files changed, 22 insertions, 8 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 9b8892c..3ad2b6a 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1672,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):
@@ -1948,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)
@@ -1956,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:
@@ -2222,6 +2230,10 @@ def render(message_json, team, channel, force=False):
text = text.replace("&lt;", "<")
text = text.replace("&gt;", ">")
text = text.replace("&amp;", "&")
+ 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')
@@ -2242,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