diff --git a/apprise/plugins/NotifyZulip.py b/apprise/plugins/NotifyZulip.py index 80ca9422..66277137 100644 --- a/apprise/plugins/NotifyZulip.py +++ b/apprise/plugins/NotifyZulip.py @@ -63,10 +63,11 @@ from ..common import NotifyType from ..utils import parse_list from ..utils import validate_regex from ..utils import is_email +from ..utils import remove_suffix from ..AppriseLocale import gettext_lazy as _ # A Valid Bot Name -VALIDATE_BOTNAME = re.compile(r'(?P[A-Z0-9_]{1,32})(-bot)?', re.I) +VALIDATE_BOTNAME = re.compile(r'(?P[A-Z0-9_-]{1,32})', re.I) # Organization required as part of the API request VALIDATE_ORG = re.compile( @@ -122,7 +123,7 @@ class NotifyZulip(NotifyBase): 'botname': { 'name': _('Bot Name'), 'type': 'string', - 'regex': (r'^[A-Z0-9_]{1,32}(-bot)?$', 'i'), + 'regex': (r'^[A-Z0-9_-]{1,32}$', 'i'), }, 'organization': { 'name': _('Organization'), @@ -183,7 +184,9 @@ class NotifyZulip(NotifyBase): raise TypeError # The botname - self.botname = match.group('name') + botname = match.group('name') + botname = remove_suffix(botname, '-bot') + self.botname = botname except (TypeError, AttributeError): msg = 'The Zulip botname specified ({}) is invalid.'\ diff --git a/apprise/utils.py b/apprise/utils.py index 6bf6df23..f07bb2cf 100644 --- a/apprise/utils.py +++ b/apprise/utils.py @@ -1379,3 +1379,10 @@ def apply_template(template, app_mode=TemplateType.RAW, **kwargs): # to drop the '{{' and '}}' surrounding our match so that we can # re-index it back into our list return mask_r.sub(lambda x: fn(kwargs[x.group()[2:-2].strip()]), template) + + +def remove_suffix(value, suffix): + """ + Removes a suffix from the end of a string. + """ + return value[:-len(suffix)] if value.endswith(suffix) else value diff --git a/test/test_plugin_zulip.py b/test/test_plugin_zulip.py index 4245d1b3..f25a0847 100644 --- a/test/test_plugin_zulip.py +++ b/test/test_plugin_zulip.py @@ -55,6 +55,11 @@ apprise_url_tests = ( ('zulip://....@apprise/{}'.format('a' * 32), { 'instance': TypeError, }), + # Valid everything - botname with a dash + ('zulip://bot-name@apprise/{}'.format('a' * 32), { + 'instance': plugins.NotifyZulip, + 'privacy_url': 'zulip://bot-name@apprise/a...a/', + }), # Valid everything - no target so default is used ('zulip://botname@apprise/{}'.format('a' * 32), { 'instance': plugins.NotifyZulip,