0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2025-03-14 14:23:51 +03:00
ocab/src/ocab_core/main.py

50 lines
1.2 KiB
Python
Raw Normal View History

import asyncio
2024-07-09 23:57:48 +03:00
import traceback
from aiogram import Bot, Dispatcher
2024-07-10 11:28:42 +03:00
from ocab_core.logger import setup_logger
from ocab_core.modules_system import ModulesManager
from ocab_core.modules_system.loaders import FSLoader
from ocab_core.modules_system.loaders.unsafe_fs_loader import UnsafeFSLoader
from ocab_core.singleton import Singleton
from ocab_modules.standard.config.config import get_telegram_token
from service import paths
2024-07-09 23:57:48 +03:00
bot_modules = [
UnsafeFSLoader(f"{paths.modules_standard}/config"),
UnsafeFSLoader(f"{paths.modules_standard}/database"),
UnsafeFSLoader(f"{paths.modules_standard}/roles"),
FSLoader(f"{paths.modules_standard}/info"),
]
2024-02-05 15:51:50 +03:00
2024-07-07 21:25:10 +03:00
async def main():
bot = None
database = None
setup_logger()
2024-07-09 23:57:48 +03:00
app = Singleton()
try:
2024-07-07 21:25:10 +03:00
bot = Bot(token=get_telegram_token())
2024-07-09 23:57:48 +03:00
app.dp = Dispatcher()
app.modules_manager = ModulesManager()
for module_loader in bot_modules:
app.modules_manager.load(module_loader)
await app.dp.start_polling(bot)
except Exception:
traceback.print_exc()
finally:
2024-07-07 21:25:10 +03:00
if bot is not None:
await bot.session.close()
if database is not None:
database.close()
if __name__ == "__main__":
2024-07-07 21:25:10 +03:00
asyncio.run(main())