mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2024-12-24 00:33:05 +03:00
Merged with chore/refactor-core
This commit is contained in:
parent
9d89aee578
commit
837613e072
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ __pycache__
|
|||||||
OCAB.db
|
OCAB.db
|
||||||
src/paths.json
|
src/paths.json
|
||||||
src/core/config.yaml
|
src/core/config.yaml
|
||||||
|
src/core/log/**/*
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
TELEGRAM:
|
|
||||||
TOKEN:
|
|
||||||
|
|
||||||
YANDEXGPT:
|
|
||||||
TOKEN:
|
|
||||||
CATALOGID:
|
|
||||||
PROMPT:
|
|
||||||
|
|
||||||
ROLES:
|
|
||||||
ADMIN: 0
|
|
||||||
MODERATOR: 1
|
|
||||||
USER: 2
|
|
||||||
BOT: 3
|
|
0
src/core/database/.gitkeep
Normal file
0
src/core/database/.gitkeep
Normal file
@ -1,24 +1,29 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
async def check_log_file():
|
|
||||||
# Проверка наличия файла для логов в формате log-dd-mm-yyyy.log
|
def setup_logger():
|
||||||
# Если файл существует, то pass
|
"""
|
||||||
# Если файл не существует, то создаём его. файл лежит в директории src.core.log
|
Настройка логирования
|
||||||
current_data = time.strftime("%d-%m-%Y")
|
"""
|
||||||
log_file = os.path.join(os.path.dirname(__file__), "log/", f"log-{current_data}.log")
|
current_date = time.strftime("%d-%m-%Y")
|
||||||
if not os.path.exists(log_file):
|
log_dir = os.path.join(os.path.dirname(__file__), "log")
|
||||||
with open(log_file, 'w') as file:
|
os.makedirs(log_dir, exist_ok=True)
|
||||||
file.write("Log file created\n")
|
log_file = os.path.join(log_dir, f"log-{current_date}.log")
|
||||||
file.close()
|
|
||||||
else:
|
logging.basicConfig(
|
||||||
pass
|
filename=log_file,
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s %(message)s",
|
||||||
|
datefmt="%H:%M:%S"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def log(message):
|
async def log(message):
|
||||||
await check_log_file()
|
"""
|
||||||
current_data = time.strftime("%d-%m-%Y")
|
Функция для логирования сообщений
|
||||||
log_file = os.path.join(os.path.dirname(__file__), "log/", f"log-{current_data}.log")
|
|
||||||
# print(log_file)
|
Она асинхронная, хотя таковой на самом деле не является.
|
||||||
with open(log_file, 'a') as file:
|
"""
|
||||||
file.write(f"{time.strftime('%H:%M:%S')} {message}\n")
|
logging.info(message)
|
||||||
file.close()
|
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
from routers import include_routers
|
from routers import include_routers
|
||||||
|
from src.core.logger import log, setup_logger
|
||||||
from src.modules.standard.config.config import get_telegram_token
|
from src.modules.standard.config.config import get_telegram_token
|
||||||
from src.modules.standard.database.db_api import connect_database, create_tables
|
from src.modules.standard.database.db_api import connect_database, create_tables
|
||||||
|
import asyncio
|
||||||
from asyncio import run
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
|
|
||||||
|
|
||||||
async def main(bot: Bot):
|
async def main():
|
||||||
|
bot = None
|
||||||
|
database = None
|
||||||
|
setup_logger()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
bot = Bot(token=get_telegram_token())
|
||||||
database, path = connect_database()
|
database, path = connect_database()
|
||||||
database.connect()
|
database.connect()
|
||||||
create_tables(database)
|
create_tables(database)
|
||||||
@ -15,12 +20,14 @@ async def main(bot: Bot):
|
|||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
await include_routers(dp)
|
await include_routers(dp)
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
except Exception as e:
|
||||||
|
log(e)
|
||||||
finally:
|
finally:
|
||||||
await bot.session.close()
|
if bot is not None:
|
||||||
database.close()
|
await bot.session.close()
|
||||||
|
if database is not None:
|
||||||
|
database.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bot = Bot(token=get_telegram_token())
|
asyncio.run(main())
|
||||||
run(main(bot))
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
from aiogram import Dispatcher, Router, F, Bot
|
from aiogram import Dispatcher
|
||||||
from aiogram.types import Message
|
|
||||||
|
|
||||||
from src.modules.standard.info.routers import router as info_router
|
from src.modules.standard.info.routers import router as info_router
|
||||||
from src.modules.standard.admin.routers import router as admin_router
|
from src.modules.standard.admin.routers import router as admin_router
|
||||||
from src.modules.standard.message_processing.message_api import router as process_message
|
from src.modules.standard.message_processing.message_api import router as process_message
|
||||||
from src.modules.standard.welcome.routers import router as welcome_router
|
|
||||||
|
|
||||||
|
|
||||||
async def include_routers(dp: Dispatcher):
|
async def include_routers(dp: Dispatcher):
|
||||||
|
Loading…
Reference in New Issue
Block a user