bot/main.py

37 lines
No EOL
1.1 KiB
Python

import asyncio
import logging
import signal
import sys
from asyncio import TaskGroup
import config
from adapters.tg import TelegramAdapter
async def main():
"""Main entry point"""
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
tasks = []
cfg = config.Config()
# Initialize and start Telegram adapter
if cfg.get_config_value('start_telegram_bot', True):
tg_adapter = TelegramAdapter()
tasks.append(tg_adapter.start())
if cfg.get_config_value('also_start_matrix_bot', False):
import adapters.matrix as matrix_bot
# Initialize and start Matrix bot if configured
tasks.append(matrix_bot.main())
if tasks:
try:
async with TaskGroup() as group:
for task in tasks:
group.create_task(task)
except asyncio.CancelledError:
logging.info("All tasks cancelled successfully")
else:
logging.error("No bot is configured to start. Please check your configuration.")
if __name__ == "__main__":
asyncio.run(main())