diff --git a/apprise/plugins/NotifyDiscord.py b/apprise/plugins/NotifyDiscord.py index af0344a06d..d64fce9616 100644 --- a/apprise/plugins/NotifyDiscord.py +++ b/apprise/plugins/NotifyDiscord.py @@ -152,6 +152,13 @@ class NotifyDiscord(NotifyBase): 'name': _('Avatar URL'), 'type': 'string', }, + 'href': { + 'name': _('URL'), + 'type': 'string', + }, + 'url': { + 'alias_of': 'href', + }, # Send a message to the specified thread within a webhook's channel. # The thread will automatically be unarchived. 'thread': { @@ -183,7 +190,8 @@ class NotifyDiscord(NotifyBase): def __init__(self, webhook_id, webhook_token, tts=False, avatar=True, footer=False, footer_logo=True, include_image=False, - fields=True, avatar_url=None, thread=None, **kwargs): + fields=True, avatar_url=None, href=None, thread=None, + **kwargs): """ Initialize Discord Object @@ -232,6 +240,9 @@ def __init__(self, webhook_id, webhook_token, tts=False, avatar=True, # dynamically generated avatar url images self.avatar_url = avatar_url + # A URL to have the title link to + self.href = href + # For Tracking Purposes self.ratelimit_reset = datetime.now(timezone.utc).replace(tzinfo=None) @@ -287,6 +298,9 @@ def send(self, body, title='', notify_type=NotifyType.INFO, attach=None, 'color': self.color(notify_type, int), }] + if self.href: + payload['embeds'][0]['url'] = self.href + if self.footer: # Acquire logo URL logo_url = self.image_url(notify_type, logo=True) @@ -540,6 +554,9 @@ def url(self, privacy=False, *args, **kwargs): if self.avatar_url: params['avatar_url'] = self.avatar_url + if self.href: + params['href'] = self.href + if self.thread_id: params['thread'] = self.thread_id @@ -611,10 +628,23 @@ def parse_url(url): results['avatar_url'] = \ NotifyDiscord.unquote(results['qsd']['avatar_url']) + # Extract url if it was specified + if 'href' in results['qsd']: + results['href'] = \ + NotifyDiscord.unquote(results['qsd']['href']) + + elif 'url' in results['qsd']: + results['href'] = \ + NotifyDiscord.unquote(results['qsd']['url']) + # Markdown is implied + results['format'] = NotifyFormat.MARKDOWN + # Extract thread id if it was specified if 'thread' in results['qsd']: results['thread'] = \ NotifyDiscord.unquote(results['qsd']['thread']) + # Markdown is implied + results['format'] = NotifyFormat.MARKDOWN return results diff --git a/test/test_plugin_discord.py b/test/test_plugin_discord.py index 30c4997726..ca045400a3 100644 --- a/test/test_plugin_discord.py +++ b/test/test_plugin_discord.py @@ -132,6 +132,18 @@ 'instance': NotifyDiscord, 'requests_response_code': requests.codes.no_content, }), + # Test with href (title link) + ('discord://%s/%s?hmarkdown=true&ref=http://localhost' % ( + 'i' * 24, 't' * 64), { + 'instance': NotifyDiscord, + 'requests_response_code': requests.codes.no_content, + }), + # Test with url (title link) - Alias of href + ('discord://%s/%s?markdown=true&url=http://localhost' % ( + 'i' * 24, 't' * 64), { + 'instance': 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), {