aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2016-03-27 11:17:37 +0200
committerTollef Fog Heen <tfheen@err.no>2016-03-27 11:17:37 +0200
commit983ec62d0508ef4c59da45843d1f24f3c3c63f38 (patch)
treec7bd5a356f508c6c86c2a82c217d2fd4351a88f1
parentb1770652b856407f76095e5a513631c340d5f072 (diff)
downloadwee-slack-983ec62d0508ef4c59da45843d1f24f3c3c63f38.tar.gz
Add author_name to attachment formatting
This should hopefully make some of the trello and other formatting a bit better. Fixes: #145
-rw-r--r--wee_slack.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 4a1d000..840c71e 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1696,22 +1696,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'] != '':