mirror of
https://github.com/caronc/apprise.git
synced 2025-01-21 05:19:01 +01:00
parent
b318c4d208
commit
3af32412df
@ -119,6 +119,10 @@ class NotifyDiscord(NotifyBase):
|
|||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
'default': True,
|
'default': True,
|
||||||
},
|
},
|
||||||
|
'avatar_url': {
|
||||||
|
'name': _('Avatar URL'),
|
||||||
|
'type': 'string',
|
||||||
|
},
|
||||||
'footer': {
|
'footer': {
|
||||||
'name': _('Display Footer'),
|
'name': _('Display Footer'),
|
||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
@ -139,7 +143,7 @@ class NotifyDiscord(NotifyBase):
|
|||||||
|
|
||||||
def __init__(self, webhook_id, webhook_token, tts=False, avatar=True,
|
def __init__(self, webhook_id, webhook_token, tts=False, avatar=True,
|
||||||
footer=False, footer_logo=True, include_image=False,
|
footer=False, footer_logo=True, include_image=False,
|
||||||
**kwargs):
|
avatar_url=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize Discord Object
|
Initialize Discord Object
|
||||||
|
|
||||||
@ -177,6 +181,11 @@ class NotifyDiscord(NotifyBase):
|
|||||||
# Place a thumbnail image inline with the message body
|
# Place a thumbnail image inline with the message body
|
||||||
self.include_image = include_image
|
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
|
return
|
||||||
|
|
||||||
def send(self, body, title='', notify_type=NotifyType.INFO, attach=None,
|
def send(self, body, title='', notify_type=NotifyType.INFO, attach=None,
|
||||||
@ -247,8 +256,9 @@ class NotifyDiscord(NotifyBase):
|
|||||||
payload['content'] = \
|
payload['content'] = \
|
||||||
body if not title else "{}\r\n{}".format(title, body)
|
body if not title else "{}\r\n{}".format(title, body)
|
||||||
|
|
||||||
if self.avatar and image_url:
|
if self.avatar and (image_url or self.avatar_url):
|
||||||
payload['avatar_url'] = image_url
|
payload['avatar_url'] = \
|
||||||
|
self.avatar_url if self.avatar_url else image_url
|
||||||
|
|
||||||
if self.user:
|
if self.user:
|
||||||
# Optionally override the default username of the webhook
|
# Optionally override the default username of the webhook
|
||||||
@ -474,6 +484,11 @@ class NotifyDiscord(NotifyBase):
|
|||||||
parse_bool(results['qsd'].get(
|
parse_bool(results['qsd'].get(
|
||||||
'image', results['qsd'].get('thumbnail', False)))
|
'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
|
return results
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -335,6 +335,12 @@ TEST_URLS = (
|
|||||||
'instance': plugins.NotifyDiscord,
|
'instance': plugins.NotifyDiscord,
|
||||||
'requests_response_code': requests.codes.no_content,
|
'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
|
# Test without image set
|
||||||
('discord://%s/%s' % ('i' * 24, 't' * 64), {
|
('discord://%s/%s' % ('i' * 24, 't' * 64), {
|
||||||
'instance': plugins.NotifyDiscord,
|
'instance': plugins.NotifyDiscord,
|
||||||
|
Loading…
Reference in New Issue
Block a user