From 548e99ac72cf15cbad9e42fa9c42b34913bb64ad Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 6 Sep 2025 16:04:26 -0400 Subject: [PATCH] Added support for discord:// flags= (#1409) --- apprise/plugins/discord.py | 32 ++++++++++++++++++++++++++++++++ tests/test_plugin_discord.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/apprise/plugins/discord.py b/apprise/plugins/discord.py index da6e1bbb..653fb67f 100644 --- a/apprise/plugins/discord.py +++ b/apprise/plugins/discord.py @@ -183,6 +183,11 @@ class NotifyDiscord(NotifyBase): "type": "bool", "default": True, }, + "flags": { + "name": _("Discord Flags"), + "type": "int", + "min": 0, + }, "image": { "name": _("Include Image"), "type": "bool", @@ -205,6 +210,7 @@ class NotifyDiscord(NotifyBase): avatar_url=None, href=None, thread=None, + flags=None, **kwargs, ): """Initialize Discord Object.""" @@ -258,6 +264,21 @@ class NotifyDiscord(NotifyBase): # A URL to have the title link to self.href = href + # A URL to have the title link to + if flags: + try: + self.flags = int(flags) + if self.flags < NotifyDiscord.template_args["flags"]["min"]: + raise ValueError() + + except (TypeError, ValueError): + msg = "An invalid Discord flags setting " \ + "({}) was specified.".format(flags) + self.logger.warning(msg) + raise TypeError(msg) from None + else: + self.flags = None + # For Tracking Purposes self.ratelimit_reset = datetime.now(timezone.utc).replace(tzinfo=None) @@ -284,6 +305,10 @@ class NotifyDiscord(NotifyBase): "wait": self.tts is False, } + if self.flags: + # Set our flag if defined: + payload["flags"] = self.flags + # Acquire image_url image_url = self.image_url(notify_type) @@ -626,6 +651,9 @@ class NotifyDiscord(NotifyBase): if self.avatar_url: params["avatar_url"] = self.avatar_url + if self.flags: + params["flags"] = str(self.flags) + if self.href: params["href"] = self.href @@ -718,6 +746,10 @@ class NotifyDiscord(NotifyBase): # Alias to User results["user"] = NotifyDiscord.unquote(results["qsd"]["botname"]) + if "flags" in results["qsd"]: + # Alias to User + results["flags"] = NotifyDiscord.unquote(results["qsd"]["flags"]) + # Extract avatar url if it was specified if "avatar_url" in results["qsd"]: results["avatar_url"] = NotifyDiscord.unquote( diff --git a/tests/test_plugin_discord.py b/tests/test_plugin_discord.py index 144a188a..c65afd32 100644 --- a/tests/test_plugin_discord.py +++ b/tests/test_plugin_discord.py @@ -165,6 +165,34 @@ apprise_url_tests = ( "requests_response_code": requests.codes.no_content, }, ), + ( + "discord://{}/{}?flags=1".format( + "i" * 24, "t" * 64 + ), + { + "instance": NotifyDiscord, + "requests_response_code": requests.codes.no_content, + }, + ), + ( + "discord://{}/{}?flags=-1".format( + "i" * 24, "t" * 64 + ), + { + # invalid flags specified (variation 1) + "instance": TypeError, + }, + ), + ( + "discord://{}/{}?flags=invalid".format( + "i" * 24, "t" * 64 + ), + { + # invalid flags specified (variation 2) + "instance": TypeError, + }, + ), + # different format support ( "discord://{}/{}?format=markdown".format("i" * 24, "t" * 64),