Stark.inline

Python decorator of class Stark to handle inline queries.

static Inline.inline(query: Optional[Union[str, List[str]]] = None, startswith: bool = False, owner_only: bool = False, group: int = 0, filters=None)

This decorator is used to handle inline queries. All arguments are optional.

Parameters:
query (str | List of str, optional) -

Query on which your function is called. Pass a list to handle multiple queries. Defaults to None, to handle all queries if your function handles all or if you are using other ‘filters’

startswith (bool, optional) -

Set to True if you want your function to handle all queries starting with the ‘query’ string passed. Defaults to False.

owner_only (bool, optional) -

Allow only owner to use this command. Defaults to False.

group (int, optional) -

Define a group for this handler. Defaults to 0. Read More

filters (optional) -

Extra filters to apply in your function. Import filters from pyrogram or pystark to use this. See example below.

Examples

from pystark import Stark

# The normal and easiest way.
# Bot will show results / execute function, if 'hello' is searched by anyone.
@Stark.inline('hello')

# Handle multiple inline queries in one function. Mainly used to execute same function or do some other pythonic thing, like if-else loop.
# Bot will show results / execute function, if 'hello' or 'hey' is searched by anyone.
@Stark.inline(['hello', 'hey'])

# Function will only be triggered if owner searches 'hello', that is, the user whose id is set as OWNER_ID in environment variables.
# Others will be ignored.
@Stark.inline('hello', owner_only=True)

# Filter/Handle all queries.

# Use positive integer to execute after executing another function in default group that also filtered this query.
@Stark.inline(group=1)

# or Use negative integer to execute before executing another function in default group that also filtered this query.
@Stark.inline(group=-1)

# Don't use this as other functions that handle queries won't work.
@Stark.inline()

# Filter other type of queries using 'filters' argument.

# Import filters from pyrogram or pystark.
from pystark import filters

# Filter only queries by 'StarkProgrammer' and 'Designatory'.
@Stark.inline(filters=filters.user(['StarkProgrammer', 'Designatory']))

# Filter only queries done in 'StarkBotsChat'
@Stark.inline(filters=filters.chat('StarkBotsChat'))

# Filter only queries ending with the word 'baby'.
@Stark.inline(filters=filters.regex(r'baby$'))

# Filter all queries with the word 'hello' AND which are done in 'StarkBotsChat'.
@Stark.inline(filters=filters.chat('StarkBotsChat') & filters.regex('hello'))
# or
@Stark.inline('hello', filters=filters.chat('StarkBotsChat'))

# Filter all queries with the word 'bots' OR which are done in 'StarkBotsChat'
@Stark.inline(filters=filters.chat('StarkBotsChat') | filters.regex('hello'))

# Filter all queries with the word 'bots' BUT which are NOT done in 'StarkBotsChat'
@Stark.inline(filters=~filters.chat('StarkBotsChat') & filters.regex('hello'))
# or
@Stark.inline(filters=filters.regex('hello') & ~filters.chat('StarkBotsChat'))