Добавлена проверка на подписки Webhook при start_polling

This commit is contained in:
Денис Семёнов 2025-07-28 01:12:55 +03:00
parent f497760f5b
commit 0bd59ddb4a

View File

@ -75,6 +75,7 @@ class Dispatcher:
self.bot: Optional[Bot] = None self.bot: Optional[Bot] = None
self.webhook_app: Optional[FastAPI] = None self.webhook_app: Optional[FastAPI] = None
self.on_started_func: Optional[Callable] = None self.on_started_func: Optional[Callable] = None
self.polling = False
self.message_created = Event(update_type=UpdateType.MESSAGE_CREATED, router=self) self.message_created = Event(update_type=UpdateType.MESSAGE_CREATED, router=self)
self.bot_added = Event(update_type=UpdateType.BOT_ADDED, router=self) self.bot_added = Event(update_type=UpdateType.BOT_ADDED, router=self)
@ -153,6 +154,13 @@ class Dispatcher:
self.bot = bot self.bot = bot
if self.polling and self.bot.auto_check_subscriptions:
response = await self.bot.get_subscriptions()
if response.subscriptions:
logger_subscriptions_text = ', '.join([s.url for s in response.subscriptions])
logger_dp.warning('БОТ ИГНОРИРУЕТ POLLING! Обнаружены установленные подписки: %s', logger_subscriptions_text)
await self.check_me() await self.check_me()
self.routers += [self] self.routers += [self]
@ -271,12 +279,14 @@ class Dispatcher:
:param bot: Экземпляр бота. :param bot: Экземпляр бота.
""" """
self.polling = True
await self.__ready(bot) await self.__ready(bot)
while True: if self.bot is None:
raise RuntimeError('Bot не инициализирован')
if self.bot is None: while self.polling:
raise RuntimeError('Bot не инициализирован')
try: try:
events: Dict = await self.bot.get_updates() events: Dict = await self.bot.get_updates()