aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-10-01 21:13:33 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-10-01 21:17:00 +0200
commitdb4f64ec1f25baa7db99d1ddf4c8ae09d9b1b9e4 (patch)
tree9c6812b7bec3308e38e56fa64a807849a2a1408e
parentc6087453d64d9158395b7227d7545bb26f36411c (diff)
downloadwee-slack-db4f64ec1f25baa7db99d1ddf4c8ae09d9b1b9e4.tar.gz
refactor: Get config variables in unfurl_refs
Instead of each of the callers of unfurl_refs having to get the config values, get them in unfurl_refs if they are not set by the caller.
-rw-r--r--wee_slack.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 23bb115..6b7a5d8 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2498,9 +2498,9 @@ def render(message_json, team, channel, force=False):
else:
text = ""
- text = unfurl_refs(text, ignore_alt_text=config.unfurl_ignore_alt_text)
+ text = unfurl_refs(text)
- text += unfurl_refs(unwrap_attachments(message_json, text), ignore_alt_text=config.unfurl_ignore_alt_text)
+ text += unfurl_refs(unwrap_attachments(message_json, text))
text = text.lstrip()
text = unhtmlescape(text.replace("\t", " "))
@@ -2557,7 +2557,7 @@ def linkify_text(message, team, channel):
return " ".join(message)
-def unfurl_refs(text, ignore_alt_text=False):
+def unfurl_refs(text, ignore_alt_text=None, auto_link_display=None):
"""
input : <@U096Q7CQM|someuser> has joined the channel
ouput : someuser has joined the channel
@@ -2567,14 +2567,21 @@ def unfurl_refs(text, ignore_alt_text=False):
# - <#C2147483705|#otherchannel>
# - <@U2147483697|@othernick>
# Test patterns lives in ./_pytest/test_unfurl.py
+
+ if ignore_alt_text is None:
+ ignore_alt_text = config.unfurl_ignore_alt_text
+ if auto_link_display is None:
+ auto_link_display = config.unfurl_auto_link_display
+
matches = re.findall(r"(<[@#]?(?:[^>]*)>)", text)
for m in matches:
# Replace them with human readable strings
- text = text.replace(m, unfurl_ref(m[1:-1], ignore_alt_text))
+ text = text.replace(
+ m, unfurl_ref(m[1:-1], ignore_alt_text, auto_link_display))
return text
-def unfurl_ref(ref, ignore_alt_text=False):
+def unfurl_ref(ref, ignore_alt_text, auto_link_display):
id = ref.split('|')[0]
display_text = ref
if ref.find('|') > -1:
@@ -2589,9 +2596,9 @@ def unfurl_ref(ref, ignore_alt_text=False):
url, desc = ref.split('|', 1)
match_url = r"^\w+:(//)?{}$".format(re.escape(desc))
url_matches_desc = re.match(match_url, url)
- if url_matches_desc and config.unfurl_auto_link_display == "text":
+ if url_matches_desc and auto_link_display == "text":
display_text = desc
- elif url_matches_desc and config.unfurl_auto_link_display == "url":
+ elif url_matches_desc and auto_link_display == "url":
display_text = url
else:
display_text = "{} ({})".format(url, desc)