diff --git a/lightbulb/components/menus.py b/lightbulb/components/menus.py index 5ce53c1e..2aa73425 100644 --- a/lightbulb/components/menus.py +++ b/lightbulb/components/menus.py @@ -55,13 +55,11 @@ from lightbulb import client as client_ - ValidSelectOptions: t.TypeAlias = t.Union[Sequence["TextSelectOption"], - Sequence[str], Sequence[tuple[str, str]]] + ValidSelectOptions: t.TypeAlias = t.Union[Sequence["TextSelectOption"], Sequence[str], Sequence[tuple[str, str]]] ComponentCallback: t.TypeAlias = Callable[["MenuContext"], Awaitable[None]] T = t.TypeVar("T") -MessageComponentT = t.TypeVar( - "MessageComponentT", bound=base.BaseComponent[special_endpoints.MessageActionRowBuilder]) +MessageComponentT = t.TypeVar("MessageComponentT", bound=base.BaseComponent[special_endpoints.MessageActionRowBuilder]) Emojiish: t.TypeAlias = t.Union[hikari.Snowflakeish, str, hikari.Emoji] @@ -69,8 +67,7 @@ class InteractiveButton(base.BaseComponent[special_endpoints.MessageActionRowBuilder]): """Class representing an interactive button.""" - __slots__ = ("_custom_id", "callback", "disabled", - "emoji", "label", "style") + __slots__ = ("_custom_id", "callback", "disabled", "emoji", "label", "style") def __init__( self, @@ -143,8 +140,7 @@ def add_to_row(self, row: special_endpoints.MessageActionRowBuilder) -> special_ class Select(t.Generic[T], base.BaseComponent[special_endpoints.MessageActionRowBuilder], abc.ABC): """Dataclass representing a generic select menu.""" - __slots__ = ("_custom_id", "callback", "disabled", - "max_values", "min_values", "placeholder") + __slots__ = ("_custom_id", "callback", "disabled", "max_values", "min_values", "placeholder") def __init__( self, @@ -226,8 +222,7 @@ def add_to_row(self, row: special_endpoints.MessageActionRowBuilder) -> special_ if isinstance(option, str): normalised_options.append(TextSelectOption(option, option)) elif isinstance(option, tuple): - normalised_options.append( - TextSelectOption(option[0], option[1])) + normalised_options.append(TextSelectOption(option[0], option[1])) else: normalised_options.append(option) @@ -310,8 +305,7 @@ def __init__( ) -> None: super().__init__(custom_id, placeholder, min_values, max_values, disabled, callback) - self.channel_types: hikari.UndefinedOr[Sequence[hikari.ChannelType] - ] = channel_types + self.channel_types: hikari.UndefinedOr[Sequence[hikari.ChannelType]] = channel_types """Channel types permitted to be shown as options.""" def add_to_row(self, row: special_endpoints.MessageActionRowBuilder) -> special_endpoints.MessageActionRowBuilder: @@ -442,7 +436,7 @@ def selected_values_for(self, select: Select[T]) -> Sequence[T]: resolved_data.members.get(sf) or resolved_data.users.get(sf) or resolved_data.roles.get(sf) - or resolved_data.channels[sf] # type: ignore[reportArgumentType] + or resolved_data.channels[sf] # type: ignore[reportArgumentType] ) return resolved @@ -452,8 +446,7 @@ async def respond_with_modal( title: str, custom_id: str, component: hikari.UndefinedOr[special_endpoints.ComponentBuilder] = hikari.UNDEFINED, - components: hikari.UndefinedOr[Sequence[special_endpoints.ComponentBuilder] - ] = hikari.UNDEFINED, + components: hikari.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = hikari.UNDEFINED, ) -> None: """ Create a modal response to the interaction that this context represents. @@ -472,8 +465,7 @@ async def respond_with_modal( """ async with self._response_lock: if self._initial_response_sent: - raise RuntimeError( - "cannot respond with a modal if an initial response has already been sent") + raise RuntimeError("cannot respond with a modal if an initial response has already been sent") await self.interaction.create_modal_response(title, custom_id, component, components) self._initial_response_sent = True @@ -488,18 +480,14 @@ async def respond( flags: int | hikari.MessageFlag | hikari.UndefinedType = hikari.UNDEFINED, tts: hikari.UndefinedOr[bool] = hikari.UNDEFINED, attachment: hikari.UndefinedOr[hikari.Resourceish] = hikari.UNDEFINED, - attachments: hikari.UndefinedOr[Sequence[hikari.Resourceish] - ] = hikari.UNDEFINED, + attachments: hikari.UndefinedOr[Sequence[hikari.Resourceish]] = hikari.UNDEFINED, component: hikari.UndefinedOr[special_endpoints.ComponentBuilder] = hikari.UNDEFINED, - components: hikari.UndefinedOr[Sequence[special_endpoints.ComponentBuilder] - ] = hikari.UNDEFINED, + components: hikari.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = hikari.UNDEFINED, embed: hikari.UndefinedOr[hikari.Embed] = hikari.UNDEFINED, embeds: hikari.UndefinedOr[Sequence[hikari.Embed]] = hikari.UNDEFINED, mentions_everyone: hikari.UndefinedOr[bool] = hikari.UNDEFINED, - user_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[hikari.PartialUser] - | bool] = hikari.UNDEFINED, - role_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[hikari.PartialRole] - | bool] = hikari.UNDEFINED, + user_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[hikari.PartialUser] | bool] = hikari.UNDEFINED, + role_mentions: hikari.UndefinedOr[hikari.SnowflakeishSequence[hikari.PartialRole] | bool] = hikari.UNDEFINED, ) -> hikari.Snowflakeish: """ Create a response to the interaction that this context represents. @@ -592,8 +580,7 @@ def add_interactive_button( *, custom_id: hikari.UndefinedOr[str] = hikari.UNDEFINED, label: hikari.UndefinedOr[str] = hikari.UNDEFINED, - emoji: hikari.UndefinedOr[hikari.Snowflakeish | - str | hikari.Emoji] = hikari.UNDEFINED, + emoji: hikari.UndefinedOr[hikari.Snowflakeish | str | hikari.Emoji] = hikari.UNDEFINED, disabled: bool = False, ) -> InteractiveButton: """ @@ -615,8 +602,7 @@ def add_interactive_button( :obj:`ValueError`: When neither ``label`` nor ``emoji`` are specified. """ if label is hikari.UNDEFINED and emoji is hikari.UNDEFINED: - raise ValueError( - "at least one of 'label' and 'emoji' must be specified") + raise ValueError("at least one of 'label' and 'emoji' must be specified") return self.add( InteractiveButton( @@ -634,8 +620,7 @@ def add_link_button( url: str, *, label: hikari.UndefinedOr[str] = hikari.UNDEFINED, - emoji: hikari.UndefinedOr[hikari.Snowflakeish | - str | hikari.Emoji] = hikari.UNDEFINED, + emoji: hikari.UndefinedOr[hikari.Snowflakeish | str | hikari.Emoji] = hikari.UNDEFINED, disabled: bool = False, ) -> LinkButton: """ @@ -654,8 +639,7 @@ def add_link_button( :obj:`ValueError`: When neither ``label`` nor ``emoji`` are specified. """ if label is hikari.UNDEFINED and emoji is hikari.UNDEFINED: - raise ValueError( - "at least one of 'label' and 'emoji' must be specified") + raise ValueError("at least one of 'label' and 'emoji' must be specified") return self.add(LinkButton(url=url, label=label, emoji=emoji, disabled=disabled)) @@ -815,8 +799,7 @@ def add_channel_select( min_values: int = 1, max_values: int = 1, disabled: bool = False, - channel_types: hikari.UndefinedOr[Sequence[hikari.ChannelType] - ] = hikari.UNDEFINED, + channel_types: hikari.UndefinedOr[Sequence[hikari.ChannelType]] = hikari.UNDEFINED, ) -> ChannelSelect: """ Add a channel select menu to this menu. @@ -847,8 +830,7 @@ def add_channel_select( ) async def _run_menu(self, client: client_.Client, timeout: float | None = None) -> None: # noqa: ASYNC109 - all_custom_ids: dict[str, - base.BaseComponent[special_endpoints.MessageActionRowBuilder]] = {} + all_custom_ids: dict[str, base.BaseComponent[special_endpoints.MessageActionRowBuilder]] = {} re_resolve_custom_ids: bool = True queue: asyncio.Queue[hikari.ComponentInteraction] = asyncio.Queue() @@ -877,8 +859,7 @@ async def _run_menu(self, client: client_.Client, timeout: float | None = None) ) if await self.predicate(context): - callback: t.Callable[[MenuContext], t.Awaitable[None]] = getattr( - component, "callback") + callback: t.Callable[[MenuContext], t.Awaitable[None]] = getattr(component, "callback") await callback(context) stopped = context._should_stop_menu