mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
parent
606c2f50ba
commit
fa4990f327
@ -74,19 +74,26 @@ async def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
return token
|
||||
|
||||
|
||||
def positive_int(arg: str) -> int:
|
||||
def non_negative_int(arg: str) -> int:
|
||||
try:
|
||||
x = int(arg)
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("Message cache size has to be a number.")
|
||||
raise argparse.ArgumentTypeError("The argument has to be a number.")
|
||||
if x < 0:
|
||||
raise argparse.ArgumentTypeError("The argument has to be a non-negative integer.")
|
||||
if x > sys.maxsize:
|
||||
raise argparse.ArgumentTypeError(
|
||||
f"The argument has to be lower than or equal to {sys.maxsize}."
|
||||
)
|
||||
return x
|
||||
|
||||
|
||||
def message_cache_size_int(arg: str) -> int:
|
||||
x = non_negative_int(arg)
|
||||
if x < 1000:
|
||||
raise argparse.ArgumentTypeError(
|
||||
"Message cache size has to be greater than or equal to 1000."
|
||||
)
|
||||
if x > sys.maxsize:
|
||||
raise argparse.ArgumentTypeError(
|
||||
f"Message cache size has to be lower than or equal to {sys.maxsize}."
|
||||
)
|
||||
return x
|
||||
|
||||
|
||||
@ -230,7 +237,7 @@ def parse_cli_flags(args):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--message-cache-size",
|
||||
type=positive_int,
|
||||
type=message_cache_size_int,
|
||||
default=1000,
|
||||
help="Set the maximum number of messages to store in the internal message cache.",
|
||||
)
|
||||
@ -265,7 +272,7 @@ def parse_cli_flags(args):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rich-traceback-extra-lines",
|
||||
type=positive_int,
|
||||
type=non_negative_int,
|
||||
default=0,
|
||||
help="Set the number of additional lines of code before and after the executed line"
|
||||
" that should be shown in tracebacks generated by Rich.\n"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user