mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-21 22:13:08 +03:00
Support await on any client.action
This commit is contained in:
parent
a3513d5232
commit
dc0f978b59
|
@ -750,3 +750,5 @@ keep support for explicit size instance?
|
||||||
renamed send_read_acknowledge. add send_read_acknowledge as alias for mark_read?
|
renamed send_read_acknowledge. add send_read_acknowledge as alias for mark_read?
|
||||||
|
|
||||||
force sms removed as it was broken anyway and not very reliable
|
force sms removed as it was broken anyway and not very reliable
|
||||||
|
|
||||||
|
you can now await client.action for a one-off any action not just cancel
|
||||||
|
|
|
@ -27,6 +27,9 @@ class _ChatAction:
|
||||||
self._task = None
|
self._task = None
|
||||||
self._running = False
|
self._running = False
|
||||||
|
|
||||||
|
def __await__(self):
|
||||||
|
return self._once().__await__()
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self._chat = await self._client.get_input_entity(self._chat)
|
self._chat = await self._client.get_input_entity(self._chat)
|
||||||
|
|
||||||
|
@ -51,6 +54,10 @@ class _ChatAction:
|
||||||
|
|
||||||
self._task = None
|
self._task = None
|
||||||
|
|
||||||
|
async def _once(self):
|
||||||
|
self._chat = await self._client.get_input_entity(self._chat)
|
||||||
|
await self._client(_tl.fn.messages.SetTyping(self._chat, self._action))
|
||||||
|
|
||||||
async def _update(self):
|
async def _update(self):
|
||||||
try:
|
try:
|
||||||
while self._running:
|
while self._running:
|
||||||
|
@ -456,11 +463,6 @@ def action(
|
||||||
auto_cancel: bool = True) -> 'typing.Union[_ChatAction, typing.Coroutine]':
|
auto_cancel: bool = True) -> 'typing.Union[_ChatAction, typing.Coroutine]':
|
||||||
action = _ChatAction._parse(action)
|
action = _ChatAction._parse(action)
|
||||||
|
|
||||||
if isinstance(action, _tl.SendMessageCancelAction):
|
|
||||||
# ``SetTyping.resolve`` will get input peer of ``entity``.
|
|
||||||
return self(_tl.fn.messages.SetTyping(
|
|
||||||
entity, _tl.SendMessageCancelAction()))
|
|
||||||
|
|
||||||
return _ChatAction(
|
return _ChatAction(
|
||||||
self, entity, action, delay=delay, auto_cancel=auto_cancel)
|
self, entity, action, delay=delay, auto_cancel=auto_cancel)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user