refactor(telegram): msgspec schemas and parsing (#156)

This commit is contained in:
banteg
2026-01-16 19:21:26 +04:00
committed by GitHub
parent 190b2f6d6e
commit c85ab2e2a2
10 changed files with 505 additions and 412 deletions
+31 -9
View File
@@ -9,7 +9,7 @@ from rich.text import Text
from takopi.config import ConfigError
from takopi.telegram import onboarding
from takopi.telegram.api_models import Update, User
from takopi.telegram.api_models import Chat, Message, Update, User
from takopi.telegram.client import TelegramRetryAfter
@@ -311,35 +311,57 @@ async def test_get_bot_info_gives_up(monkeypatch) -> None:
@pytest.mark.anyio
async def test_wait_for_chat_filters_updates(monkeypatch) -> None:
updates = [
[Update(update_id=1, message={"from": {"is_bot": True}, "chat": {"id": 1}})],
[
Update(
update_id=1,
message=Message(
message_id=1,
from_=User(id=1, is_bot=True),
chat=Chat(id=1, type="private"),
),
)
],
None,
[],
[Update(update_id=2, message=None)],
[
Update(
update_id=3,
message={"from": {"is_bot": True}, "chat": {"id": 2}},
message=Message(
message_id=3,
from_=User(id=2, is_bot=True),
chat=Chat(id=2, type="private"),
),
)
],
[
Update(
update_id=4,
message={"from": {"is_bot": False}, "chat": "nope"},
message=Message(
message_id=4,
from_=User(id=3, is_bot=True),
chat=Chat(id=3, type="private"),
),
)
],
[
Update(
update_id=5,
message={"from": {"is_bot": False}, "chat": {"id": "bad"}},
message=Message(
message_id=5,
from_=User(id=4, is_bot=True),
chat=Chat(id=4, type="private"),
),
)
],
[
Update(
update_id=6,
message={
"from": {"is_bot": False},
"chat": {"id": 7, "username": "bob", "type": "private"},
},
message=Message(
message_id=6,
from_=User(id=5, is_bot=False),
chat=Chat(id=7, username="bob", type="private"),
),
)
],
]