@@ -1306,11 +1306,11 @@ def generate_snowflake(dt: datetime.datetime | None = None) -> int:
1306
1306
AV = Awaitable [V ]
1307
1307
Values = Union [V , Callable [[AutocompleteContext ], Union [V , AV ]], AV ]
1308
1308
AutocompleteFunc = Callable [[AutocompleteContext ], AV ]
1309
- CheckFunc = Callable [[AutocompleteContext , Any ], Union [bool , Awaitable [bool ]]]
1309
+ FilterFunc = Callable [[AutocompleteContext , Any ], Union [bool , Awaitable [bool ]]]
1310
1310
1311
1311
1312
1312
def basic_autocomplete (
1313
- values : Values , * , check : CheckFunc | None = None
1313
+ values : Values , * , filter : FilterFunc | None = None
1314
1314
) -> AutocompleteFunc :
1315
1315
"""A helper function to make a basic autocomplete for slash commands. This is a pretty standard autocomplete and
1316
1316
will return any options that start with the value from the user, case-insensitive. If the ``values`` parameter is
@@ -1323,9 +1323,9 @@ def basic_autocomplete(
1323
1323
values: Union[Union[Iterable[:class:`.OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`.AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
1324
1324
Possible values for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
1325
1325
single argument of :class:`.AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
1326
- check : Optional[Callable[[:class:`.AutocompleteContext`, Any], Union[:class:`bool`, Awaitable[:class:`bool`]]]]
1326
+ filter : Optional[Callable[[:class:`.AutocompleteContext`, Any], Union[:class:`bool`, Awaitable[:class:`bool`]]]]
1327
1327
Predicate callable (sync or async) used to filter the autocomplete options. This function should accept two arguments:
1328
- the :class:`.AutocompleteContext` and an item from ``values``. If ``None`` is provided, a default check is used that includes items whose string representation starts with the user's input value, case-insensitive.
1328
+ the :class:`.AutocompleteContext` and an item from ``values``. If ``None`` is provided, a default filter is used that includes items whose string representation starts with the user's input value, case-insensitive.
1329
1329
1330
1330
Returns
1331
1331
-------
@@ -1361,22 +1361,22 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V:
1361
1361
if asyncio .iscoroutine (_values ):
1362
1362
_values = await _values
1363
1363
1364
- if check is None :
1364
+ if filter is None :
1365
1365
1366
- def _check (ctx : AutocompleteContext , item : Any ) -> bool :
1366
+ def _filter (ctx : AutocompleteContext , item : Any ) -> bool :
1367
1367
item = getattr (item , "name" , item )
1368
1368
return str (item ).lower ().startswith (str (ctx .value or "" ).lower ())
1369
1369
1370
- gen = (val for val in _values if _check (ctx , val ))
1370
+ gen = (val for val in _values if _filter (ctx , val ))
1371
1371
1372
- elif asyncio .iscoroutinefunction (check ):
1373
- gen = (val for val in _values if await check (ctx , val ))
1372
+ elif asyncio .iscoroutinefunction (filter ):
1373
+ gen = (val for val in _values if await filter (ctx , val ))
1374
1374
1375
- elif callable (check ):
1376
- gen = (val for val in _values if check (ctx , val ))
1375
+ elif callable (filter ):
1376
+ gen = (val for val in _values if filter (ctx , val ))
1377
1377
1378
1378
else :
1379
- raise TypeError ("``check `` must be callable." )
1379
+ raise TypeError ("``filter `` must be callable." )
1380
1380
1381
1381
return iter (itertools .islice (gen , 25 ))
1382
1382
0 commit comments