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

feat(commands): Add support for Range[LargeInt, ...] #1201

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/1201.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Add support for ``Range[LargeInt, ...]`` in command parameters
4 changes: 2 additions & 2 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ def __init__(
self.required: bool = required
self.options: List[Option] = options or []

if min_value and self.type is OptionType.integer:
if min_value is not None and self.type is OptionType.integer:
min_value = math.ceil(min_value)
if max_value and self.type is OptionType.integer:
if max_value is not None and self.type is OptionType.integer:
max_value = math.floor(max_value)

self.min_value: Optional[float] = min_value
Expand Down
31 changes: 31 additions & 0 deletions disnake/ext/commands/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,37 @@ def __init__(self, argument: str) -> None:
super().__init__(f"{argument} is not able to be converted to an integer")


class LargeIntOutOfRange(BadArgument):
"""Exception raised when an argument to a large integer option exceeds given range.

This inherits from :exc:`BadArgument`

.. versionadded:: 2.11

Attributes
----------
argument: :class:`str`
The argument that exceeded the defined range.
min_value: Optional[Union[:class:`int`, :class:`float`]]
The minimum allowed value.
max_value: Optional[Union[:class:`int`, :class:`float`]]
The maximum allowed value.
"""

def __init__(
self,
argument: str,
min_value: Union[int, float, None],
max_value: Union[int, float, None],
) -> None:
self.argument: str = argument
self.min_value: Union[int, float, None] = min_value
self.max_value: Union[int, float, None] = max_value
a = "..." if min_value is None else min_value
b = "..." if max_value is None else max_value
super().__init__(f"{argument} is not in range [{a}, {b}]")


class DisabledCommand(CommandError):
"""Exception raised when the command being invoked is disabled.

Expand Down
Loading
Loading