Skip to content

Commit

Permalink
Discord now supports href= (and alias url=) arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 19, 2023
1 parent 207db69 commit beb6463
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
33 changes: 32 additions & 1 deletion apprise/plugins/NotifyDiscord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -611,10 +628,24 @@ 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

Expand Down
12 changes: 12 additions & 0 deletions test/test_plugin_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down

0 comments on commit beb6463

Please sign in to comment.