From af6cadc39138adeb0a4698f16be57856f62048d3 Mon Sep 17 00:00:00 2001 From: Ruslan Bel'kov Date: Sat, 28 Sep 2024 23:08:09 +0300 Subject: [PATCH] fix: use attribute instead of item getter; better admin filtering --- src/bot/routers/admin.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/bot/routers/admin.py b/src/bot/routers/admin.py index 998b126..1dd798f 100644 --- a/src/bot/routers/admin.py +++ b/src/bot/routers/admin.py @@ -22,29 +22,26 @@ async def __call__(self, event: TelegramObject, event_from_user: User) -> bool | if self._status is None: return {"status": user.status} - if user["status"] == self._status: + if user.status == self._status: return True return False -@router.message(Command("admin"), StatusFilter()) -async def enable_admin_mode(message: types.Message, bot: Bot, status: str): - if status == UserStatus.LORD: - text = "You are the Lord of the Music Room! You can use the following commands:" +@router.message(Command("admin"), StatusFilter(UserStatus.LORD)) +async def enable_admin_mode(message: types.Message, bot: Bot): + text = "You are the Lord of the Music Room! You can use the following commands:" - for command in admin_commands: - text += f"\n{command.command} - {command.description}" + for command in admin_commands: + text += f"\n{command.command} - {command.description}" - await message.answer(text) - await bot.set_my_commands( - bot_commands + admin_commands, - scope=BotCommandScopeChat(chat_id=message.from_user.id), - ) - else: - await bot.set_my_commands(bot_commands, scope=BotCommandScopeChat(chat_id=message.from_user.id)) + await message.answer(text) + await bot.set_my_commands( + bot_commands + admin_commands, + scope=BotCommandScopeChat(chat_id=message.from_user.id), + ) -@router.message(Command("export_users")) +@router.message(Command("export_users"), StatusFilter(UserStatus.LORD)) async def export_users(message: types.Message): response = await api_client.export_users(message.from_user.id) if response: @@ -52,4 +49,4 @@ async def export_users(message: types.Message): document = BufferedInputFile(bytes_, filename) await message.answer_document(document, caption="Here is the list of users.") else: - await message.answer("You don't have access to this command.") + await message.answer("Failed to export users.")