aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2017-04-13 08:23:44 -0700
committerGitHub <noreply@github.com>2017-04-13 08:23:44 -0700
commitd96e41d18c1d30a9e34ef72306723a9a04e4153d (patch)
tree53d9706492bb24fafbed16a410b6b9293bfcfd32
parent0d74722da5943ce3adfb460e581c2485baa0be65 (diff)
parent521166bf08f1970c91c5da8c20109dd3199a1184 (diff)
downloadwee-slack-d96e41d18c1d30a9e34ef72306723a9a04e4153d.tar.gz
Merge pull request #287 from ToxicFrog/toxicfrog/action-support
Fix /me handling for sent and received messages
-rw-r--r--_pytest/conftest.py2
-rw-r--r--wee_slack.py22
2 files changed, 17 insertions, 7 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..9ef1f21 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1675,6 +1675,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 +1958,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 +1967,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: