dp = Dispatcher(vk) class MyMiddleware(BaseMiddleware): async def pre_process_event(self, event, data: dict): print("Called before handlers!") if event.type != "message_new": raise SkipHandler data["my_message"] = "hello, handler!" return data async def post_process_event(self): print("Called after handlers!") @dp.message_handler(text="hello!", data_check={"my_message": "hello, handler!"}) async def handle(message: types.Message, data: dict): print(data["my_message"]) # hello, handler! await message.reply("Hello!") async def run(): dp.run_polling(await get_group_id(vk)) if __name__ == "__main__": dp.setup_middleware(MyMiddleware()) # setup middleware task_manager.add_task(run) task_manager.run()
return True elif self.is_admin and status != "admin": return False @dp.message_handler(rules.Command("start")) async def handle(message: types.Message, data: dict): await message.reply("Hello!") @dp.message_handler(rules.Command("admin"), IsAdmin(True)) async def admin_panel(message: types.Message, data: dict): await message.reply("Is admin panel!") @dp.message_handler(rules.Command("get"), IsAdmin(False)) async def get_admin_rights(message: types.Message, data: dict): USERS[message.from_id] = "admin" await message.reply("Successfully!") async def run(): dp.run_polling() if __name__ == "__main__": dp.setup_middleware(RegistrationMiddleware()) # setup middleware task_manager.add_task(run) task_manager.run()