aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-07-06 21:56:03 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2023-07-06 21:56:03 +0200
commit857a42dee093ef87723d0e214a29bc346a29a595 (patch)
tree2d151d8caf28c5afbef5c2bebb438b71e516f959
parent5302c8701c5411c28a00b022600ee7cd723718e2 (diff)
downloadwee-slack-857a42dee093ef87723d0e214a29bc346a29a595.tar.gz
Support printing URLs without a title/alt text
Not sure if this ever occurs, but better safe than sorry.
-rw-r--r--wee_slack.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index b402397..ff794f9 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -4628,7 +4628,10 @@ def unfurl_block_element(text):
elif text["type"] == "plain_text":
return text["text"]
elif text["type"] == "image":
- return "{} ({})".format(text["image_url"], text["alt_text"])
+ if text.get("alt_text"):
+ return "{} ({})".format(text["image_url"], text["alt_text"])
+ else:
+ return text["image_url"]
def unfurl_refs(text):
@@ -4852,10 +4855,11 @@ def unwrap_files(message, message_json, text_before):
f["permalink"], message.team.identifier, message.channel.identifier
)
text = "{} ({})".format(url, f["title"])
- elif (
- f.get("url_private", None) is not None and f.get("title", None) is not None
- ):
- text = "{} ({})".format(f["url_private"], f["title"])
+ elif f.get("url_private"):
+ if f.get("title"):
+ text = "{} ({})".format(f["url_private"], f["title"])
+ else:
+ text = f["url_private"]
else:
dbg("File {} has unrecognized mode {}".format(f["id"], f.get("mode")), 5)
text = colorize_string(