Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
add constant tag_as_mention
Browse files Browse the repository at this point in the history
- update `BaseUser.username` to `BaseUser.tag`
  • Loading branch information
AlbertUnruh committed Oct 30, 2022
1 parent 419cf20 commit da514aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions naff/client/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -48,6 +49,7 @@
"get_logger",
"logger_name",
"kwarg_spam",
"tag_as_mention",
"DISCORD_EPOCH",
"ACTION_ROW_MAX_ITEMS",
"SELECTS_MAX_OPTIONS",
Expand Down Expand Up @@ -96,6 +98,7 @@ def get_logger() -> logging.Logger:

default_locale = "english_us"
kwarg_spam = False
tag_as_mention = True

DISCORD_EPOCH = 1420070400000

Expand Down
3 changes: 2 additions & 1 deletion naff/client/utils/text_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import naff.client.const as const
import naff.models as models

__all__ = ("mentions",)
Expand All @@ -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:
Expand Down

0 comments on commit da514aa

Please sign in to comment.