2024-07-08 00:38:01 +03:00
|
|
|
import asyncio
|
2024-07-09 23:57:48 +03:00
|
|
|
import traceback
|
2024-07-08 00:38:01 +03:00
|
|
|
|
|
|
|
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"),
|
|
|
|
]
|
2023-11-30 16:23:37 +03:00
|
|
|
|
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()
|
|
|
|
|
2023-11-30 16:23:37 +03:00
|
|
|
try:
|
2024-07-07 21:25:10 +03:00
|
|
|
bot = Bot(token=get_telegram_token())
|
2023-12-10 19:04:17 +03:00
|
|
|
|
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()
|
2023-11-30 16:23:37 +03:00
|
|
|
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()
|
2023-11-30 16:23:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-07-07 21:25:10 +03:00
|
|
|
asyncio.run(main())
|