mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-27 08:19:47 +03:00
Rename ReplyMarkup to Keyboard
This commit is contained in:
parent
3bc4c949fb
commit
b2c49912fa
|
@ -45,7 +45,7 @@ from ..types import (
|
||||||
RecentAction,
|
RecentAction,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from ..types.buttons.reply_markup import ReplyMarkupType
|
from ..types.buttons.keyboard import KeyboardType
|
||||||
from .auth import (
|
from .auth import (
|
||||||
bot_sign_in,
|
bot_sign_in,
|
||||||
check_password,
|
check_password,
|
||||||
|
@ -252,12 +252,13 @@ class Client:
|
||||||
self._message_box = MessageBox(base_logger=base_logger)
|
self._message_box = MessageBox(base_logger=base_logger)
|
||||||
self._chat_hashes = ChatHashCache(None)
|
self._chat_hashes = ChatHashCache(None)
|
||||||
self._last_update_limit_warn: Optional[float] = None
|
self._last_update_limit_warn: Optional[float] = None
|
||||||
self._updates: asyncio.Queue[
|
self._updates: asyncio.Queue[tuple[abcs.Update, dict[int, Peer]]] = (
|
||||||
tuple[abcs.Update, dict[int, Peer]]
|
asyncio.Queue(maxsize=self._config.update_queue_limit or 0)
|
||||||
] = asyncio.Queue(maxsize=self._config.update_queue_limit or 0)
|
)
|
||||||
self._dispatcher: Optional[asyncio.Task[None]] = None
|
self._dispatcher: Optional[asyncio.Task[None]] = None
|
||||||
self._handlers: dict[
|
self._handlers: dict[
|
||||||
Type[Event], list[tuple[Callable[[Any], Awaitable[Any]], Optional[Filter]]]
|
Type[Event],
|
||||||
|
list[tuple[Callable[[Any], Awaitable[Any]], Optional[Filter]]],
|
||||||
] = {}
|
] = {}
|
||||||
self._check_all_handlers = check_all_handlers
|
self._check_all_handlers = check_all_handlers
|
||||||
|
|
||||||
|
@ -572,7 +573,7 @@ class Client:
|
||||||
markdown: Optional[str] = None,
|
markdown: Optional[str] = None,
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Edit a message.
|
Edit a message.
|
||||||
|
@ -587,10 +588,10 @@ class Client:
|
||||||
:param markdown: See :ref:`formatting`.
|
:param markdown: See :ref:`formatting`.
|
||||||
:param html: See :ref:`formatting`.
|
:param html: See :ref:`formatting`.
|
||||||
:param link_preview: See :ref:`formatting`.
|
:param link_preview: See :ref:`formatting`.
|
||||||
:param buttons:
|
:param keyboard:
|
||||||
The buttons to use for the message.
|
The keyboard to use for the message.
|
||||||
|
|
||||||
Only bot accounts can send buttons.
|
Only bot accounts can send keyboard.
|
||||||
|
|
||||||
:return: The edited message.
|
:return: The edited message.
|
||||||
|
|
||||||
|
@ -616,7 +617,7 @@ class Client:
|
||||||
markdown=markdown,
|
markdown=markdown,
|
||||||
html=html,
|
html=html,
|
||||||
link_preview=link_preview,
|
link_preview=link_preview,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def forward_messages(
|
async def forward_messages(
|
||||||
|
@ -1394,7 +1395,7 @@ class Client:
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Send an audio file.
|
Send an audio file.
|
||||||
|
@ -1438,7 +1439,7 @@ class Client:
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_file(
|
async def send_file(
|
||||||
|
@ -1467,7 +1468,7 @@ class Client:
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType],
|
keyboard: Optional[KeyboardType],
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Send any type of file with any amount of attributes.
|
Send any type of file with any amount of attributes.
|
||||||
|
@ -1621,7 +1622,7 @@ class Client:
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_message(
|
async def send_message(
|
||||||
|
@ -1634,7 +1635,7 @@ class Client:
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Send a message.
|
Send a message.
|
||||||
|
@ -1650,10 +1651,10 @@ class Client:
|
||||||
:param reply_to:
|
:param reply_to:
|
||||||
The message identifier of the message to reply to.
|
The message identifier of the message to reply to.
|
||||||
|
|
||||||
:param buttons:
|
:param keyboard:
|
||||||
The buttons to use for the message.
|
The keyboard to use for the message.
|
||||||
|
|
||||||
Only bot accounts can send buttons.
|
Only bot accounts can send keyboard.
|
||||||
|
|
||||||
.. rubric:: Example
|
.. rubric:: Example
|
||||||
|
|
||||||
|
@ -1669,7 +1670,7 @@ class Client:
|
||||||
html=html,
|
html=html,
|
||||||
link_preview=link_preview,
|
link_preview=link_preview,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_photo(
|
async def send_photo(
|
||||||
|
@ -1688,7 +1689,7 @@ class Client:
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Send a photo file.
|
Send a photo file.
|
||||||
|
@ -1734,7 +1735,7 @@ class Client:
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_video(
|
async def send_video(
|
||||||
|
@ -1756,7 +1757,7 @@ class Client:
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType],
|
keyboard: Optional[KeyboardType],
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Send a video file.
|
Send a video file.
|
||||||
|
@ -1803,7 +1804,7 @@ class Client:
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def set_chat_default_restrictions(
|
async def set_chat_default_restrictions(
|
||||||
|
|
|
@ -22,7 +22,7 @@ from ..types import (
|
||||||
parse_message,
|
parse_message,
|
||||||
try_get_url_path,
|
try_get_url_path,
|
||||||
)
|
)
|
||||||
from ..types.buttons.reply_markup import ReplyMarkupType
|
from ..types.buttons.keyboard import KeyboardType
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import Client
|
from .client import Client
|
||||||
|
@ -57,7 +57,7 @@ async def send_photo(
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
return await send_file(
|
return await send_file(
|
||||||
self,
|
self,
|
||||||
|
@ -77,7 +77,7 @@ async def send_photo(
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ async def send_audio(
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
return await send_file(
|
return await send_file(
|
||||||
self,
|
self,
|
||||||
|
@ -115,7 +115,7 @@ async def send_audio(
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ async def send_video(
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType],
|
keyboard: Optional[KeyboardType],
|
||||||
) -> Message:
|
) -> Message:
|
||||||
return await send_file(
|
return await send_file(
|
||||||
self,
|
self,
|
||||||
|
@ -157,7 +157,7 @@ async def send_video(
|
||||||
caption_markdown=caption_markdown,
|
caption_markdown=caption_markdown,
|
||||||
caption_html=caption_html,
|
caption_html=caption_html,
|
||||||
reply_to=reply_to,
|
reply_to=reply_to,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ async def send_file(
|
||||||
caption_markdown: Optional[str] = None,
|
caption_markdown: Optional[str] = None,
|
||||||
caption_html: Optional[str] = None,
|
caption_html: Optional[str] = None,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType],
|
keyboard: Optional[KeyboardType],
|
||||||
) -> Message:
|
) -> Message:
|
||||||
message, entities = parse_message(
|
message, entities = parse_message(
|
||||||
text=caption, markdown=caption_markdown, html=caption_html, allow_empty=True
|
text=caption, markdown=caption_markdown, html=caption_html, allow_empty=True
|
||||||
|
@ -196,7 +196,7 @@ async def send_file(
|
||||||
# Re-send existing file.
|
# Re-send existing file.
|
||||||
if isinstance(file, File):
|
if isinstance(file, File):
|
||||||
return await do_send_file(
|
return await do_send_file(
|
||||||
self, chat, file._input_media, message, entities, reply_to, buttons
|
self, chat, file._input_media, message, entities, reply_to, keyboard
|
||||||
)
|
)
|
||||||
|
|
||||||
# URLs are handled early as they can't use any other attributes either.
|
# URLs are handled early as they can't use any other attributes either.
|
||||||
|
@ -220,7 +220,7 @@ async def send_file(
|
||||||
spoiler=False, url=file, ttl_seconds=None
|
spoiler=False, url=file, ttl_seconds=None
|
||||||
)
|
)
|
||||||
return await do_send_file(
|
return await do_send_file(
|
||||||
self, chat, input_media, message, entities, reply_to, buttons
|
self, chat, input_media, message, entities, reply_to, keyboard
|
||||||
)
|
)
|
||||||
|
|
||||||
input_file, name = await upload(self, file, size, name)
|
input_file, name = await upload(self, file, size, name)
|
||||||
|
@ -286,7 +286,7 @@ async def send_file(
|
||||||
)
|
)
|
||||||
|
|
||||||
return await do_send_file(
|
return await do_send_file(
|
||||||
self, chat, input_media, message, entities, reply_to, buttons
|
self, chat, input_media, message, entities, reply_to, keyboard
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ async def do_send_file(
|
||||||
message: str,
|
message: str,
|
||||||
entities: Optional[list[abcs.MessageEntity]],
|
entities: Optional[list[abcs.MessageEntity]],
|
||||||
reply_to: Optional[int],
|
reply_to: Optional[int],
|
||||||
buttons: Optional[ReplyMarkupType],
|
keyboard: Optional[KeyboardType],
|
||||||
) -> Message:
|
) -> Message:
|
||||||
random_id = generate_random_id()
|
random_id = generate_random_id()
|
||||||
return client._build_message_map(
|
return client._build_message_map(
|
||||||
|
@ -317,7 +317,7 @@ async def do_send_file(
|
||||||
media=input_media,
|
media=input_media,
|
||||||
message=message,
|
message=message,
|
||||||
random_id=random_id,
|
random_id=random_id,
|
||||||
reply_markup=buttons._build() if buttons is not None else None,
|
reply_markup=keyboard._raw if keyboard else None,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
schedule_date=None,
|
schedule_date=None,
|
||||||
send_as=None,
|
send_as=None,
|
||||||
|
|
|
@ -15,7 +15,7 @@ from ..types import (
|
||||||
parse_message,
|
parse_message,
|
||||||
peer_id,
|
peer_id,
|
||||||
)
|
)
|
||||||
from ..types.buttons.reply_markup import ReplyMarkupType
|
from ..types.buttons.keyboard import KeyboardType
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import Client
|
from .client import Client
|
||||||
|
@ -31,7 +31,7 @@ async def send_message(
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
reply_to: Optional[int] = None,
|
reply_to: Optional[int] = None,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
random_id = generate_random_id()
|
random_id = generate_random_id()
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ async def send_message(
|
||||||
),
|
),
|
||||||
message=message,
|
message=message,
|
||||||
random_id=random_id,
|
random_id=random_id,
|
||||||
reply_markup=buttons._build() if buttons is not None else None,
|
reply_markup=keyboard._raw if keyboard else None,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
schedule_date=None,
|
schedule_date=None,
|
||||||
send_as=None,
|
send_as=None,
|
||||||
|
@ -128,7 +128,7 @@ async def edit_message(
|
||||||
markdown: Optional[str] = None,
|
markdown: Optional[str] = None,
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
buttons: Optional[ReplyMarkupType] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
message, entities = parse_message(
|
message, entities = parse_message(
|
||||||
text=text, markdown=markdown, html=html, allow_empty=False
|
text=text, markdown=markdown, html=html, allow_empty=False
|
||||||
|
@ -141,7 +141,7 @@ async def edit_message(
|
||||||
id=message_id,
|
id=message_id,
|
||||||
message=message,
|
message=message,
|
||||||
media=None,
|
media=None,
|
||||||
reply_markup=buttons._build() if buttons is not None else None,
|
reply_markup=keyboard._raw if keyboard else None,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
schedule_date=None,
|
schedule_date=None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from ....tl import abcs, types
|
||||||
from .button import Button
|
from .button import Button
|
||||||
from .callback import Callback
|
from .callback import Callback
|
||||||
from .inline_button import InlineButton
|
from .inline_button import InlineButton
|
||||||
from .reply_markup import ReplyInlineMarkup, ReplyKeyboardMarkup
|
from .keyboard import InlineKeyboard, Keyboard
|
||||||
from .request_geo_location import RequestGeoLocation
|
from .request_geo_location import RequestGeoLocation
|
||||||
from .request_phone import RequestPhone
|
from .request_phone import RequestPhone
|
||||||
from .request_poll import RequestPoll
|
from .request_poll import RequestPoll
|
||||||
|
@ -80,8 +80,8 @@ __all__ = [
|
||||||
"Button",
|
"Button",
|
||||||
"Callback",
|
"Callback",
|
||||||
"InlineButton",
|
"InlineButton",
|
||||||
"ReplyInlineMarkup",
|
"InlineKeyboard",
|
||||||
"ReplyKeyboardMarkup",
|
"Keyboard",
|
||||||
"RequestGeoLocation",
|
"RequestGeoLocation",
|
||||||
"RequestPhone",
|
"RequestPhone",
|
||||||
"RequestPoll",
|
"RequestPoll",
|
||||||
|
|
53
client/src/telethon/_impl/client/types/buttons/keyboard.py
Normal file
53
client/src/telethon/_impl/client/types/buttons/keyboard.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
from typing import Optional, TypeAlias
|
||||||
|
|
||||||
|
from ....tl import abcs, types
|
||||||
|
from .button import Button
|
||||||
|
|
||||||
|
|
||||||
|
def _build_keyboard_rows(
|
||||||
|
btns: list[Button] | list[list[Button]],
|
||||||
|
) -> list[abcs.KeyboardButtonRow]:
|
||||||
|
# list[button] -> list[list[button]]
|
||||||
|
# This does allow for "invalid" inputs (mixing lists and non-lists), but that's acceptable.
|
||||||
|
buttons_lists_iter = [
|
||||||
|
button if isinstance(button, list) else [button] for button in (btns or [])
|
||||||
|
]
|
||||||
|
# Remove empty rows (also making it easy to check if all-empty).
|
||||||
|
buttons_lists = [bs for bs in buttons_lists_iter if bs]
|
||||||
|
|
||||||
|
return [
|
||||||
|
types.KeyboardButtonRow(buttons=[btn._raw for btn in btns])
|
||||||
|
for btns in buttons_lists
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Keyboard:
|
||||||
|
__slots__ = ("_raw",)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
buttons: list[Button] | list[list[Button]],
|
||||||
|
resize: bool,
|
||||||
|
single_use: bool,
|
||||||
|
selective: bool,
|
||||||
|
persistent: bool,
|
||||||
|
placeholder: Optional[str],
|
||||||
|
) -> None:
|
||||||
|
self._raw = types.ReplyKeyboardMarkup(
|
||||||
|
resize=resize,
|
||||||
|
single_use=single_use,
|
||||||
|
selective=selective,
|
||||||
|
persistent=persistent,
|
||||||
|
rows=_build_keyboard_rows(buttons),
|
||||||
|
placeholder=placeholder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InlineKeyboard:
|
||||||
|
__slots__ = ("_raw",)
|
||||||
|
|
||||||
|
def __init__(self, buttons: list[Button] | list[list[Button]]) -> None:
|
||||||
|
self._raw = types.ReplyInlineMarkup(rows=_build_keyboard_rows(buttons))
|
||||||
|
|
||||||
|
|
||||||
|
KeyboardType: TypeAlias = Keyboard | InlineKeyboard
|
|
@ -1,71 +0,0 @@
|
||||||
from typing import Optional, TypeAlias
|
|
||||||
|
|
||||||
from ....tl import abcs, types
|
|
||||||
from .button import Button
|
|
||||||
|
|
||||||
|
|
||||||
def build_keyboard_rows(
|
|
||||||
btns: list[Button] | list[list[Button]],
|
|
||||||
) -> list[abcs.KeyboardButtonRow]:
|
|
||||||
# list[button] -> list[list[button]]
|
|
||||||
# This does allow for "invalid" inputs (mixing lists and non-lists), but that's acceptable.
|
|
||||||
buttons_lists_iter = [
|
|
||||||
button if isinstance(button, list) else [button] for button in (btns or [])
|
|
||||||
]
|
|
||||||
# Remove empty rows (also making it easy to check if all-empty).
|
|
||||||
buttons_lists = [bs for bs in buttons_lists_iter if bs]
|
|
||||||
|
|
||||||
return [
|
|
||||||
types.KeyboardButtonRow(buttons=[btn._raw for btn in btns])
|
|
||||||
for btns in buttons_lists
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ReplyKeyboardMarkup:
|
|
||||||
__slots__ = (
|
|
||||||
"_btns",
|
|
||||||
"resize",
|
|
||||||
"single_use",
|
|
||||||
"selective",
|
|
||||||
"persistent",
|
|
||||||
"placeholder",
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
btns: list[Button] | list[list[Button]],
|
|
||||||
resize: bool,
|
|
||||||
single_use: bool,
|
|
||||||
selective: bool,
|
|
||||||
persistent: bool,
|
|
||||||
placeholder: Optional[str],
|
|
||||||
) -> None:
|
|
||||||
self._btns = build_keyboard_rows(btns)
|
|
||||||
self.resize = resize
|
|
||||||
self.single_use = single_use
|
|
||||||
self.selective = selective
|
|
||||||
self.persistent = persistent
|
|
||||||
self.placeholder = placeholder
|
|
||||||
|
|
||||||
def _build(self) -> abcs.ReplyMarkup:
|
|
||||||
return types.ReplyKeyboardMarkup(
|
|
||||||
resize=self.resize,
|
|
||||||
single_use=self.single_use,
|
|
||||||
selective=self.selective,
|
|
||||||
persistent=self.persistent,
|
|
||||||
rows=self._btns,
|
|
||||||
placeholder=self.placeholder,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ReplyInlineMarkup:
|
|
||||||
__slots__ = ("_btns",)
|
|
||||||
|
|
||||||
def __init__(self, btns: list[Button] | list[list[Button]]) -> None:
|
|
||||||
self._btns = build_keyboard_rows(btns)
|
|
||||||
|
|
||||||
def _build(self) -> abcs.ReplyMarkup:
|
|
||||||
return types.ReplyInlineMarkup(rows=self._btns)
|
|
||||||
|
|
||||||
|
|
||||||
ReplyMarkupType: TypeAlias = ReplyKeyboardMarkup | ReplyInlineMarkup
|
|
|
@ -13,6 +13,7 @@ from ..parsers import (
|
||||||
parse_markdown_message,
|
parse_markdown_message,
|
||||||
)
|
)
|
||||||
from .buttons import Button, as_concrete_row, create_button
|
from .buttons import Button, as_concrete_row, create_button
|
||||||
|
from .buttons.keyboard import KeyboardType
|
||||||
from .file import File
|
from .file import File
|
||||||
from .meta import NoPublicConstructor
|
from .meta import NoPublicConstructor
|
||||||
from .peer import Peer, expand_peer, peer_id
|
from .peer import Peer, expand_peer, peer_id
|
||||||
|
@ -333,7 +334,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
markdown: Optional[str] = None,
|
markdown: Optional[str] = None,
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
buttons: Optional[list[Button] | list[list[Button]]] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Alias for :meth:`telethon.Client.send_message`.
|
Alias for :meth:`telethon.Client.send_message`.
|
||||||
|
@ -342,7 +343,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
:param markdown: See :ref:`formatting`.
|
:param markdown: See :ref:`formatting`.
|
||||||
:param html: See :ref:`formatting`.
|
:param html: See :ref:`formatting`.
|
||||||
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
||||||
:param buttons: See :meth:`~telethon.Client.send_message`.
|
:param keyboard: See :meth:`~telethon.Client.send_message`.
|
||||||
"""
|
"""
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
self.chat,
|
self.chat,
|
||||||
|
@ -350,7 +351,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
markdown=markdown,
|
markdown=markdown,
|
||||||
html=html,
|
html=html,
|
||||||
link_preview=link_preview,
|
link_preview=link_preview,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def reply(
|
async def reply(
|
||||||
|
@ -360,7 +361,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
markdown: Optional[str] = None,
|
markdown: Optional[str] = None,
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
buttons: Optional[list[Button] | list[list[Button]]] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Alias for :meth:`telethon.Client.send_message` with the ``reply_to`` parameter set to this message.
|
Alias for :meth:`telethon.Client.send_message` with the ``reply_to`` parameter set to this message.
|
||||||
|
@ -369,7 +370,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
:param markdown: See :ref:`formatting`.
|
:param markdown: See :ref:`formatting`.
|
||||||
:param html: See :ref:`formatting`.
|
:param html: See :ref:`formatting`.
|
||||||
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
||||||
:param buttons: See :meth:`~telethon.Client.send_message`.
|
:param keyboard: See :meth:`~telethon.Client.send_message`.
|
||||||
"""
|
"""
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
self.chat,
|
self.chat,
|
||||||
|
@ -378,7 +379,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
html=html,
|
html=html,
|
||||||
link_preview=link_preview,
|
link_preview=link_preview,
|
||||||
reply_to=self.id,
|
reply_to=self.id,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def delete(self, *, revoke: bool = True) -> None:
|
async def delete(self, *, revoke: bool = True) -> None:
|
||||||
|
@ -395,7 +396,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
markdown: Optional[str] = None,
|
markdown: Optional[str] = None,
|
||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
link_preview: bool = False,
|
link_preview: bool = False,
|
||||||
buttons: Optional[list[Button] | list[list[Button]]] = None,
|
keyboard: Optional[KeyboardType] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
"""
|
"""
|
||||||
Alias for :meth:`telethon.Client.edit_message`.
|
Alias for :meth:`telethon.Client.edit_message`.
|
||||||
|
@ -404,7 +405,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
:param markdown: See :ref:`formatting`.
|
:param markdown: See :ref:`formatting`.
|
||||||
:param html: See :ref:`formatting`.
|
:param html: See :ref:`formatting`.
|
||||||
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
:param link_preview: See :meth:`~telethon.Client.send_message`.
|
||||||
:param buttons: See :meth:`~telethon.Client.send_message`.
|
:param keyboard: See :meth:`~telethon.Client.send_message`.
|
||||||
"""
|
"""
|
||||||
return await self._client.edit_message(
|
return await self._client.edit_message(
|
||||||
self.chat,
|
self.chat,
|
||||||
|
@ -413,7 +414,7 @@ class Message(metaclass=NoPublicConstructor):
|
||||||
markdown=markdown,
|
markdown=markdown,
|
||||||
html=html,
|
html=html,
|
||||||
link_preview=link_preview,
|
link_preview=link_preview,
|
||||||
buttons=buttons,
|
keyboard=keyboard,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def forward(self, target: Peer | PeerRef) -> Message:
|
async def forward(self, target: Peer | PeerRef) -> Message:
|
||||||
|
|
|
@ -25,8 +25,8 @@ from .._impl.client.types import (
|
||||||
from .._impl.client.types.buttons import (
|
from .._impl.client.types.buttons import (
|
||||||
Button,
|
Button,
|
||||||
InlineButton,
|
InlineButton,
|
||||||
ReplyInlineMarkup,
|
InlineKeyboard,
|
||||||
ReplyKeyboardMarkup,
|
Keyboard,
|
||||||
)
|
)
|
||||||
from .._impl.session import ChannelRef, GroupRef, PeerRef, UserRef
|
from .._impl.session import ChannelRef, GroupRef, PeerRef, UserRef
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ __all__ = [
|
||||||
"Draft",
|
"Draft",
|
||||||
"File",
|
"File",
|
||||||
"Group",
|
"Group",
|
||||||
|
"InlineKeyboard",
|
||||||
"InlineResult",
|
"InlineResult",
|
||||||
|
"Keyboard",
|
||||||
"LoginToken",
|
"LoginToken",
|
||||||
"Message",
|
"Message",
|
||||||
"Participant",
|
"Participant",
|
||||||
"PasswordToken",
|
"PasswordToken",
|
||||||
"ReplyInlineMarkup",
|
|
||||||
"ReplyKeyboardMarkup",
|
|
||||||
"RecentAction",
|
"RecentAction",
|
||||||
"User",
|
"User",
|
||||||
"Button",
|
"Button",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user