67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
#! /usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
import threading
|
||
from argparse import ArgumentParser
|
||
from configuration import Config
|
||
from constants import ChatType
|
||
from robot import Robot
|
||
|
||
from loguru import logger
|
||
|
||
# INFO 日志(包含 INFO、DEBUG,但不包含 WARNING、ERROR)
|
||
logger.add(
|
||
f"wx_info.log",
|
||
level="INFO",
|
||
filter=lambda record: record["level"].name in ["INFO", "DEBUG"],
|
||
rotation="10 MB",
|
||
retention="7 days",
|
||
encoding="utf-8"
|
||
)
|
||
|
||
# ERROR 日志(仅 ERROR 及以上)
|
||
logger.add(
|
||
f"wx_error.log",
|
||
level="ERROR",
|
||
rotation="10 MB",
|
||
retention="7 days",
|
||
encoding="utf-8"
|
||
)
|
||
|
||
|
||
def main(chat_type: int):
|
||
config = Config()
|
||
|
||
# 创建机器人实例
|
||
robot = Robot(config)
|
||
robot.LOG.info(f"WeChatRobot 正在启动...")
|
||
|
||
# 初始化并启动wechat_ipad客户端
|
||
if robot.init_wechat_ipad():
|
||
robot.LOG.info("wechat_ipad客户端启动成功")
|
||
else:
|
||
robot.LOG.error("wechat_ipad客户端启动失败")
|
||
|
||
# 启动Dashboard服务器
|
||
dashboard_server = None
|
||
try:
|
||
# 创建Dashboard服务器实例,共享robot对象
|
||
from admin.dashboard.server import DashboardServer
|
||
dashboard_server = DashboardServer(robot_instance=robot)
|
||
|
||
# 在单独的线程中启动Dashboard服务器
|
||
dashboard_thread = threading.Thread(target=dashboard_server.run, daemon=True)
|
||
dashboard_thread.start()
|
||
robot.LOG.info(f"Dashboard服务器已在 http://{dashboard_server.host}:{dashboard_server.port} 启动")
|
||
except Exception as e:
|
||
robot.LOG.error(f"Dashboard服务器启动失败: {e}")
|
||
|
||
# 让机器人一直跑
|
||
robot.keep_running_and_block_process()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
parser = ArgumentParser()
|
||
parser.add_argument('-c', type=int, default=0, help=f'选择模型参数序号: {ChatType.help_hint()}')
|
||
args = parser.parse_args()
|
||
main(args.c)
|