aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2015-08-29 18:00:42 +0200
committerTollef Fog Heen <tfheen@err.no>2015-08-29 18:00:42 +0200
commitd46b8366cb1e35fd939b4e3e6f8bf087b2208c1b (patch)
tree9c22d7cfc3de3b8fc21c7bf14b91e5faa479a7dc /wee_slack.py
parent5567f3f5b14445820b4a08f076b193a6f4c173c7 (diff)
downloadwee-slack-d46b8366cb1e35fd939b4e3e6f8bf087b2208c1b.tar.gz
Handle unfurling of things with no alt text correctly as well
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py36
1 files changed, 20 insertions, 16 deletions
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):