feat(bot): доступ по QR-приглашениям, раздел «Участники», отзыв доступа
- AccessService: одноразовые приглашения (128 бит, в БД только sha256, TTL 24 ч), атомарный захват приглашения (условный UPDATE — из двух сканов одного QR проходит один), антиперебор (> 5 неудач в час — молчание), отзыв (черновик и FSM удаляются), повторное приглашение - ADMIN_IDS заводятся в БД при старте; дальше — только по приглашению - AccessMiddleware: участники из БД (+ last_seen раз в 5 мин), новичкам — только /start <токен> - «👥 Участники» для админов: список, QR (segno) + ссылка, отзыв с подтверждением - один ответ на неверный/истёкший/использованный токен — без подсказок Refs #25 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+11
-1
@@ -7,7 +7,7 @@ from typing import Any
|
||||
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.client.session.base import BaseSession
|
||||
from aiogram.methods import EditMessageText, SendMessage, TelegramMethod
|
||||
from aiogram.methods import EditMessageText, GetMe, SendMessage, SendPhoto, TelegramMethod
|
||||
from aiogram.methods.base import TelegramType
|
||||
from aiogram.types import Chat, Message, Update, User
|
||||
|
||||
@@ -27,6 +27,16 @@ class FakeSession(BaseSession):
|
||||
timeout: int | None = None, # noqa: ASYNC109 - signature fixed by aiogram BaseSession
|
||||
) -> TelegramType:
|
||||
self.requests.append(method)
|
||||
if isinstance(method, GetMe):
|
||||
return User(id=42, is_bot=True, first_name="tgit", username="tgit_test_bot") # type: ignore[return-value]
|
||||
if isinstance(method, SendPhoto):
|
||||
chat = method.chat_id if isinstance(method.chat_id, int) else 0
|
||||
return Message( # type: ignore[return-value]
|
||||
message_id=next(self._ids),
|
||||
date=datetime.now(UTC),
|
||||
chat=Chat(id=chat, type="private"),
|
||||
caption=method.caption,
|
||||
)
|
||||
if isinstance(method, SendMessage | EditMessageText):
|
||||
chat_id = method.chat_id if isinstance(method.chat_id, int) else 0
|
||||
return Message( # type: ignore[return-value]
|
||||
|
||||
Reference in New Issue
Block a user