feat: QQ群的免@唤醒支持多个前缀(nick指令) #92

This commit is contained in:
Soulter
2023-05-08 20:17:51 +08:00
parent cfd5fb1452
commit 30a48fea6e
2 changed files with 19 additions and 6 deletions
+14 -4
View File
@@ -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
+5 -2
View File
@@ -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"