diff options
author | Tollef Fog Heen <tfheen@err.no> | 2015-07-31 12:37:30 +0200 |
---|---|---|
committer | Tollef Fog Heen <tfheen@err.no> | 2015-07-31 12:37:30 +0200 |
commit | 04705fea669507e617d576579894ad2e7f4dc685 (patch) | |
tree | c0607266da1c6c3f8d67508f6e08f59f4eee24a8 /wee_slack.py | |
parent | 8b357dc4171583e8aac09323036195c3e4dca7de (diff) | |
download | wee-slack-04705fea669507e617d576579894ad2e7f4dc685.tar.gz |
Make it possible to ignore alt text when unfurling
Add a setting unfurl_ignore_alt_text which when non-0 will prefer the
plain text version of URLs and other similar instead of using the
expanded version from slack.
Nicks and channel names are always expanded.
The default is the old behaviour, to prefer the slack-expanded text.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py index d13d64c..9722bbd 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1337,7 +1337,11 @@ def process_message(message_json, cache=True): text = text.decode('utf-8') - text = unfurl_refs(text) + ignore_alt_text = False + if w.config_get_plugin('unfurl_ignore_alt_text') != "0": + ignore_alt_text = True + text = unfurl_refs(text, ignore_alt_text=ignore_alt_text) + if "attachments" in message_json: text += u" --- {}".format(unwrap_attachments(message_json)) text = text.lstrip() @@ -1404,7 +1408,7 @@ def unwrap_attachments(message_json): return attachment_text -def unfurl_refs(text): +def unfurl_refs(text, ignore_alt_text=False): """ Worst code ever written. this needs work """ @@ -1422,7 +1426,10 @@ def unfurl_refs(text): suffix = item[end+1:] item = item[start + 1:end] if item.find('|') > -1: - item = item.split('|')[0] + if ignore_alt_text: + item = item.split('|')[1] + else: + item = item.split('|')[0] if item.startswith('@U'): if users.find(item[1:]): try: @@ -1831,6 +1838,8 @@ if __name__ == "__main__": w.config_set_plugin('colorize_nicks', "1") if not w.config_get_plugin('trigger_value'): w.config_set_plugin('trigger_value', "0") + if not w.config_get_plugin('unfurl_ignore_alt_text'): + w.config_set_plugin('unfurl_ignore_alt_text', "0") version = w.info_get("version_number", "") or 0 if int(version) >= 0x00040400: |