Files
downloads-all-bot/bot/middleware.py
2026-01-02 17:48:48 +07:00

17 lines
647 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from aiogram import BaseMiddleware
from aiogram.types import Message, CallbackQuery
from config import ALLOWED_USERS
class PrivateMiddleware(BaseMiddleware):
async def __call__(self, handler, event, data):
user_id = event.from_user.id
if ALLOWED_USERS and user_id not in ALLOWED_USERS:
if isinstance(event, Message):
await event.answer("🚫 У тебя нет доступа к этому боту.")
elif isinstance(event, CallbackQuery):
await event.answer("🚫 Нет доступа", show_alert=True)
return
return await handler(event, data)