mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 04:43:45 +03:00
update ButtonCallback to handle types.UpdateInlineBotCallbackQuery
This commit is contained in:
parent
70fb266eea
commit
8948c8cef9
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Dict, Optional, Self
|
from typing import TYPE_CHECKING, Dict, Optional, Self, Union
|
||||||
|
|
||||||
from ...tl import abcs, functions, types
|
from ...tl import abcs, functions, types
|
||||||
from ..types import Chat, Message
|
from ..types import Chat, Message
|
||||||
|
@ -22,7 +22,7 @@ class ButtonCallback(Event):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
client: Client,
|
client: Client,
|
||||||
update: types.UpdateBotCallbackQuery,
|
update: Union[types.UpdateBotCallbackQuery, types.UpdateInlineBotCallbackQuery],
|
||||||
chat_map: Dict[int, Chat],
|
chat_map: Dict[int, Chat],
|
||||||
):
|
):
|
||||||
self._client = client
|
self._client = client
|
||||||
|
@ -33,7 +33,10 @@ class ButtonCallback(Event):
|
||||||
def _try_from_update(
|
def _try_from_update(
|
||||||
cls, client: Client, update: abcs.Update, chat_map: Dict[int, Chat]
|
cls, client: Client, update: abcs.Update, chat_map: Dict[int, Chat]
|
||||||
) -> Optional[Self]:
|
) -> Optional[Self]:
|
||||||
if isinstance(update, types.UpdateBotCallbackQuery) and update.data is not None:
|
if (
|
||||||
|
isinstance(update, (types.UpdateBotCallbackQuery, types.UpdateInlineBotCallbackQuery))
|
||||||
|
and update.data is not None
|
||||||
|
):
|
||||||
return cls._create(client, update, chat_map)
|
return cls._create(client, update, chat_map)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -43,6 +46,16 @@ class ButtonCallback(Event):
|
||||||
assert self._raw.data is not None
|
assert self._raw.data is not None
|
||||||
return self._raw.data
|
return self._raw.data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def chat(self) -> Optional[Chat]:
|
||||||
|
"""
|
||||||
|
The :term:`chat` when the message was sent.
|
||||||
|
Only available if the event was triggered by a button under usual message, not an inline one.
|
||||||
|
"""
|
||||||
|
if isinstance(self._raw, types.UpdateInlineBotCallbackQuery):
|
||||||
|
return None
|
||||||
|
return self._chat_map.get(peer_id(self._raw.peer))
|
||||||
|
|
||||||
async def answer(
|
async def answer(
|
||||||
self,
|
self,
|
||||||
text: Optional[str] = None,
|
text: Optional[str] = None,
|
||||||
|
@ -75,8 +88,10 @@ class ButtonCallback(Event):
|
||||||
"""
|
"""
|
||||||
Get the :class:`~telethon.types.Message` containing the button that was clicked.
|
Get the :class:`~telethon.types.Message` containing the button that was clicked.
|
||||||
|
|
||||||
If the message is too old and is no longer accessible, :data:`None` is returned instead.
|
If the message is inline, or too old and is no longer accessible, :data:`None` is returned instead.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(self._raw, types.UpdateInlineBotCallbackQuery):
|
||||||
|
return None
|
||||||
|
|
||||||
pid = peer_id(self._raw.peer)
|
pid = peer_id(self._raw.peer)
|
||||||
chat = self._chat_map.get(pid)
|
chat = self._chat_map.get(pid)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user