Discord Apprise URL supports thread= directive (#630)

This commit is contained in:
Chris Caron 2022-07-13 19:26:21 -04:00 committed by GitHub
parent b34051ccaf
commit 088aba1622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -128,6 +128,12 @@ class NotifyDiscord(NotifyBase):
'name': _('Avatar URL'), 'name': _('Avatar URL'),
'type': 'string', 'type': 'string',
}, },
# Send a message to the specified thread within a webhook's channel.
# The thread will automatically be unarchived.
'thread': {
'name': _('Thread ID'),
'type': 'string',
},
'footer': { 'footer': {
'name': _('Display Footer'), 'name': _('Display Footer'),
'type': 'bool', 'type': 'bool',
@ -153,7 +159,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,
fields=True, avatar_url=None, **kwargs): fields=True, avatar_url=None, thread=None, **kwargs):
""" """
Initialize Discord Object Initialize Discord Object
@ -194,6 +200,9 @@ class NotifyDiscord(NotifyBase):
# Use Fields # Use Fields
self.fields = fields self.fields = fields
# Specified Thread ID
self.thread_id = thread
# Avatar URL # Avatar URL
# This allows a user to provide an over-ride to the otherwise # This allows a user to provide an over-ride to the otherwise
# dynamically generated avatar url images # dynamically generated avatar url images
@ -274,6 +283,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.thread_id:
payload['thread_id'] = self.thread_id
if self.avatar and (image_url or self.avatar_url): if self.avatar and (image_url or self.avatar_url):
payload['avatar_url'] = \ payload['avatar_url'] = \
self.avatar_url if self.avatar_url else image_url self.avatar_url if self.avatar_url else image_url
@ -447,6 +459,9 @@ class NotifyDiscord(NotifyBase):
if self.avatar_url: if self.avatar_url:
params['avatar_url'] = self.avatar_url params['avatar_url'] = self.avatar_url
if self.thread_id:
params['thread'] = self.thread_id
# Extend our parameters # Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
@ -515,6 +530,11 @@ class NotifyDiscord(NotifyBase):
results['avatar_url'] = \ results['avatar_url'] = \
NotifyDiscord.unquote(results['qsd']['avatar_url']) NotifyDiscord.unquote(results['qsd']['avatar_url'])
# Extract thread id if it was specified
if 'thread' in results['qsd']:
results['thread'] = \
NotifyDiscord.unquote(results['qsd']['thread'])
return results return results
@staticmethod @staticmethod

View File

@ -113,6 +113,12 @@ apprise_url_tests = (
'instance': plugins.NotifyDiscord, 'instance': plugins.NotifyDiscord,
'requests_response_code': requests.codes.no_content, 'requests_response_code': requests.codes.no_content,
}), }),
# Thread ID
('discord://%s/%s?format=markdown&thread=abc123' % (
'i' * 24, 't' * 64), {
'instance': plugins.NotifyDiscord,
'requests_response_code': requests.codes.no_content,
}),
('discord://%s/%s?format=text' % ('i' * 24, 't' * 64), { ('discord://%s/%s?format=text' % ('i' * 24, 't' * 64), {
'instance': plugins.NotifyDiscord, 'instance': plugins.NotifyDiscord,
'requests_response_code': requests.codes.no_content, 'requests_response_code': requests.codes.no_content,