From 825860b6f97ef4c9d894afb7861455947465f901 Mon Sep 17 00:00:00 2001 From: taylor Date: Sun, 13 Oct 2024 20:09:19 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4ai?= =?UTF-8?q?=20model=20list=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maubot_llmplus/aibot.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index 84c3b96..1dfe7f7 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -29,18 +29,15 @@ class Config(BaseProxyConfig): class AiBotPlugin(Plugin): - name: str + default_username: str + user_id: str async def start(self) -> None: await super().start() # 加载并更新配置 self.config.load_and_update() - # 决定当前机器人的名称 - self.name = self.config['name'] or \ - await self.client.get_displayname(self.client.mxid) or \ - self.client.parse_user_id(self.client.mxid)[0] - self.log.debug(f"DEBUG gpt plugin started with bot name: {self.name}") - + self.default_username = await self.client.get_displayname(self.client.mxid) + self.user_id = self.client.parse_user_id(self.client.mxid)[0] """ 判断sender是否是allowed_users中的成员 @@ -72,6 +69,11 @@ class AiBotPlugin(Plugin): 5. 在thread中 """ + def get_bot_name(self, config: BaseProxyConfig): + return config['name'] or \ + self.default_username or \ + self.user_id + async def should_respond(self, event: MessageEvent) -> bool: # 发送者是机器人本身, 返回False if event.sender == self.client.mxid: @@ -92,7 +94,7 @@ class AiBotPlugin(Plugin): return False # 检查是否发送消息中有带上机器人的别名 - if re.search("(^|\\s)(@)?" + self.name + "([ :,.!?]|$)", event.content.body, re.IGNORECASE): + if re.search("(^|\\s)(@)?" + self.get_bot_name() + "([ :,.!?]|$)", event.content.body, re.IGNORECASE): return True # 当聊天室只有两个人并且其中一个是机器人时