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