diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index b2e1bb16..d8d1e42b 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 016de5f4..e8cc7d9c 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"