diff --git a/main.py b/main.py index 3f0bca9..41445a5 100644 --- a/main.py +++ b/main.py @@ -20,5 +20,5 @@ if __name__ == "__main__": # Start bot bot = NwXrayBot(config.bot_token.get_secret_value()) - bot.include_routers(HelloHandler(), MenuHandler()) + bot.include_routers(HelloHandler(), MenuHandler(), AdminHandler()) uvloop.run(bot.start(skip_updates=True)) diff --git a/nwxraybot/__init__.py b/nwxraybot/__init__.py index 667fdf5..4621279 100644 --- a/nwxraybot/__init__.py +++ b/nwxraybot/__init__.py @@ -1,2 +1,3 @@ from nwxraybot.bot import NwXrayBot from nwxraybot.config import Settings +from nwxraybot.utils import get_code, get_subscription_info diff --git a/nwxraybot/bot.py b/nwxraybot/bot.py index 8fcc426..b24ae5d 100644 --- a/nwxraybot/bot.py +++ b/nwxraybot/bot.py @@ -1,4 +1,5 @@ from aiogram import Bot, Dispatcher, Router +from aiogram.utils.callback_answer import CallbackAnswerMiddleware from nwxraybot.middlewares import UserMiddleware @@ -10,6 +11,7 @@ class NwXrayBot: self.bot = Bot(token=token) self.dp = Dispatcher() self.dp.message.middleware(UserMiddleware()) + self.dp.message.middleware(CallbackAnswerMiddleware()) def include_routers(self, *routers: Handler): for router in routers: diff --git a/nwxraybot/handlers/__init__.py b/nwxraybot/handlers/__init__.py index 9a127c1..0dde1e6 100644 --- a/nwxraybot/handlers/__init__.py +++ b/nwxraybot/handlers/__init__.py @@ -1,2 +1,3 @@ +from nwxraybot.handlers.admin import AdminHandler from nwxraybot.handlers.hello import HelloHandler from nwxraybot.handlers.menu import MenuHandler diff --git a/nwxraybot/handlers/admin.py b/nwxraybot/handlers/admin.py new file mode 100644 index 0000000..70ab2a7 --- /dev/null +++ b/nwxraybot/handlers/admin.py @@ -0,0 +1,37 @@ +import re +from datetime import datetime + +from aiogram.enums import ParseMode +from aiogram.filters import Command +from aiogram.types import Message + +from nwxraybot import get_code +from nwxraybot.meta import Handler +from nwxraybot.middlewares import AdminMiddleware +from nwxraybot.models import User + + +class AdminHandler(Handler): + def __init__(self) -> None: + super().__init__() + + self.router.message.middleware(AdminMiddleware()) + + @self.router.message(Command('adduser')) + async def add_user(message: Message): + mask = r"^(?P[a-zA-Z0-9]+)\s(?P[^\s]+)($|\s(?P[0-9]{2}\.[0-9]{2}\.[0-9]{4})\s(?P