diff options
Diffstat (limited to 'bot/converters.py')
-rw-r--r-- | bot/converters.py | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/bot/converters.py b/bot/converters.py index 3c8ea44d7..34a764567 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. @@ -504,23 +500,23 @@ class Infraction(Converter): if t.TYPE_CHECKING: - ValidDiscordServerInvite = dict # noqa: F811 + ValidDiscordServerInvite = dict ValidFilterListType = str - Extension = str # noqa: F811 - PackageName = str # noqa: F811 - ValidURL = str # noqa: F811 - Inventory = tuple[str, _inventory_parser.InventoryDict] # noqa: F811 - Snowflake = int # noqa: F811 - SourceConverter = SourceType # noqa: F811 + Extension = str + PackageName = str + ValidURL = str + Inventory = tuple[str, _inventory_parser.InventoryDict] + Snowflake = int + SourceConverter = SourceType DurationDelta = relativedelta - Duration = datetime # noqa: F811 - Age = datetime # noqa: F811 - OffTopicName = str # noqa: F811 - ISODateTime = datetime # noqa: F811 - HushDurationConverter = int # noqa: F811 - UnambiguousUser = discord.User # noqa: F811 - UnambiguousMember = discord.Member # noqa: F811 - Infraction = dict | None # noqa: F811 + Duration = datetime + Age = datetime + OffTopicName = str + ISODateTime = datetime + HushDurationConverter = int + UnambiguousUser = discord.User + UnambiguousMember = discord.Member + Infraction = dict | None Expiry = Duration | ISODateTime DurationOrExpiry = DurationDelta | ISODateTime |