commit 58775f993562e129da58c836c4042328e12cabb5 Author: Sergey Elpashev Date: Sat Oct 28 16:31:26 2023 +0300 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e300722 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +**/__pycache__ +.env \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e8e8f1d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "editor.defaultFormatter": "ms-python.autopep8", + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/.ruby-lsp": true, + "**/venv": true + } +} \ No newline at end of file diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py new file mode 100644 index 0000000..45f2121 --- /dev/null +++ b/handlers/admin_commands.py @@ -0,0 +1,22 @@ +from typing import Any + +from aiogram import Bot, F, Router, types +from aiogram.filters import Command + +from handlers.middlewares.user import AdminMiddleware + + +class Admin_commands: + bot: Bot + router: Router + def __init__(self, bot: Bot) -> None: + self.bot = bot + self.router = Router() + self.router.message.middleware(AdminMiddleware()) + + @self.router.message(Command('info')) + async def info_command(message: types.Message): + await message.answer('Тест') + + def __call__(self, *args: Any, **kwds: Any) -> Router: + return self.router \ No newline at end of file diff --git a/handlers/middlewares/user.py b/handlers/middlewares/user.py new file mode 100644 index 0000000..4f46342 --- /dev/null +++ b/handlers/middlewares/user.py @@ -0,0 +1,17 @@ +from typing import Any, Awaitable, Callable, Dict + +from aiogram import BaseMiddleware +from aiogram.types import Message + +ADMIN_LIST = [248770879, 395543883] + +class AdminMiddleware(BaseMiddleware): + def __init__(self) -> None: + pass + + async def __call__(self, handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]], event: Message, data: Dict[str, Any]) -> Any: + if event.from_user.id in ADMIN_LIST: + await event.answer('Команда только для админов!') + return None + return await handler(event, data) + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..0bb0f7b --- /dev/null +++ b/main.py @@ -0,0 +1,33 @@ +import asyncio +import logging +import os +import sys + +import aioschedule as schedule +import dotenv +from aiogram import Bot, Dispatcher, F, types +from aiogram.filters import Command, CommandStart +from aiogram.fsm.context import FSMContext +from aiogram.fsm.state import State, StatesGroup +from aiogram.utils.keyboard import InlineKeyboardBuilder + +from handlers.admin_commands import Admin_commands + +dotenv.load_dotenv() + +token = os.getenv('TOKEN') + +bot = Bot(token) +dp = Dispatcher() + +@dp.message(CommandStart()) +async def start_message(message: types.Message): + await message.answer('Абоба') + +async def main() -> None: + dp.include_router(Admin_commands(bot)()) + await dp.start_polling(bot, skip_updates=True) + +if __name__ == '__main__': + logging.basicConfig(level=logging.INFO, stream=sys.stdout) + asyncio.run(main()) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b2da1b7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +aiogram==3.1.1 +aioschedule @ https://github.com/AleksHeller/python-aioschedule/archive/refs/heads/master.zip +python-dotenv==1.0.0