From 016ad3b9fd3858993e7ffaa5f45af20fcca7671f Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 4 Jan 2024 16:31:26 +0000 Subject: Update unambiguous converter to not support usernames --- bot/converters.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/bot/converters.py b/bot/converters.py index 3c8ea44d7..977035e1d 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -423,23 +423,19 @@ class HushDurationConverter(Converter): def _is_an_unambiguous_user_argument(argument: str) -> bool: - """Check if the provided argument is a user mention, user id, or username (name#discrim).""" - has_id_or_mention = bool(IDConverter()._get_id_match(argument) or RE_USER_MENTION.match(argument)) + """Check if the provided argument is a user mention or user id.""" + user_id = IDConverter()._get_id_match(argument) + user_mention = RE_USER_MENTION.match(argument) - # Check to see if the author passed a username (a discriminator exists) - argument = argument.removeprefix("@") - has_username = len(argument) > 5 and argument[-5] == "#" + return bool(user_id or user_mention) - return has_id_or_mention or has_username - -AMBIGUOUS_ARGUMENT_MSG = ("`{argument}` is not a User mention, a User ID or a Username in the format" - " `name#discriminator`.") +AMBIGUOUS_ARGUMENT_MSG = "`{argument}` is not a User mention or a User ID." class UnambiguousUser(UserConverter): """ - Converts to a `discord.User`, but only if a mention, userID or a username (name#discrim) is provided. + Converts to a `discord.User`, but only if a mention or userID is provided. Unlike the default `UserConverter`, it doesn't allow conversion from a name. This is useful in cases where that lookup strategy would lead to too much ambiguity. @@ -454,7 +450,7 @@ class UnambiguousUser(UserConverter): class UnambiguousMember(MemberConverter): """ - Converts to a `discord.Member`, but only if a mention, userID or a username (name#discrim) is provided. + Converts to a `discord.Member`, but only if a mention or userID is provided. Unlike the default `MemberConverter`, it doesn't allow conversion from a name or nickname. This is useful in cases where that lookup strategy would lead to too much ambiguity. -- cgit v1.2.3 From e8bc1b80b4d2b2e50832761cee2ed3e343cf51c8 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 5 Jan 2024 13:48:49 +0000 Subject: Don't instantiate class to call static method --- bot/converters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/converters.py b/bot/converters.py index 977035e1d..038f815a5 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -424,7 +424,7 @@ class HushDurationConverter(Converter): def _is_an_unambiguous_user_argument(argument: str) -> bool: """Check if the provided argument is a user mention or user id.""" - user_id = IDConverter()._get_id_match(argument) + user_id = IDConverter._get_id_match(argument) user_mention = RE_USER_MENTION.match(argument) return bool(user_id or user_mention) -- cgit v1.2.3