async def main():
dp.callback_query.outer_middleware.register(CheckerOnCallbackData())
dp.include_router(router)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(format='%(message)s :%(name)s -%(asctime)s'
,level=logging.DEBUG)
asyncio.run(main())
код Клавиатуры
keyboard_access =InlKB(inline_keyboard=[[InKButton(text = "✅ Проверить",callback_data="Check")]])
код миделвейров
async def CheckOnSubscriptions(from_user_id) -> Union[bool,list]:
non_sub = []
for channel in CHANNELS:
user_channel_status = await bot.get_chat_member(chat_id=channel,user_id=from_user_id)
if user_channel_status.status == "left":
non_sub.append(channel)
if len(non_sub) == 0:
return True
return non_sub
def CreateString(channel_non_sub:list):
stringi = "Вы ещё не подписались на каналы :"
for index,channel in enumerate(channel_non_sub):
stringi += f"\n {index + 1}. {channel}"
return stringi
async def CheckCheck(callback_data : types.CallbackQuery):
return callback_data == "Check"
class CheckerSubscriptionsOnChannel(BaseMiddleware):
async def __call__(
self,
handler: Callable[[types.TelegramObject, Dict[str, Any]], Awaitable[Any]],
event: types.TelegramObject,
data: Dict[str, Any]
) -> Any:
result = await CheckOnSubscriptions(event.from_user.id)
ic('adsad')
if result == True:
return await handler(event,data)
await bot.send_message(text=CreateString(result),reply_markup=keyboard_access,chat_id=event.from_user.id)
class CheckerOnCallbackData(BaseMiddleware):
async def __call__(
self,
handler: Callable[[types.TelegramObject, Dict[str, Any]], Awaitable[Any]],
event: types.TelegramObject,
data: Dict[str, Any]
) -> Any:
print("Hello World")
return await handler(event,data)
Hello World не выводится, миделвейр который написал я не работает. Как сделать так, чтобы он работал?