This commit is contained in:
2023-10-28 16:31:26 +03:00
commit 58775f9935
6 changed files with 91 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
venv
**/__pycache__
.env

13
.vscode/settings.json vendored Normal file
View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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)

33
main.py Normal file
View File

@@ -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())

3
requirements.txt Normal file
View File

@@ -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