Some refactoring and started second bot

This commit is contained in:
2023-11-27 22:04:50 +03:00
parent b14eeb8342
commit a848733422
8 changed files with 108 additions and 63 deletions

View File

@@ -1,6 +1,6 @@
from typing import Any, List
from typing import List
from aiogram import Bot, F, Router, types
from aiogram import Bot, F, types
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.utils.media_group import MediaGroupBuilder
@@ -9,6 +9,7 @@ import neuroapi.types as neuroTypes
from handlers.filters.new_post import (ChangePosts, NewPostFilter,
NewSoloPostFilter)
from handlers.filters.reply_to_user import ReplyToUser
from handlers.handler import Handler
from handlers.middlewares.user import AdminMiddleware
from handlers.states.change_post import ChangePost
from neuroapi import neuroapi
@@ -23,13 +24,9 @@ def get_post_info(post: neuroTypes.Post, post_id: int) -> str:
return s
class Admin_commands:
bot: Bot
router: Router
class AdminCommands(Handler):
def __init__(self, bot: Bot) -> None:
self.bot = bot
self.router = Router()
super().__init__(bot)
self.router.message.middleware(AdminMiddleware())
@self.router.message(NewPostFilter())
@@ -210,9 +207,4 @@ class Admin_commands:
except Exception as e:
print(e)
def __call__(self, *args: Any, **kwds: Any) -> Router:
return self.router
def setup(bot: Bot) -> Router:
return Admin_commands(bot)()

16
handlers/handler.py Normal file
View File

@@ -0,0 +1,16 @@
from typing import Any
from aiogram import Bot, Router
class Handler:
bot: Bot
router: Router
def __init__(self, bot: Bot) -> None:
assert isinstance(bot, Bot)
self.bot = bot
self.router = Router()
def __call__(self) -> Router:
return self.router

View File

@@ -1,20 +1,17 @@
from typing import Any, List
from typing import List
from aiogram import Bot, F, Router, types
from aiogram import Bot, F, types
from handlers.handler import Handler
from neuroapi import neuroapi
from neuroapi.types import Admin as AdminType
class User_commands:
bot: Bot
router: Router
class UserCommands(Handler):
def __init__(self, bot: Bot) -> None:
self.bot = bot
self.router = Router()
super().__init__(bot)
@self.router.message(F.chat.type == 'private')
async def forward_post(message: types.Message):
admins: List[AdminType] = await neuroapi.admin.get()
@@ -27,9 +24,3 @@ class User_commands:
canReply = False
await message.reply('Ваше сообщение было отправлено администраторам'+('' if canReply else '\nНо они не смогут вам ответить из-за ваших настроек конфиденциальности.'))
def __call__(self, *args: Any, **kwds: Any) -> Router:
return self.router
def setup(bot: Bot) -> Router:
return User_commands(bot)()