Discord Thread ID Reference fixed (#855)

pull/863/head
Chris Caron 2023-03-24 06:02:21 -04:00 committed by GitHub
parent be174c374f
commit 76d44a3179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -290,9 +290,6 @@ class NotifyDiscord(NotifyBase):
payload['content'] = \
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):
payload['avatar_url'] = \
self.avatar_url if self.avatar_url else image_url
@ -301,7 +298,8 @@ class NotifyDiscord(NotifyBase):
# Optionally override the default username of the webhook
payload['username'] = self.user
if not self._send(payload):
params = {'thread_id': self.thread_id} if self.thread_id else None
if not self._send(payload, params=params):
# We failed to post our message
return False
@ -345,7 +343,7 @@ class NotifyDiscord(NotifyBase):
# Otherwise return
return True
def _send(self, payload, attach=None, **kwargs):
def _send(self, payload, attach=None, params=None, **kwargs):
"""
Wrapper to the requests (post) object
"""
@ -396,6 +394,7 @@ class NotifyDiscord(NotifyBase):
r = requests.post(
notify_url,
params=params,
data=payload if files else dumps(payload),
headers=headers,
files=files,

View File

@ -368,6 +368,27 @@ def test_plugin_discord_general(mock_post):
assert a.notify(
body='body', title='title', notify_type=NotifyType.INFO) is True
# Create an apprise instance
a = Apprise()
# Reset our object
mock_post.reset_mock()
# Test our threading
assert a.add(
'discord://{webhook_id}/{webhook_token}/'
'?thread=12345'.format(
webhook_id=webhook_id,
webhook_token=webhook_token)) is True
# This call includes an image with it's payload:
assert a.notify(body='test', title='title') is True
assert mock_post.call_count == 1
response = mock_post.call_args_list[0][1]
assert 'params' in response
assert response['params'].get('thread_id') == '12345'
@mock.patch('requests.post')
def test_plugin_discord_markdown_extra(mock_post):