aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wee_slack.py24
1 files changed, 7 insertions, 17 deletions
diff --git a/wee_slack.py b/wee_slack.py
index c8d24ee..9760b28 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1671,24 +1671,14 @@ def unfurl_ref(ref, ignore_alt_text=False):
def unfurl_refs(text, ignore_alt_text=False):
"""
- Worst code ever written. this needs work
+ input : <@U096Q7CQM|someuser> has joined the channel
+ ouput : someuser has joined the channel
"""
- if text and text.find('<') > -1:
- end = 0
- newtext = u""
- while text.find('<') > -1:
- # Prepend prefix
- newtext += text[:text.find('<')]
- text = text[text.find('<'):]
- end = text.find('>')
- if end == -1:
- newtext += text
- break
- # Format thingabob
- newtext += unfurl_ref(text[1:end], ignore_alt_text)
- text = text[end+1:]
- newtext += text
- return newtext
+ # Find all string enclosed by <> and starting with an @
+ matches = re.findall(r"(<@(?:\S*)>)", text)
+ for m in matches:
+ # Replace them with human readable strings
+ text = text.replace(m, unfurl_ref(m[1:-1]))
return text