From da514aa1f91f422a55224fd7ba0da322b5a90df9 Mon Sep 17 00:00:00 2001 From: AlbertUnruh Date: Sun, 30 Oct 2022 23:26:31 +0100 Subject: [PATCH] add constant `tag_as_mention` - update `BaseUser.username` to `BaseUser.tag` --- naff/client/const.py | 3 +++ naff/client/utils/text_utils.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/naff/client/const.py b/naff/client/const.py index d70a67778..0143f0bb0 100644 --- a/naff/client/const.py +++ b/naff/client/const.py @@ -8,6 +8,7 @@ logger_name str: The name of NAFFs default logger. Invalid if a custom logger is passed to `Client` to replace the default logger. logger logging.Logger: The logger used throughout NAFF. If a custom logger is passed to `Client`, this obj is replaced with the new logger. kwarg_spam bool: Should ``unused kwargs`` be logged. + tag_as_mention bool: Should utils interpret ``BaseUser.tag`` as a mention of it. ACTION_ROW_MAX_ITEMS int: The maximum number of items in an action row. SELECTS_MAX_OPTIONS int: The maximum number of options a select may have. @@ -48,6 +49,7 @@ "get_logger", "logger_name", "kwarg_spam", + "tag_as_mention", "DISCORD_EPOCH", "ACTION_ROW_MAX_ITEMS", "SELECTS_MAX_OPTIONS", @@ -96,6 +98,7 @@ def get_logger() -> logging.Logger: default_locale = "english_us" kwarg_spam = False +tag_as_mention = True DISCORD_EPOCH = 1420070400000 diff --git a/naff/client/utils/text_utils.py b/naff/client/utils/text_utils.py index fdc83eba4..47b41dedf 100644 --- a/naff/client/utils/text_utils.py +++ b/naff/client/utils/text_utils.py @@ -1,4 +1,5 @@ import re +import naff.client.const as const import naff.models as models __all__ = ("mentions",) @@ -21,7 +22,7 @@ def mentions(text: str, query: "str | re.Pattern[str] | models.BaseUser | models return query.match(text) is not None elif isinstance(query, models.BaseUser): # mentions with <@!ID> aren't detected without the replacement - return (query.mention in text.replace("@!", "@")) or (query.username in text) + return (query.mention in text.replace("@!", "@")) or (query.tag in text if const.tag_as_mention else False) elif isinstance(query, (models.BaseChannel, models.Role)): return (query.mention in text) or (query.name in text) else: