From 5852f36557ce7f222a288d904c74b0c8117bf175 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 10 Sep 2023 09:03:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=20gocq=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E4=B8=8D=E5=9B=9E=E5=A4=8D=E7=BE=A4=E3=80=81=E7=A7=81=E8=81=8A?= =?UTF-8?q?=E3=80=81=E9=A2=91=E9=81=93=E6=B6=88=E6=81=AF=E3=80=82=20(?= =?UTF-8?q?=E5=9C=A8cmd=5Fconfig.json=E6=96=87=E4=BB=B6=E8=AE=BE=E7=BD=AEg?= =?UTF-8?q?ocq=5Freact=5Fxxx=E7=AD=89=E9=A1=B9)=EF=BC=9B=202.=20update?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E5=8D=87=E7=BA=A7=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=96=B0=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 65 +++++++++++++++++++++------------------- model/command/command.py | 16 +++++++--- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index f629e128..5602bfc6 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -103,7 +103,7 @@ qqchannel_bot: QQChan = None PLATFORM_QQCHAN = 'qqchan' qqchan_loop = None -# 新版配置文件 +# 配置 cc.init_attributes(["qq_forward_threshold"], 200) cc.init_attributes(["qq_welcome"], "欢迎加入本群!\n欢迎给https://github.com/Soulter/QQChannelChatGPT项目一个Star😊~\n输入help查看帮助~\n") cc.init_attributes(["bing_proxy"], "") @@ -115,6 +115,10 @@ cc.init_attributes(["rev_chatgpt_unverified_plugin_domains"], []) cc.init_attributes(["gocq_host"], "127.0.0.1") cc.init_attributes(["gocq_http_port"], 5700) cc.init_attributes(["gocq_websocket_port"], 6700) +cc.init_attributes(["gocq_react_group"], True) +cc.init_attributes(["gocq_react_guild"], True) +cc.init_attributes(["gocq_react_friend"], True) +cc.init_attributes(["gocq_react_group_increase"], True) # cc.init_attributes(["qq_forward_mode"], False) # QQ机器人 @@ -681,11 +685,16 @@ def oper_msg(message, if command == "nick": nick_qq = cc.get("nick_qq", nick_qq) + if command == "update latest r": + send_message(platform, message, command_result[1] + "\n\n即将自动重启。", msg_ref=msg_ref, session_id=session_id) + py = sys.executable + os.execl(py, py, *sys.argv) + if not command_result[0]: send_message(platform, message, f"指令调用错误: \n{str(command_result[1])}", msg_ref=msg_ref, session_id=session_id) return # 画图指令 - if isinstance(command_result[1], list) and len(command_result) == 3 and command_result[2] == 'draw': + if isinstance(command_result[1], list) and len(command_result) == 3 and command == 'draw': for i in command_result[1]: # i is a link # 保存到本地 @@ -753,42 +762,38 @@ class gocqClient(): @gocq_app.receiver("GroupMessage") async def _(app: CQHTTP, source: GroupMessage): # gu.log(str(source), gu.LEVEL_INFO, max_len=9999) - - if isinstance(source.message[0], Plain): - new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) - if isinstance(source.message[0], At): - if source.message[0].qq == source.self_id: + if cc.get("gocq_react_group", True): + if isinstance(source.message[0], Plain): new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) - else: - return + if isinstance(source.message[0], At): + if source.message[0].qq == source.self_id: + new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) + else: + return @gocq_app.receiver("FriendMessage") async def _(app: CQHTTP, source: FriendMessage): - if isinstance(source.message[0], Plain): - new_sub_thread(oper_msg, (source, False, None, PLATFORM_GOCQ)) - else: - return + if cc.get("gocq_react_friend", True): + if isinstance(source.message[0], Plain): + new_sub_thread(oper_msg, (source, False, None, PLATFORM_GOCQ)) + else: + return @gocq_app.receiver("GroupMemberIncrease") async def _(app: CQHTTP, source: GroupMemberIncrease): - global nick_qq, announcement - await app.sendGroupMessage(source.group_id, [ - Plain(text = announcement), - ]) + if cc.get("gocq_react_group_increase", True): + global nick_qq, announcement + await app.sendGroupMessage(source.group_id, [ + Plain(text = announcement), + ]) @gocq_app.receiver("GuildMessage") async def _(app: CQHTTP, source: GuildMessage): - - if isinstance(source.message[0], Plain): - # if source.message[0].text.startswith(nick_qq): - # _len = 0 - # for i in nick_qq: - # if source.message[0].text.startswith(i): - # _len = len(i) - # source.message[0].text = source.message[0].text[_len:].strip() - new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) - if isinstance(source.message[0], At): - if source.message[0].qq == source.self_tiny_id: + if cc.get("gocq_react_guild", True): + if isinstance(source.message[0], Plain): new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) - else: - return \ No newline at end of file + if isinstance(source.message[0], At): + if source.message[0].qq == source.self_tiny_id: + new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) + else: + return \ No newline at end of file diff --git a/model/command/command.py b/model/command/command.py index 229fb5bb..483e7de5 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -455,11 +455,19 @@ class Command: pash_tag = "QQChannelChatGPT"+os.sep repo.remotes.origin.pull() - if len(l) == 3 and l[2] == "r": - py = sys.executable - os.execl(py, py, *sys.argv) + try: + origin = repo.remotes.origin + origin.fetch() + commits = list(repo.iter_commits('master', max_count=1)) + commit_log = commits[0].message + except BaseException as e: + commit_log = "无法获取commit信息" - return True, "更新成功~是否重启?输入update r重启(重启指令不返回任何确认信息)。", "update" + tag = "update" + if len(l) == 3 and l[2] == "r": + tag = "update latest r" + + return True, f"更新成功。新版本内容: \n{commit_log}\nps:重启后生效。输入update r重启(重启指令不返回任何确认信息)。", tag except BaseException as e: return False, "更新失败: "+str(e), "update"