Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord now supports href= (and alias url=) arguments #927

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 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,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

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