forked from LlmKira/Openaibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (48 loc) · 1.72 KB
/
main.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
# -*- coding: utf-8 -*-
# @Time : 9/22/22 10:07 PM
# @FileName: main.py
# @Software: PyCharm
# @Github :sudoskys,ElvinStarry
from pathlib import Path
from utils.Base import ReadConfig
# 日志
from loguru import logger
import sys
import multiprocessing
import importlib
logger.remove()
handler_id = logger.add(sys.stderr, level="INFO")
# 日志机器
logger.add(sink='run.log',
format="{time} - {level} - {message}",
level="INFO",
rotation="500 MB",
enqueue=True)
# logger.info("新闻:api key 只能通过 机器人命令配置")
logger.debug("Debug Mode On")
logger.info("NEWS Channel:https://t.me/Openaibot_channel")
# logger.info("新闻:命令表有改动")
logger.info("新闻:请使用 `pip install -U llm-kira -i https://pypi.org/simple/` `pip uninstall openai-kira`")
config = ReadConfig().parseFile(str(Path.cwd()) + "/Config/app.toml")
def start():
# pool = multiprocessing.Pool(processes=len(ctrlConfig)) # 进程池
ctrlConfig = config.Controller
pLock = multiprocessing.Lock()
try:
for starter in ctrlConfig:
if not Path(f"App/{starter}.py").exists():
logger.warning(f"Controller {starter} Do Not Exist.")
continue
module = importlib.import_module('App.' + starter)
p = multiprocessing.Process(target=module.BotRunner(ctrlConfig.get(starter)).run, args=(pLock,))
p.start()
# threads.append(t)
# for t in threads:
# t.join() # 等待所有线程退出
# pool.close()
# pool.join()
except KeyboardInterrupt:
logger.info('Exiting.')
exit(0)
if __name__ == '__main__': # 兼容Windows multiprocessing
start()