From bcba51ac5d793e03e0699600c51d174df2d8f588 Mon Sep 17 00:00:00 2001 From: WowInceptionGood <143893762+WowInceptionGood@users.noreply.github.com> Date: Sun, 8 Mar 2026 21:12:57 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B9=20SQLite.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 ++++ .gitignore | 4 ++-- LICENSE | 1 + readme.md | 4 ++-- requirements.txt | 5 ++++- src/common/config.py | 6 ++++++ src/main.py | 30 +++++++++++++++++++----------- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index 48bae3b..ec2c8ec 100644 --- a/.env.example +++ b/.env.example @@ -7,12 +7,16 @@ tamtam_ws_port = "82" log_level = "debug" +db_type = "mysql" + db_host = "localhost" db_port = "3306" db_user = "root" db_password = "password" db_name = "openmax" +db_file = "" + certfile = "cert.pem" keyfile = "key.pem" diff --git a/.gitignore b/.gitignore index c4d5dd5..babc0d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ __pycache__ .env -cert.pem -key.pem \ No newline at end of file +*.pem +*.sqlite \ No newline at end of file diff --git a/LICENSE b/LICENSE index e666ede..b037cb6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright 2025-2026 Alexey Polyakov + 2026 Inception Time Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/readme.md b/readme.md index c9b5922..9a803d8 100644 --- a/readme.md +++ b/readme.md @@ -5,8 +5,9 @@ # Требования - Python 3.12+ (поддержка версий ниже не гарантирована) -- MariaDB или MySQL +- MariaDB, MySQL или SQLite - Уметь патчить клиент MAX или собирать Komet из исходного кода (естественно с заменой сервера) +- Сертификат и приватный ключ X.509 # Требования к клиенту @@ -20,7 +21,6 @@ ```bash pip install -r requirements.txt ``` - 3. Настройте сервер (пример в `.env.example`) 4. Импортируйте схему таблиц в свою базу данных из `tables.sql` 5. Запустите сервер diff --git a/requirements.txt b/requirements.txt index 775227c..8b73f40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,7 @@ aiomysql python-dotenv msgpack lz4 -websockets \ No newline at end of file +websockets +pydantic +aiohttp +aiosqlite \ No newline at end of file diff --git a/src/common/config.py b/src/common/config.py index f2558cd..dc4c7ed 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -20,6 +20,9 @@ class ServerConfig: ### Уровень отладки log_level = os.getenv("log_level") or "debug" + ### Тип базы данных + db_type = os.getenv("db_type") or "mysql" + ### MySQL db_host = os.getenv("db_host") or "127.0.0.1" db_port = int(os.getenv("db_port") or 3306) @@ -27,6 +30,9 @@ class ServerConfig: db_password = os.getenv("db_password") or "qwerty" db_name = os.getenv("db_name") or "openmax" + ### SQLite + db_file = os.getenv("db_file") or "openmax.db" + ### SSL certfile = os.getenv("certfile") or "cert.pem" keyfile = os.getenv("keyfile") or "key.pem" diff --git a/src/main.py b/src/main.py index 0cad9ce..ddb0b47 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,5 @@ # Импортирование библиотек -import aiomysql, ssl, logging, asyncio +import ssl, logging, asyncio from common.config import ServerConfig from oneme_tcp.controller import OnemeMobileController from telegrambot.controller import TelegramBotController @@ -10,16 +10,24 @@ server_config = ServerConfig() async def init_db(): """Инициализация базы данных""" - # Создаем пул - db = await aiomysql.create_pool( - host=server_config.db_host, - port=server_config.db_port, - user=server_config.db_user, - password=server_config.db_password, - db=server_config.db_name, - cursorclass=aiomysql.DictCursor, - autocommit=True - ) + + db = {} + + if server_config.db_type == "mysql": + import aiomysql + db = await aiomysql.create_pool( + host=server_config.db_host, + port=server_config.db_port, + user=server_config.db_user, + password=server_config.db_password, + db=server_config.db_name, + cursorclass=aiomysql.DictCursor, + autocommit=True + ) + elif server_config.db_type == "sqlite": + import aiosqlite + raw_db = await aiosqlite.connect(server_config.db_file) + db["acquire"] = raw_db # Возвращаем return db