pyrofork/pyrogram/methods/utilities/ask.py
Cezar Pauxis e39fdcca0e
PyroFork: Add listen and ask
Co-authored-by: wulan17 <wulan17@nusantararom.org>
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2023-01-05 01:58:09 +07:00

68 lines
2.3 KiB
Python

# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import logging
import pyrogram
from typing import Union
log = logging.getLogger(__name__)
class Ask:
async def ask(
self: "pyrogram.Client",
chat_id: Union[str, int],
text: str,
filters=None,
timeout: int = None,
*args,
**kwargs
):
"""Send message then awaits for a new message in the specified chat.
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
text (``str``):
Text of the message to be sent.
filters (:obj:`~pyrogram.filters`, *optional*):
Pass one or more filters to allow only a subset of messages to be passed
in your function.
timeout (``int``, *optional*):
The waiting timeout.
Returns:
:obj:`~pyrogram.types.Message`: On success, text message is returned.
Example:
.. code-block:: python
answer = await Client.listen(chat_id, "Your name:")
name = answer.text
"""
request = await self.send_message(chat_id, text, *args, **kwargs)
response = await self.listen(chat_id, filters, timeout)
response.request = request
return response