forked from lss233/chatgpt-mirai-qq-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
62 lines (49 loc) · 1.9 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import creart
sys.path.append(os.getcwd())
from asyncio import AbstractEventLoop
import asyncio
from utils.exithooks import hook
from loguru import logger
from constants import config, botManager
from utils.edge_tts import load_edge_tts_voices
loop = creart.create(AbstractEventLoop)
loop.run_until_complete(botManager.login())
bots = []
# 将log输出到stdout
logger.configure(handlers=[{"sink": sys.stdout}])
if config.mirai:
logger.info("检测到 mirai 配置,将启动 mirai 模式……")
from platforms.ariadne_bot import start_task
bots.append(loop.create_task(start_task()))
if config.onebot:
logger.info("检测到 Onebot 配置,将启动 Onebot 模式……")
from platforms.onebot_bot import start_task
bots.append(loop.create_task(start_task()))
if config.telegram:
logger.info("检测到 telegram 配置,将启动 telegram bot 模式……")
from platforms.telegram_bot import start_task
bots.append(loop.create_task(start_task()))
if config.discord:
logger.info("检测到 discord 配置,将启动 discord bot 模式……")
from platforms.discord_bot import start_task
bots.append(loop.create_task(start_task()))
if config.http:
logger.info("检测到 http 配置,将启动 http service 模式……")
from platforms.http_service import start_task
bots.append(loop.create_task(start_task()))
if config.wecom:
logger.info("检测到 Wecom 配置,将启动 Wecom Bot 模式……")
from platforms.wecom_bot import start_task
bots.append(loop.create_task(start_task()))
try:
logger.info("[Edge TTS] 读取 Edge TTS 可用音色列表……")
loop.run_until_complete(load_edge_tts_voices())
logger.info("[Edge TTS] 读取成功!")
except Exception as e:
logger.exception(e)
logger.error("[Edge TTS] 读取失败!")
hook()
loop.run_until_complete(asyncio.gather(*bots))
loop.run_forever()