aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2015-12-21 19:51:22 +0100
committerTollef Fog Heen <tfheen@err.no>2016-02-19 10:56:39 +0100
commit3c4e38c8133f9b4b6276d50d33ada1abfe84dec3 (patch)
treec1b8fa6c3df92580f2e7eeb20a73c47eb523b5f8 /wee_slack.py
parentefb41803ed9293f0724da2c93898abd481a3a908 (diff)
downloadwee-slack-3c4e38c8133f9b4b6276d50d33ada1abfe84dec3.tar.gz
Format more fields from attachments
This makes the formatting of attachments somewhat more verbose and makes it more similar to the web client. Downside is that it takes more vertical space.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 6172636..12b891a 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1642,14 +1642,36 @@ def unwrap_attachments(message_json, text_before):
attachment_text = ''
if "attachments" in message_json:
if text_before:
- attachment_text = u' --- '
+ attachment_text = u'\n'
for attachment in message_json["attachments"]:
+ # Attachments should be rendered roughly like:
+ #
+ # $pretext
+ # $title ($title_link) OR $from_url
+ # $text
+ # $fields
t = []
- if "from_url" in attachment and text_before is False:
- t.append(attachment['from_url'])
- if "fallback" in attachment:
+ if 'pretext' in attachment:
+ t.append(attachment['pretext'])
+ if "title" in attachment:
+ if attachment["title_link"]:
+ t.append('%s (%s)' % (attachment["title"], attachment["title_link"],))
+ else:
+ t.append(attachment["title"])
+ elif "from_url" in attachment:
+ t.append(attachment["from_url"])
+ if "text" in attachment:
+ tx = re.sub(r' *\n[\n ]+', '\n', attachment["text"])
+ t.append(tx)
+ if 'fields' in attachment:
+ for f in attachment['fields']:
+ if f['title'] != '':
+ t.append('%s %s' % (f['title'], f['value'],))
+ else:
+ t.append(f['value'])
+ if t == [] and "fallback" in attachment:
t.append(attachment["fallback"])
- attachment_text += ": ".join(t)
+ attachment_text += "\n".join([x.strip() for x in t if x])
return attachment_text