diff options
-rw-r--r-- | _pytest/test_unfurl.py | 3 | ||||
-rw-r--r-- | wee_slack.py | 36 |
2 files changed, 23 insertions, 16 deletions
diff --git a/_pytest/test_unfurl.py b/_pytest/test_unfurl.py index 8c7f96e..9af7cf2 100644 --- a/_pytest/test_unfurl.py +++ b/_pytest/test_unfurl.py @@ -15,6 +15,9 @@ unfurl_map = [ { "input": "foo <#C2147483705|#otherchannel> foo", "output": "foo #otherchannel foo", }, + { "input": "foo <#C2147483705> foo", + "output": "foo #testchan foo", + }, { "input": "url: <https://example.com|example> suffix", "output": "url: https://example.com (example) suffix", }, diff --git a/wee_slack.py b/wee_slack.py index 885dc3d..b550d05 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1465,33 +1465,37 @@ def unwrap_attachments(message_json): # attachment_text = attachment_text.encode('ascii', 'ignore') return attachment_text +def resolve_ref(ref): + if ref.startswith('@U'): + if users.find(ref[1:]): + try: + return "@{}".format(users.find(ref[1:]).name) + except: + dbg("NAME: {}".format(ref)) + elif ref.startswith('#C'): + if channels.find(ref[1:]): + try: + return "{}".format(channels.find(ref[1:]).name) + except: + dbg("CHANNEL: {}".format(ref)) + + # Something else, just return as-is + return ref + def unfurl_ref(ref, ignore_alt_text=False): id = ref.split('|')[0] display_text = ref if ref.find('|') > -1: if ignore_alt_text: - if id.startswith('@U'): - if users.find(id[1:]): - try: - display_text = "@{}".format(users.find(id[1:]).name) - except: - dbg("NAME: {}".format(ref)) - elif id.startswith('#C'): - if channels.find(id[1:]): - try: - display_text = "{}".format(channels.find(id[1:]).name) - except: - dbg("CHANNEL: {}".format(ref)) - else: - # This is probably a URL, we don't want to ignore anything - # XXX: fix up nicer formatting to generate more clickable urls - display_text = ref + display_text = resolve_ref(id) else: if id.startswith("#C") or id.startswith("@U"): display_text = ref.split('|')[1] else: url, desc = ref.split('|', 1) display_text = "{} ({})".format(url, desc) + else: + display_text = resolve_ref(ref) return display_text def unfurl_refs(text, ignore_alt_text=False): |