pyrofork/pyrogram/methods/pyromod/register_next_step_handler.py
wulan17 d6e0a4f520
Pyrofork: Add pyromod documentation
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2023-12-13 12:09:40 +07:00

84 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2020 Cezar H. <https://github.com/usernein>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrofork.
#
# Pyrofork is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrofork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from pyrogram.filters import Filter
from typing import Callable, List, Optional, Union
from pyrogram.types import ListenerTypes, Identifier, Listener
class RegisterNextStepHandler:
def register_next_step_handler(
self: "pyrogram.Client",
callback: Callable,
filters: Optional[Filter] = None,
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
unallowed_click_alert: bool = True,
chat_id: Union[Union[int, str], List[Union[int, str]]] = None,
user_id: Union[Union[int, str], List[Union[int, str]]] = None,
message_id: Union[int, List[int]] = None,
inline_message_id: Union[str, List[str]] = None,
):
"""Registers a listener with a callback to be called when the listener is fulfilled.
.. include:: /_includes/usable-by/users-bots.rst
Parameters:
callback (``Callable``):
The callback to call when the listener is fulfilled.
user_id (``int`` | ``str`` | Iterable of ``int`` | Iterable of ``str``, *optional*):
The user ID to listen for.
filters (:obj:`~pyrogram.filters`, *optional*):
A filter to check the incoming message against.
listener_type (:obj:`~pyrogram.types.ListenerTypes`, *optional*):
The type of listener to listen for.
Default to Message.
timeout (``int``, *optional*):
The maximum amount of time to wait for a message.
unallowed_click_alert (``bool``, *optional*):
Whether to alert the user if they click a button that doesnt match the filters.
Default to True.
message_id (``int``, *optional*):
The message ID to listen for.
inline_message_id (``str``, *optional*):
The inline message ID to listen for.
"""
pattern = Identifier(
from_user_id=user_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
)
listener = Listener(
callback=callback,
filters=filters,
unallowed_click_alert=unallowed_click_alert,
identifier=pattern,
listener_type=listener_type,
)
self.listeners[listener_type].append(listener)