From 3af32412df59159eda4746a1e0e597c000a0642d Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 7 Jun 2020 14:08:57 -0400 Subject: [PATCH] added avatar_url keyword support to Discord; refs #234 (#237) --- apprise/plugins/NotifyDiscord.py | 21 ++++++++++++++++++--- test/test_rest_plugins.py | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apprise/plugins/NotifyDiscord.py b/apprise/plugins/NotifyDiscord.py index 45dd07ad..c119814c 100644 --- a/apprise/plugins/NotifyDiscord.py +++ b/apprise/plugins/NotifyDiscord.py @@ -119,6 +119,10 @@ class NotifyDiscord(NotifyBase): 'type': 'bool', 'default': True, }, + 'avatar_url': { + 'name': _('Avatar URL'), + 'type': 'string', + }, 'footer': { 'name': _('Display Footer'), 'type': 'bool', @@ -139,7 +143,7 @@ class NotifyDiscord(NotifyBase): def __init__(self, webhook_id, webhook_token, tts=False, avatar=True, footer=False, footer_logo=True, include_image=False, - **kwargs): + avatar_url=None, **kwargs): """ Initialize Discord Object @@ -177,6 +181,11 @@ class NotifyDiscord(NotifyBase): # Place a thumbnail image inline with the message body self.include_image = include_image + # Avatar URL + # This allows a user to provide an over-ride to the otherwise + # dynamically generated avatar url images + self.avatar_url = avatar_url + return def send(self, body, title='', notify_type=NotifyType.INFO, attach=None, @@ -247,8 +256,9 @@ class NotifyDiscord(NotifyBase): payload['content'] = \ body if not title else "{}\r\n{}".format(title, body) - if self.avatar and image_url: - payload['avatar_url'] = image_url + if self.avatar and (image_url or self.avatar_url): + payload['avatar_url'] = \ + self.avatar_url if self.avatar_url else image_url if self.user: # Optionally override the default username of the webhook @@ -474,6 +484,11 @@ class NotifyDiscord(NotifyBase): parse_bool(results['qsd'].get( 'image', results['qsd'].get('thumbnail', False))) + # Extract avatar url if it was specified + if 'avatar_url' in results['qsd']: + results['avatar_url'] = \ + NotifyDiscord.unquote(results['qsd']['avatar_url']) + return results @staticmethod diff --git a/test/test_rest_plugins.py b/test/test_rest_plugins.py index b3bc9f87..70b7eb93 100644 --- a/test/test_rest_plugins.py +++ b/test/test_rest_plugins.py @@ -335,6 +335,12 @@ TEST_URLS = ( 'instance': plugins.NotifyDiscord, 'requests_response_code': requests.codes.no_content, }), + # Test with avatar URL + ('discord://%s/%s?avatar_url=http://localhost/test.jpg' % ( + 'i' * 24, 't' * 64), { + 'instance': plugins.NotifyDiscord, + 'requests_response_code': requests.codes.no_content, + }), # Test without image set ('discord://%s/%s' % ('i' * 24, 't' * 64), { 'instance': plugins.NotifyDiscord,