Handler

class pyrubrum.Handler(nodes: Set[pyrubrum.tree.node.Node])

Implementation of a simple handler for non-parameterized menus which has got, by definition, multiple top-level nodes whose linked menus are displayed to the user whenever a message is being handled and matches one of their filters.

Parameters

nodes (Set[Node]) – The top-level nodes, which represent the text commands that are available to the user.

Note

In order to make use of parameterized menus (e.g. PageMenu) or to pass parameters between menus, you will have to use an handler which supports such feature (e.g. ParameterizedHandler).

get_family(menu_id: str) → Tuple[Optional[pyrubrum.menus.base_menu.BaseMenu], Optional[Iterable[pyrubrum.menus.base_menu.BaseMenu]]]

Retrieve the menus which are linked to both parent and children of the top-level nodes of this instance if this instance matches the provided identifier. Otherwise it will search the menu matching it in the children of the :term:top-level nodes <Top-level node>` and will return their own families, if matched. On failure, it will return a tuple of length two filled with null values (i.e. None).

Parameters

menu_id (str) – The identifier which must be matched.

Returns

A tuple of length two, whose first element is the parent node of the matched node while the second one is a tuple of all its children If no Node is found, the tuple will be filled with null values (i.e. None).

Return type

Tuple[Optional[BaseMenu], Optional[Iterable[BaseMenu]]]

get_menus() → Set[pyrubrum.menus.base_menu.BaseMenu]

Retrieve the set of all the menus which are linked to the nodes belonging to the descent of the top-level nodes of this class (i.e. the children, the children of the children, etc…). In other words, it retrieves all the menus which were defined at the initialization of this instance.

Returns

The set of all the retrieved menus.

Return type

Set[BaseMenu]

setup(client: pyrogram.client.client.Client)

Set up a client instance by adding filters for handling callbacks and messages. If there is a default menu, it adds it using MessageHandler.

Parameters

client (Client) – The client you are setting up. It must be a bot instance in order to work.