From a78984376f749a076a44fdb1fc64d6e211af9465 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:52:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=8Ego-cqhttp?= =?UTF-8?q?=E7=9A=84=E9=80=9A=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 59d7ef127..b2e1bb160 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -91,16 +91,29 @@ qqchan_loop = None # QQ机器人 gocq_bot = None PLATFORM_GOCQ = 'gocq' -gocq_app = CQHTTP( - host="127.0.0.1", - port=6700, - http_port=5700, -) +gocq_app = None + gocq_loop = None nick_qq = "ai " bing_cache_loop = None +def gocq_runner(): + global gocq_app + ok = False + while not ok: + try: + gocq_app = CQHTTP( + host="127.0.0.1", + port=6700, + http_port=5700, + ) + ok = True + except BaseException as e: + print("[System-err] 连接到go-cqhttp异常, 5秒后重试。"+str(e)) + +threading.Thread(target=gocq_runner, daemon=True).start() + def new_sub_thread(func, args=()): thread = threading.Thread(target=func, args=args, daemon=True)