Skip to content

Commit

Permalink
fix: use attribute instead of item getter; better admin filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Sep 28, 2024
1 parent e3fe2da commit af6cadc
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/bot/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,31 @@ 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:
bytes_, filename = response
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.")

0 comments on commit af6cadc

Please sign in to comment.