mirror of
https://github.com/caronc/apprise.git
synced 2025-01-03 20:49:19 +01:00
parent
b318c4d208
commit
3af32412df
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user