tgram:// be sure total notification size is always under their 4096 size limit

pull/560/head
dgtlmoon 3 years ago
parent e4eaa0c817
commit 37775a46c6

@ -66,19 +66,25 @@ def process_notification(n_object, datastore):
if not 'avatar_url' in url: if not 'avatar_url' in url:
url += k + 'avatar_url=https://raw.githubusercontent.com/dgtlmoon/changedetection.io/master/changedetectionio/static/images/avatar-256x256.png' url += k + 'avatar_url=https://raw.githubusercontent.com/dgtlmoon/changedetection.io/master/changedetectionio/static/images/avatar-256x256.png'
payload_max_size = 1700 if url.startswith('tgram://'):
# Trim everything to a max of 1700 total chars (leave some for padding, control etc) # real limit is 4096, but minus some for extra metadata
# Incase n_title > 1700 payload_max_size = 3600
# basically trim back the body until the total size fits our threshold body_limit = max(0, payload_max_size - len(n_title))
# and trim off the n_title to fit always. n_title = n_title[0:payload_max_size]
body_limit = max(0, payload_max_size - len(n_title)) n_body = n_body[0:body_limit]
body = n_body[0:body_limit] if 'discord://' in url else n_body
elif url.startswith('discord://'):
# real limit is 2000, but minus some for extra metadata
payload_max_size = 1700
body_limit = max(0, payload_max_size - len(n_title))
n_title = n_title[0:payload_max_size]
n_body = n_body[0:body_limit]
apobj.add(url) apobj.add(url)
apobj.notify( apobj.notify(
title=n_title[0:payload_max_size], title=n_title,
body=body, body=n_body,
body_format=n_format) body_format=n_format)
apobj.clear() apobj.clear()

Loading…
Cancel
Save