From b8e40ba9871682739784d9aa9d50dcf52cdc8e92 Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 8 Apr 2025 13:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4@=E5=AF=B9=E8=AF=9D=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E6=89=80=E6=9C=89=E8=A7=A6=E5=8F=91=E9=83=BD?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=8A=A0=E5=85=A5=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot.py | 66 +++++++++++++------------------------------------------- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/robot.py b/robot.py index 89c157c..165c50d 100644 --- a/robot.py +++ b/robot.py @@ -164,60 +164,24 @@ class Robot(Job): def toChitchat(self, msg: WxMsg) -> bool: """闲聊,接入 ChatGPT """ - if not self.chat: # 没接 ChatGPT,固定回复 - rsp = "你@我干嘛?" - else: # 接了 ChatGPT,智能回复 - # 去除@的人和空格等字符 - q = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "") - - # 所有人员都可以要求他撤回刚刚的信息 - if msg.from_group() and q.startswith("/"): - # 进行权限判断 加入权限,防止tokens浪费 - if self.gbm.get_group_permission(msg.roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED: - return True - else: - try: - # 因为内容中存在空格指令,所以不能使用q - game_message = re.sub(r"@.*?[\u2005|\s]", "", msg.content) - self.LOG.info(f"msg.content:{msg.content}\n game_message: {game_message}") - resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=game_message, - player_name=self.allContacts.get(msg.sender, msg.sender)) - message = resp["message"] - player_id = resp["player_id"] - print(f"消息: {message}") - print(f"玩家ID: {player_id}") - self.send_text_msg(message, msg.roomid, msg.sender) - except Exception as e: - self.LOG.error(f"game_message_load error:{e}") - return True - if q == "#今日百度新闻": - self.news_baidu_report((msg.roomid if msg.from_group() else msg.sender)) - return True - elif q in ["nbc", "cnn", "abc", "fox", "bbc"]: - self.news_en_report(q, (msg.roomid if msg.from_group() else msg.sender)) - return True - else: - # 如果是群消息,并且群没开启AI,则不处理该动作 - if msg.from_group() and self.gbm.get_group_permission(msg.roomid, - Feature.AI_CAPABILITY) == PermissionStatus.DISABLED: - return True - else: - resp = self.gbm.get_enabled_features(msg.roomid) - self.message_util.send_text_msg(resp, (msg.roomid if msg.from_group() else msg.sender), msg.sender) - # if msg.type == 1: # 只处理类型为1的消息提供的问题,引用@不予以对话 - # rsp = self.chat.get_answer(q, (msg.roomid if msg.from_group() else msg.sender)) - # else: - return True - if rsp: - if msg.from_group(): - self.send_text_msg(rsp, msg.roomid, msg.sender) - else: - self.send_text_msg(rsp, msg.sender) + # 去除@的人和空格等字符 + q = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "") + if q == "#今日百度新闻": + self.news_baidu_report((msg.roomid if msg.from_group() else msg.sender)) + return True + elif q in ["nbc", "cnn", "abc", "fox", "bbc"]: + self.news_en_report(q, (msg.roomid if msg.from_group() else msg.sender)) return True else: - self.LOG.error(f"无法从 ChatGPT 获得答案") - return False + # 如果是群消息,并且群没开启AI,则不处理该动作 + if msg.from_group() and self.gbm.get_group_permission(msg.roomid, + Feature.AI_CAPABILITY) == PermissionStatus.ENABLED: + resp = self.gbm.get_enabled_features(msg.roomid) + self.message_util.send_text_msg(resp, (msg.roomid if msg.from_group() else msg.sender), msg.sender) + return True + else: + return True def processMsg(self, msg: WxMsg) -> None: """当接收到消息的时候,会调用本方法。如果不实现本方法,则打印原始消息。