-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathask.py
More file actions
104 lines (84 loc) · 3.68 KB
/
ask.py
File metadata and controls
104 lines (84 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Hydrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2020-present Cezar H. <https://github.com/usernein>
# Copyright (C) 2023-present Hydrogram <https://hydrogram.org>
#
# This file is part of Hydrogram.
#
# Hydrogram 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.
#
# Hydrogram 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 Hydrogram. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import TYPE_CHECKING
from hydrogram.types import ListenerTypes
if TYPE_CHECKING:
import hydrogram
from hydrogram.filters import Filter
class Ask:
async def ask(
self: hydrogram.Client,
chat_id: int | str | list[int | str],
text: str,
filters: Filter | None = None,
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
timeout: int | None = None,
unallowed_click_alert: bool = True,
user_id: int | str | list[int | str] | None = None,
message_id: int | list[int] | None = None,
inline_message_id: str | list[str] | None = None,
*args,
**kwargs,
):
"""
Sends a message and waits for a response.
Parameters:
chat_id (``Union[int, str], List[Union[int, str]]``):
The chat ID(s) to wait for a message from. The first chat ID will be used to send the message.
text (``str``):
The text to send.
filters (``Optional[Filter]``):
Same as :meth:`hydrogram.Client.listen`.
listener_type (``ListenerTypes``):
Same as :meth:`hydrogram.Client.listen`.
timeout (``Optional[int]``):
Same as :meth:`hydrogram.Client.listen`.
unallowed_click_alert (``bool``):
Same as :meth:`hydrogram.Client.listen`.
user_id (``Optional[Union[int, str], List[Union[int, str]]]``):
Same as :meth:`hydrogram.Client.listen`.
message_id (``Optional[Union[int, List[int]]]``):
Same as :meth:`hydrogram.Client.listen`.
inline_message_id (``Optional[Union[str, List[str]]]``):
Same as :meth:`hydrogram.Client.listen`.
args (``Any``):
Additional arguments to pass to :meth:`hydrogram.Client.send_message`.
kwargs (``Any``):
Additional keyword arguments to pass to :meth:`hydrogram.Client.send_message`.
Returns:
Same as :meth:`hydrogram.Client.listen`. The sent message is returned as the attribute ``sent_message``.
"""
sent_message = None
if text.strip():
chat_to_ask = chat_id[0] if isinstance(chat_id, list) else chat_id
sent_message = await self.send_message(chat_to_ask, text, *args, **kwargs)
response = await self.listen(
filters=filters,
listener_type=listener_type,
timeout=timeout,
unallowed_click_alert=unallowed_click_alert,
chat_id=chat_id,
user_id=user_id,
message_id=message_id,
inline_message_id=inline_message_id,
)
if response:
response.sent_message = sent_message
return response