diff --git a/revolt/ext/commands/command.py b/revolt/ext/commands/command.py index deaa727..f6cb27a 100755 --- a/revolt/ext/commands/command.py +++ b/revolt/ext/commands/command.py @@ -148,8 +148,20 @@ class Command(Generic[ClientT_Co_D]): elif origin is Annotated: annotated_args = get_args(annotation) - if origin := get_origin(annotated_args[0]): - return await cls.handle_origin(context, origin, annotated_args[1], arg) + if annotated_args[1] == "_revolt_greedy_marker": + real_annotation = get_args(annotated_args[0])[0] + converted_args: list[Any] = [] + + converted_args.append(await cls.convert_argument(arg, real_annotation, context)) + + for arg in context.view: + try: + converted_args.append(await cls.convert_argument(arg, real_annotation, context)) + except: + context.view.undo() + break + + return converted_args else: return await cls.convert_argument(arg, annotated_args[1], context) diff --git a/revolt/ext/commands/converters.py b/revolt/ext/commands/converters.py index 88342d3..c9e9fe7 100755 --- a/revolt/ext/commands/converters.py +++ b/revolt/ext/commands/converters.py @@ -13,7 +13,9 @@ from .errors import (BadBoolArgument, CategoryConverterError, if TYPE_CHECKING: from .client import CommandsClient -__all__: tuple[str, ...] = ("bool_converter", "category_converter", "channel_converter", "user_converter", "member_converter", "IntConverter", "BoolConverter", "CategoryConverter", "UserConverter", "MemberConverter", "ChannelConverter") +T = TypeVar("T") + +__all__: tuple[str, ...] = ("bool_converter", "category_converter", "channel_converter", "user_converter", "member_converter", "IntConverter", "BoolConverter", "CategoryConverter", "UserConverter", "MemberConverter", "ChannelConverter", "Greedy") channel_regex: re.Pattern[str] = re.compile("<#([A-z0-9]{26})>") user_regex: re.Pattern[str] = re.compile("<@([A-z0-9]{26})>") @@ -120,3 +122,5 @@ CategoryConverter = Annotated[Category, category_converter] UserConverter = Annotated[User, user_converter] MemberConverter = Annotated[Member, member_converter] ChannelConverter = Annotated[Channel, channel_converter] + +Greedy = Annotated[list[T], "_revolt_greedy_marker"] \ No newline at end of file diff --git a/revolt/ext/commands/view.py b/revolt/ext/commands/view.py index f029a29..5f732d5 100755 --- a/revolt/ext/commands/view.py +++ b/revolt/ext/commands/view.py @@ -1,4 +1,6 @@ from typing import Iterator +from typing_extensions import Self + from .errors import NoClosingQuote @@ -52,3 +54,9 @@ class StringView: self.temp = output return output + + def __iter__(self) -> Self: + return self + + def __next__(self) -> str: + return self.get_next_word() \ No newline at end of file