Skip to content

Commit

Permalink
fix: 修复修改cqhttp端口后仍检测失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Feb 19, 2024
1 parent 60ca538 commit 1d30f1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions addons/dashboard/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ def parse_default_config(self, dashboard_data: DashBoardData, config: dict):
)
qq_gocq_platform_group = DashBoardConfig(
config_type="group",
name="GO-CQHTTP 平台配置",
name="OneBot协议平台配置",
description="",
body=[
DashBoardConfig(
config_type="item",
val_type="bool",
name="启用 GO-CQHTTP 平台",
description="gocq 是一个基于 HTTP 协议的 CQHTTP 协议的实现。详见 github.com/Mrs4s/go-cqhttp",
name="启用",
description="支持cq-http、shamrock等(目前仅支持QQ平台)",
value=config['gocqbot']['enable'],
path="gocqbot.enable",
),
Expand All @@ -135,7 +135,7 @@ def parse_default_config(self, dashboard_data: DashBoardData, config: dict):
config_type="item",
val_type="int",
name="WebSocket 服务器端口",
description="",
description="目前仅支持正向 WebSocket",
value=config['gocq_websocket_port'],
path="gocq_websocket_port",
),
Expand Down
4 changes: 2 additions & 2 deletions addons/dashboard/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def _generate_outline(self):
"tag": ""
},
{
"title": "QQ_GOCQ",
"desc": "go-cqhttp",
"title": "OneBot协议",
"desc": "支持cq-http、shamrock等(目前仅支持QQ平台)",
"namespace": "internal_platform_qq_gocq",
"tag": ""
}
Expand Down
9 changes: 6 additions & 3 deletions cores/qqbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,16 @@ def run_qqchan_bot(cfg: dict, global_object: GlobalObject):
def run_gocq_bot(cfg: dict, _global_object: GlobalObject):
from model.platform.qq_gocq import QQGOCQ

logger.log("正在检查本地GO-CQHTTP连接...端口5700, 6700", tag="QQ")
noticed = False
host = cc.get("gocq_host", "127.0.0.1")
port = cc.get("gocq_websocket_port", 6700)
http_port = cc.get("gocq_http_port", 5700)
logger.log(f"正在检查连接...host: {host}, ws port: {port}, http port: {http_port}", tag="QQ")
while True:
if not gu.port_checker(5700, cc.get("gocq_host", "127.0.0.1")) or not gu.port_checker(6700, cc.get("gocq_host", "127.0.0.1")):
if not gu.port_checker(port=port, host=host) or gu.port_checker(port=http_port, host=host):
if not noticed:
noticed = True
logger.log("与GO-CQHTTP通信失败, 请检查GO-CQHTTP是否启动并正确配置。程序会每隔 5s 自动重试。", gu.LEVEL_CRITICAL, tag="QQ")
logger.log(f"连接到{host}:{port}(或{http_port})失败。程序会每隔 5s 自动重试。", gu.LEVEL_CRITICAL, tag="QQ")
time.sleep(5)
else:
logger.log("检查完毕,未发现问题。", tag="QQ")
Expand Down

0 comments on commit 1d30f1a

Please sign in to comment.