Skip to content

Commit

Permalink
improved handling of discord:// botname
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Dec 20, 2024
1 parent 11f3899 commit 73a60f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
23 changes: 17 additions & 6 deletions apprise/plugins/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,21 @@ def url(self, privacy=False, *args, **kwargs):
if self.thread_id:
params['thread'] = self.thread_id

# Ensure our botname is set
botname = f'{self.user}@' if self.user else ''

# Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))

return '{schema}://{webhook_id}/{webhook_token}/?{params}'.format(
schema=self.secure_protocol,
webhook_id=self.pprint(self.webhook_id, privacy, safe=''),
webhook_token=self.pprint(self.webhook_token, privacy, safe=''),
params=NotifyDiscord.urlencode(params),
)
return '{schema}://{botname}{webhook_id}/{webhook_token}/?{params}' \
.format(
schema=self.secure_protocol,
botname=botname,
webhook_id=self.pprint(self.webhook_id, privacy, safe=''),
webhook_token=self.pprint(
self.webhook_token, privacy, safe=''),
params=NotifyDiscord.urlencode(params),
)

@property
def url_identifier(self):
Expand Down Expand Up @@ -668,6 +674,11 @@ def parse_url(url):
results['include_image'] = parse_bool(results['qsd'].get(
'image', NotifyDiscord.template_args['image']['default']))

if 'botname' in results['qsd']:
# Alias to User
results['user'] = \
NotifyDiscord.unquote(results['qsd']['botname'])

# Extract avatar url if it was specified
if 'avatar_url' in results['qsd']:
results['avatar_url'] = \
Expand Down
11 changes: 10 additions & 1 deletion test/test_plugin_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
'instance': NotifyDiscord,
'requests_response_code': requests.codes.no_content,
}),
('discord://%s/%s?format=markdown&footer=Yes&image=Yes' % (
('discord://jack@%s/%s?format=markdown&footer=Yes&image=Yes' % (
'i' * 24, 't' * 64), {
'instance': NotifyDiscord,
'requests_response_code': requests.codes.no_content,
'privacy_url': 'discord://[email protected]/t...t/',
}),
('https://discord.com/api/webhooks/{}/{}'.format(
'0' * 10, 'B' * 40), {
Expand All @@ -113,6 +114,14 @@
# Native URL Support with arguments
'instance': NotifyDiscord,
'requests_response_code': requests.codes.no_content,
'privacy_url': 'discord://0...0/B...B/',
}),
('https://discordapp.com/api/webhooks/{}/{}?footer=yes&botname=joe'.format(
'0' * 10, 'B' * 40), {
# Native URL Support with arguments
'instance': NotifyDiscord,
'requests_response_code': requests.codes.no_content,
'privacy_url': 'discord://[email protected]/B...B/',
}),
('discord://%s/%s?format=markdown&avatar=No&footer=No' % (
'i' * 24, 't' * 64), {
Expand Down

0 comments on commit 73a60f2

Please sign in to comment.