diff --git a/src/__init__.py b/src/__init__.py index bcc746e..fa7075c 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1 @@ -import service \ No newline at end of file +import src.service \ No newline at end of file diff --git a/src/core/main.py b/src/core/main.py index ed06471..a7e7422 100644 --- a/src/core/main.py +++ b/src/core/main.py @@ -1,18 +1,19 @@ -from src.modules.standard.config.config import get_config -from src.modules.standard.database.models.base import database -from src.modules.standard.database.api import connect_database +from src.core.routers import include_routers +from src.modules.standard.config.config import get_telegram_token +from src.modules.standard.database.api import connect_database, create_tables from asyncio import run from aiogram import Bot, Dispatcher -async def main(): +async def main(bot: Bot): try: - database = connect_database() - bot = Bot(token=get_config()["TELEGRAM"]["TOKEN"]) + database, path = connect_database() + database.connect() + create_tables(database) dp = Dispatcher() - + await include_routers(dp) await dp.start_polling(bot) finally: @@ -21,4 +22,5 @@ async def main(): if __name__ == "__main__": - run(main()) + bot = Bot(token=get_telegram_token()) + run(main(bot)) diff --git a/src/core/routers.py b/src/core/routers.py new file mode 100644 index 0000000..a0390b0 --- /dev/null +++ b/src/core/routers.py @@ -0,0 +1,11 @@ +from aiogram import Dispatcher + +from src.modules.standard.admin.routers import router as admin_router + + +async def include_routers(dp: Dispatcher): + """ + Подключение роутеров в бота + dp.include_router() + """ + dp.include_router(admin_router) \ No newline at end of file diff --git a/src/modules/standard/admin/__init__.py b/src/modules/standard/admin/__init__.py new file mode 100644 index 0000000..62a5d54 --- /dev/null +++ b/src/modules/standard/admin/__init__.py @@ -0,0 +1 @@ +from . import routers diff --git a/src/modules/standard/admin/handlers.py b/src/modules/standard/admin/handlers.py new file mode 100644 index 0000000..863f091 --- /dev/null +++ b/src/modules/standard/admin/handlers.py @@ -0,0 +1,10 @@ +from aiogram import Bot +from aiogram.types import Message + + +async def delete_message(message: Message, bot: Bot): + reply_message_id = message.reply_to_message.message_id + await bot.delete_message(message.chat.id, reply_message_id) + +async def delete_message_error_access(message: Message, bot: Bot): + await message.reply("Вы не админ/модератор") \ No newline at end of file diff --git a/src/modules/standard/admin/info.json b/src/modules/standard/admin/info.json new file mode 100644 index 0000000..bd45d98 --- /dev/null +++ b/src/modules/standard/admin/info.json @@ -0,0 +1,6 @@ +{ + "name": "Admin", + "description": "Модуль для работы с админкой", + "author": "OCAB Team", + "version": "1.0" +} \ No newline at end of file diff --git a/src/modules/standard/admin/routers.py b/src/modules/standard/admin/routers.py new file mode 100644 index 0000000..45cb557 --- /dev/null +++ b/src/modules/standard/admin/routers.py @@ -0,0 +1,8 @@ +from aiogram import Router, F + +from src.modules.standard.admin.handlers import delete_message, delete_message_error_access +from src.modules.standard.filters.admin import ChatModerOrAdminFilter + +router = Router() +router.message.register(delete_message, ChatModerOrAdminFilter(), F.text == '/rm') +router.message.register(delete_message_error_access, F.text == '/rm') \ No newline at end of file diff --git a/src/modules/standard/config/config.py b/src/modules/standard/config/config.py index 49e37da..f53c62f 100644 --- a/src/modules/standard/config/config.py +++ b/src/modules/standard/config/config.py @@ -12,14 +12,18 @@ def get_config(is_test: bool = False) -> dict: with open(path, 'r') as file: return yaml.full_load(file) +config = get_config() + +def get_telegram_token() -> str: + return config["TELEGRAM"]["TOKEN"] def get_yandexgpt_token() -> str: - return get_config()["YANDEX_GPT_TOKEN"] + return config["YANDEX_GPT_TOKEN"] def get_yandexgpt_catalog_id() -> str: - return get_config()["YANDEX_GPT_CATALOG_ID"] + return config["YANDEX_GPT_CATALOG_ID"] def get_yandexgpt_prompt() -> str: - return get_config()["YANDEX_GPT_PROMPT"] + return config["YANDEX_GPT_PROMPT"] diff --git a/src/modules/standard/database/api.py b/src/modules/standard/database/api.py index 2c0ff88..5663d6d 100644 --- a/src/modules/standard/database/api.py +++ b/src/modules/standard/database/api.py @@ -22,6 +22,8 @@ def connect_database(is_test: bool = False, module: str | None = None): Chats._meta.database = _database Messages._meta.database = _database Users._meta.database = _database + UserStats._meta.database = _database + ChatStats._meta.database = _database return _database, f"{db_path}/OCAB.db" diff --git a/src/modules/standard/filters/__init__.py b/src/modules/standard/filters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/standard/filters/admin.py b/src/modules/standard/filters/admin.py new file mode 100644 index 0000000..f0c1c14 --- /dev/null +++ b/src/modules/standard/filters/admin.py @@ -0,0 +1,11 @@ +from aiogram.filters import BaseFilter +from aiogram.types import Message + +from src.modules.standard.roles.api import Roles + +class ChatModerOrAdminFilter(BaseFilter): + async def __call__(self, message: Message) -> bool: + user_id = message.from_user.id + roles = Roles() + return await roles.check_admin_permission(user_id) or \ + await roles.check_moderator_permission(user_id) diff --git a/src/modules/standard/filters/info.json b/src/modules/standard/filters/info.json new file mode 100644 index 0000000..59f6d44 --- /dev/null +++ b/src/modules/standard/filters/info.json @@ -0,0 +1,6 @@ +{ + "name": "Filters", + "description": "Модуль с фильтрами", + "author": "OCAB Team", + "version": "1.0" +} \ No newline at end of file