Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed [p]ban raising an unhandled error if an ID too large is provided #6486

Open
wants to merge 1 commit into
base: V3/develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions redbot/core/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

_ = Translator("commands.converter", __file__)

ID_REGEX = re.compile(r"([0-9]{15,20})")
USER_MENTION_REGEX = re.compile(r"<@!?([0-9]{15,21})>$")
ID_REGEX = re.compile(r"([0-9]{15,19})")
USER_MENTION_REGEX = re.compile(r"<@!?([0-9]{15,19})>$")


# Taken with permission from
Expand Down Expand Up @@ -239,8 +239,16 @@ async def convert(self, ctx: "Context", argument: str) -> int:
# are most likely not in the guild.
# Mentions are supported, but most likely won't ever be in cache.

if match := ID_REGEX.match(argument) or USER_MENTION_REGEX.match(argument):
return int(match.group(1))
if match := ID_REGEX.fullmatch(argument) or USER_MENTION_REGEX.fullmatch(argument):
user_id = int(match.group(1))

# Validate user ID range (Discord user IDs are 64-bit integers but must be ≤ 2^63 - 1)
if user_id > 9223372036854775807: # 2^63 - 1
raise BadArgument(
f"The ID '{argument}' is too large to be a valid Discord user ID."
)

return user_id

raise BadArgument(_("'{input}' doesn't look like a valid user ID.").format(input=argument))

Expand Down
Loading