diff --git a/changedetectionio/notification.py b/changedetectionio/notification.py index 54495685..a3fc9548 100644 --- a/changedetectionio/notification.py +++ b/changedetectionio/notification.py @@ -26,13 +26,6 @@ default_notification_title = 'ChangeDetection.io Notification - {watch_url}' def process_notification(n_object, datastore): - apobj = apprise.Apprise(debug=True) - - for url in n_object['notification_urls']: - url = url.strip() - print (">> Process Notification: AppRise notifying {}".format(url)) - apobj.add(url) - # Get the notification body from datastore n_body = n_object.get('notification_body', default_notification_body) n_title = n_object.get('notification_title', default_notification_title) @@ -54,19 +47,31 @@ def process_notification(n_object, datastore): # https://github.com/caronc/apprise/wiki/Development_LogCapture # Anything higher than or equal to WARNING (which covers things like Connection errors) # raise it as an exception + apobjs=[] + for url in n_object['notification_urls']: - with apprise.LogCapture(level=apprise.logging.DEBUG) as logs: - apobj.notify( - body=n_body, - title=n_title, - body_format=n_format) - - # Returns empty string if nothing found, multi-line string otherwise - log_value = logs.getvalue() - if log_value and 'WARNING' in log_value or 'ERROR' in log_value: - raise Exception(log_value) - - + apobj = apprise.Apprise(debug=True) + url = url.strip() + if len(url): + print(">> Process Notification: AppRise notifying {}".format(url)) + apobj.add(url) + with apprise.LogCapture(level=apprise.logging.DEBUG) as logs: + # Re 323 - Limit discord length to their 2000 char limit total + # Or it wont send. + # Because different notifications may require different pre-processing, run each sequentially :( + body = n_body[0:2000-len(n_title)] if 'discord://' in url else n_body + apobj.notify( + title=n_title, + body=body, + body_format=n_format) + + # Incase it needs to exist in memory for a while after to process(?) + apobjs.append(apobj) + + # Returns empty string if nothing found, multi-line string otherwise + log_value = logs.getvalue() + if log_value and 'WARNING' in log_value or 'ERROR' in log_value: + raise Exception(log_value) # Notification title + body content parameters get created here. def create_notification_parameters(n_object, datastore): diff --git a/changedetectionio/templates/_common_fields.jinja b/changedetectionio/templates/_common_fields.jinja index 6a5ec7c2..514db394 100644 --- a/changedetectionio/templates/_common_fields.jinja +++ b/changedetectionio/templates/_common_fields.jinja @@ -13,7 +13,7 @@