45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import argparse
|
|
import asyncio
|
|
import json
|
|
|
|
from aiogram import Bot, Dispatcher
|
|
|
|
from ai_agent import create_ai_agent
|
|
|
|
import tg.tg_database as database
|
|
|
|
from . import handlers
|
|
from . import tasks
|
|
|
|
|
|
async def main() -> None:
|
|
parser = argparse.ArgumentParser(description='Telegram chat bot')
|
|
parser.add_argument('-c', '--config', type=str, required=True,
|
|
help='Path to the JSON configuration file')
|
|
args = parser.parse_args()
|
|
|
|
with open(args.config, 'r') as file:
|
|
config = json.load(file)
|
|
print('Конфигурация загружена.')
|
|
|
|
database.create_database(config['db_connection_string'])
|
|
|
|
create_ai_agent(config['openrouter_token'],
|
|
config['openrouter_model'],
|
|
config['openrouter_model_temp'],
|
|
database.DB)
|
|
|
|
bots: list[Bot] = []
|
|
for item in database.DB.get_bots():
|
|
bot = Bot(token=item['api_token'])
|
|
asyncio.create_task(tasks.startup_task(bot))
|
|
asyncio.create_task(tasks.daily_maintenance_task(bot))
|
|
bots.append(bot)
|
|
|
|
dp = Dispatcher()
|
|
dp.include_router(handlers.router)
|
|
await dp.start_polling(*bots)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|