Skip to content

Commit

Permalink
bot admin callback filter
Browse files Browse the repository at this point in the history
  • Loading branch information
KruASe76 committed Dec 18, 2022
1 parent fcc0421 commit ef9ab51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
from aiogram.filters import Command, Text
from aiogram.types import Message, CallbackQuery

from handlers.filters import BotAdminFilter
from handlers.filters import BotAdminMessageFilter, BotAdminCallbackFilter
from misc.config import conf, save_config
from misc.constants import admin_inline_keyboard


router = Router()


@router.message(Command(commands=["god"]), BotAdminFilter())
@router.message(Command(commands=["god"]), BotAdminMessageFilter())
async def admin_panel_command(message: Message):
await message.answer("Здравствуй, отец\!", reply_markup=admin_inline_keyboard)
await message.answer("Здарова, отец\!", reply_markup=admin_inline_keyboard)


@router.callback_query(Text(text="santa_progress"))
@router.callback_query(Text(text="santa_progress"), BotAdminCallbackFilter())
async def shutdown_query(callback: CallbackQuery):
await callback.answer()
await callback.message.answer(
Expand All @@ -26,7 +26,7 @@ async def shutdown_query(callback: CallbackQuery):
))
)

@router.callback_query(Text(text="shutdown"))
@router.callback_query(Text(text="shutdown"), BotAdminCallbackFilter())
async def shutdown_query(callback: CallbackQuery):
save_config()

Expand Down
15 changes: 12 additions & 3 deletions handlers/filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from aiogram.filters import BaseFilter
from aiogram.types import Message
from aiogram.types import Message, CallbackQuery

from misc.constants import admin_id


class BotAdminFilter(BaseFilter):
class BotAdminMessageFilter(BaseFilter):
async def __call__(self, message: Message) -> bool:
return message.from_user.id == admin_id
if flag := (message.from_user.id != admin_id):
await message.reply("Ты не отец\! 🫵")
return not flag


class BotAdminCallbackFilter(BaseFilter):
async def __call__(self, callback: CallbackQuery):
if flag := (callback.from_user.id != admin_id):
await callback.answer("Ты не отец! 🫵")
return not flag

0 comments on commit ef9ab51

Please sign in to comment.