Skip to content

Commit 8fa6c24

Browse files
authored
Merge pull request #30 from Aidenable/dev
v1.3.7: URL value in @rt.keyboard.static
2 parents af03418 + 829e08c commit 8fa6c24

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

docs/source/plugins/conversations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Building multi-step dialogs in Telegram bots is often clunky.
55

66
Raito provides a lightweight way to wait for the **next user message** in a clean, linear style.
77

8+
.. warning::
9+
10+
Conversations DO NOT work with ``Dispatcher.events_isolation``,
11+
since ``SimpleEventIsolation`` operates with a ``asyncio.Lock`` on active handlers,
12+
and ``wait_for`` will never receive an update.
13+
14+
815
--------
916

1017
Example

examples/12-conversations/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33

44
from aiogram import Bot, Dispatcher
5+
from aiogram.fsm.storage.memory import DisabledEventIsolation
56

67
from raito import Raito
78

@@ -10,7 +11,7 @@
1011
DEBUG = False
1112

1213
bot = Bot(token=TOKEN)
13-
dispatcher = Dispatcher()
14+
dispatcher = Dispatcher(events_isolation=DisabledEventIsolation())
1415
raito = Raito(dispatcher, HANDLERS_DIR, developers=[], locales=["en"], production=not DEBUG)
1516
raito.init_logging()
1617

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "raito"
7-
version = "1.3.6"
7+
version = "1.3.7"
88
description = "REPL, hot-reload, keyboards, pagination, and internal dev tools — all in one. That's Raito."
99
authors = [{ name = "Aiden", email = "aidenthedev@gmail.com" }]
1010
license = "MIT"

raito/plugins/keyboards/static.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
P = ParamSpec("P")
2121
R = TypeVar("R")
2222

23-
ButtonData: TypeAlias = str | tuple[str] | tuple[str, str]
23+
ButtonData: TypeAlias = str | tuple[str] | tuple[str, str] | list[str]
2424
LayoutRow: TypeAlias = Sequence[ButtonData]
2525
LayoutReturn: TypeAlias = Sequence[ButtonData | LayoutRow]
2626

@@ -31,6 +31,12 @@
3131
BuilderFn: TypeAlias = Callable[P, KeyboardMarkupT]
3232

3333

34+
@overload
35+
def _get_button(data: ButtonData, *, inline: Literal[True]) -> InlineKeyboardButton: ...
36+
@overload
37+
def _get_button(data: ButtonData, *, inline: Literal[False]) -> KeyboardButton: ...
38+
@overload
39+
def _get_button(data: ButtonData, *, inline: bool) -> InlineKeyboardButton | KeyboardButton: ...
3440
def _get_button(data: ButtonData, *, inline: bool) -> InlineKeyboardButton | KeyboardButton:
3541
"""Convert button data to the appropriate button type.
3642
@@ -44,7 +50,24 @@ def _get_button(data: ButtonData, *, inline: bool) -> InlineKeyboardButton | Key
4450

4551
if isinstance(data, str) or len(data) != 2:
4652
raise ValueError("InlineKeyboardButton must be tuple of (text, callback_data)")
47-
return InlineKeyboardButton(text=data[0], callback_data=data[1])
53+
54+
name, value = data
55+
56+
url: str | None = None
57+
if value.startswith("t.me/"):
58+
url = "https://" + value
59+
elif value.startswith(
60+
(
61+
"http://",
62+
"https://",
63+
"tg://",
64+
)
65+
):
66+
url = value
67+
68+
if url:
69+
return InlineKeyboardButton(text=name, url=url)
70+
return InlineKeyboardButton(text=name, callback_data=value)
4871

4972

5073
def _is_button(row: LayoutRow) -> bool:

0 commit comments

Comments
 (0)