From 30a48fea6ef853f9c3d70289ccfe2587e1a73055 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Mon, 8 May 2023 20:17:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20QQ=E7=BE=A4=E7=9A=84=E5=85=8D@=E5=94=A4?= =?UTF-8?q?=E9=86=92=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA=E5=89=8D=E7=BC=80?= =?UTF-8?q?(nick=E6=8C=87=E4=BB=A4)=20#92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 18 ++++++++++++++---- model/command/command.py | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index b2e1bb160..d8d1e42bd 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -94,7 +94,7 @@ PLATFORM_GOCQ = 'gocq' gocq_app = None gocq_loop = None -nick_qq = "ai " +nick_qq = "ai" bing_cache_loop = None @@ -681,14 +681,24 @@ class gocqClient(): @gocq_app.receiver("GroupMessage") async def _(app: CQHTTP, source: GroupMessage): global nick_qq + # 将nick_qq转换为元组 + if nick_qq == None: + nick_qq = ("ai",) + if isinstance(nick_qq, str): + nick_qq = (nick_qq,) + if isinstance(nick_qq, list): + nick_qq = tuple(nick_qq) + if isinstance(source.message[0], Plain): if source.message[0].text.startswith(nick_qq): - source.message[0].text = source.message[0].text[len(nick_qq):].strip() + _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_id: - if source.message[1].text.startswith(nick_qq): - source.message[1].text = source.message[0].text[len(nick_qq):].strip() new_sub_thread(oper_msg, (source, True, None, PLATFORM_GOCQ)) else: return diff --git a/model/command/command.py b/model/command/command.py index 016de5f46..e8cc7d9c3 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -27,9 +27,12 @@ class Command: ''' def set_nick(self, message: str, platform: str): if platform == PLATFORM_GOCQ: - nick = message.split(" ")[1] + l = message.split(" ") + if len(l) == 1: + return True, "【设置机器人昵称】示例:\n支持多昵称\nnick 昵称1 昵称2 昵称3", "nick" + nick = l[1:] self.general_command_storer("nick_qq", nick) - return True, f"设置成功!现在你可以叫我{nick}来提问我啦~", "nick" + return True, f"设置成功!现在你可以叫我这些昵称来提问我啦~", "nick" elif platform == PLATFORM_QQCHAN: nick = message.split(" ")[2] return False, "QQ频道平台不支持为机器人设置昵称。", "nick"