Skip to content

Commit fa583f0

Browse files
Eneggshiftinv
andauthored
feat(commands): Add support for Range[LargeInt, ...] (#1201)
Signed-off-by: Eneg <42005170+Enegg@users.noreply.github.com> Signed-off-by: vi <8530778+shiftinv@users.noreply.github.com> Co-authored-by: vi <8530778+shiftinv@users.noreply.github.com>
1 parent 2bfeac1 commit fa583f0

10 files changed

Lines changed: 405 additions & 153 deletions

File tree

changelog/1201.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
|commands| Add support for ``Range[LargeInt, ...]`` in slash command parameters.

disnake/app_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ def __init__(
289289
self.required: bool = required
290290
self.options: list[Option] = options or []
291291

292-
if min_value and self.type is OptionType.integer:
292+
if min_value is not None and self.type is OptionType.integer:
293293
min_value = math.ceil(min_value)
294-
if max_value and self.type is OptionType.integer:
294+
if max_value is not None and self.type is OptionType.integer:
295295
max_value = math.floor(max_value)
296296

297297
self.min_value: float | None = min_value

disnake/ext/commands/errors.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"PartialEmojiConversionFailure",
5757
"BadBoolArgument",
5858
"LargeIntConversionFailure",
59+
"LargeIntOutOfRange",
5960
"MissingRole",
6061
"BotMissingRole",
6162
"MissingAnyRole",
@@ -571,7 +572,38 @@ class LargeIntConversionFailure(BadArgument):
571572

572573
def __init__(self, argument: str) -> None:
573574
self.argument: str = argument
574-
super().__init__(f"{argument} is not able to be converted to an integer")
575+
super().__init__(f"{argument} is not a valid base 10 integer")
576+
577+
578+
class LargeIntOutOfRange(LargeIntConversionFailure):
579+
"""Exception raised when an argument to a large integer option exceeds given range.
580+
581+
This inherits from :exc:`LargeIntConversionFailure`
582+
583+
.. versionadded:: |vnext|
584+
585+
Attributes
586+
----------
587+
argument: :class:`str`
588+
The argument that exceeded the defined range.
589+
min_value: :class:`int` | :data:`None`
590+
The minimum allowed value.
591+
max_value: :class:`int` | :data:`None`
592+
The maximum allowed value.
593+
"""
594+
595+
def __init__(
596+
self,
597+
argument: str,
598+
min_value: int | None,
599+
max_value: int | None,
600+
) -> None:
601+
self.argument: str = argument
602+
self.min_value: int | None = min_value
603+
self.max_value: int | None = max_value
604+
a = "..." if min_value is None else min_value
605+
b = "..." if max_value is None else max_value
606+
BadArgument.__init__(self, f"{argument} is not in range [{a}, {b}]")
575607

576608

577609
class DisabledCommand(CommandError):

0 commit comments

Comments
 (0)