Skip to content

Commit

Permalink
Add get_option method to autocomplete context
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Feb 20, 2024
1 parent 936ae0a commit e92458d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lightbulb/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class AutocompleteContext:

@property
def focused(self) -> hikari.AutocompleteInteractionOption:
"""The focused option for the autocomplete interaction."""
"""
The focused option for the autocomplete interaction - the option currently being autocompleted.
See Also:
:meth:`~AutocompleteContext.get_option`
"""
if self._focused is not None:
return self._focused

Expand All @@ -76,6 +81,22 @@ def focused(self) -> hikari.AutocompleteInteractionOption:
self._focused = found
return self._focused

def get_option(self, name: str) -> t.Optional[hikari.AutocompleteInteractionOption]:
"""
Get the option with the given name if available.
Args:
name (:obj:`str`): The name of the option to get.
Returns:
:obj:`~typing.Optional` [ :obj:`hikari.interactions.command_interactions.AutocompleteInteractionOption` ]: The
option, or :obj:`None` if not available from the interaction.
See Also:
:obj:`~AutocompleteContext.focused`
""" # noqa: E501
return next(filter(lambda opt: opt.name == name, self.options), None)

@staticmethod
def _normalise_choices(choices: AutocompleteResponseT) -> t.Sequence[special_endpoints.AutocompleteChoiceBuilder]:
if isinstance(choices, dict):
Expand Down

0 comments on commit e92458d

Please sign in to comment.