aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteinar H. Gunderson <steinar+github@gunderson.no>2023-10-06 00:31:06 +0200
committerGitHub <noreply@github.com>2023-10-06 00:31:06 +0200
commit1f9f89c778708698070e9cba639f2c53dec23490 (patch)
tree4403bec3354880b2010338593368de02130daf00
parentbc1c2b6373a999c671a32f6f3d20146bbd90109c (diff)
downloadwee-slack-1f9f89c778708698070e9cba639f2c53dec23490.tar.gz
Handle millisecond-level timestamps in attachments (#905)
The Slack documentation claims that the “ts” flag on attachments is “An integer Unix timestamp”. However, evidently it can be in milliseconds (i.e., a timestamp multiplied by 1000), causing out-of-range exceptions when trying to feed them to date.fromtimestamp(). This can cause all messages after such attachments to just vanish, as if they were never there, as parsing stops. Accept both; as a heuristic, the Slack web interface seems to use 100000000000 as a threshold, so we do the same and divide by 1000 if so. Co-authored-by: Steinar H. Gunderson <steinar+git@gunderson.no>
-rw-r--r--wee_slack.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index e6c8e62..3c35570 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -4978,6 +4978,11 @@ def unwrap_attachments(message, text_before):
ts = attachment.get("ts")
if ts:
ts_int = ts if isinstance(ts, int) else SlackTS(ts).major
+ if ts_int > 100000000000:
+ # The Slack web interface interprets very large timestamps
+ # as milliseconds after the epoch instead of regular Unix
+ # timestamps. We use the same heuristic here.
+ ts_int = ts_int // 1000
time_string = ""
if date.today() - date.fromtimestamp(ts_int) <= timedelta(days=1):
time_string = " at {time}"