aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2016-03-28 09:13:51 -0700
committerRyan Huber <rhuber@gmail.com>2016-03-28 09:13:51 -0700
commitac9b781b987a01aa1717f99c354b39e879e761f6 (patch)
tree64c96e2030c802d2f7ac78666cc989c44d660ef8 /wee_slack.py
parent76a62b8d015155d6b48805ca56fb216980e87969 (diff)
parent983ec62d0508ef4c59da45843d1f24f3c3c63f38 (diff)
downloadwee-slack-ac9b781b987a01aa1717f99c354b39e879e761f6.tar.gz
Merge pull request #201 from rawdigits/better-attachment-formatting
Add author_name to attachment formatting
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 746342e..b1da9ec 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1698,22 +1698,27 @@ def unwrap_attachments(message_json, text_before):
# Attachments should be rendered roughly like:
#
# $pretext
- # $title ($title_link) OR $from_url
- # $text
+ # $author: (if rest of line is non-empty) $title ($title_link) OR $from_url
+ # $author: (if no $author on previous line) $text
# $fields
t = []
+ prepend_title_text = ''
+ if 'author_name' in attachment:
+ prepend_title_text = attachment['author_name'] + ": "
if 'pretext' in attachment:
t.append(attachment['pretext'])
if "title" in attachment:
if 'title_link' in attachment:
- t.append('%s (%s)' % (attachment["title"], attachment["title_link"],))
+ t.append('%s%s (%s)' % (prepend_title_text, attachment["title"], attachment["title_link"],))
else:
- t.append(attachment["title"])
+ t.append(prepend_title_text + attachment["title"])
+ prepend_title_text = ''
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)
+ t.append(prepend_title_text + tx)
+ prepend_title_text = ''
if 'fields' in attachment:
for f in attachment['fields']:
if f['title'] != '':