diff --git a/README.MD b/README.MD index 205ab05..a38e4dc 100644 --- a/README.MD +++ b/README.MD @@ -77,7 +77,7 @@ Bubbles 是一个功能丰富的微信机器人框架,基于 [wcferry](https:/ - 处理各类微信消息(文本、图片、小程序、链接等) #### 🔧 实用工具 -- 自动接受好友请求并打招呼 +- 自动接受好友请求并打招呼(可通过 `auto_accept_friend_request` 配置开启) - 自动响应群聊和私聊消息 ## 🛠️ 安装指南 diff --git a/config.yaml.template b/config.yaml.template index ddafffd..40be244 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -148,3 +148,5 @@ perplexity: # -----perplexity配置这行不填----- ai_router: # -----AI路由器配置----- enable: true # 是否启用AI路由功能 allowed_groups: [] # 允许使用AI路由的群聊ID列表,例如:["123456789@chatroom", "123456789@chatroom"] + +auto_accept_friend_request: false # 是否自动通过好友申请,默认关闭 diff --git a/configuration.py b/configuration.py index ff8ccee..4af82b4 100644 --- a/configuration.py +++ b/configuration.py @@ -41,5 +41,6 @@ class Config(object): self.GEMINI_IMAGE = yconfig.get("gemini_image", {}) self.GEMINI = yconfig.get("gemini", {}) self.AI_ROUTER = yconfig.get("ai_router", {"enable": True, "allowed_groups": []}) + self.AUTO_ACCEPT_FRIEND_REQUEST = yconfig.get("auto_accept_friend_request", False) self.MAX_HISTORY = yconfig.get("MAX_HISTORY", 300) self.SEND_RATE_LIMIT = yconfig.get("send_rate_limit", 0) diff --git a/robot.py b/robot.py index 52adce5..cd95fd3 100644 --- a/robot.py +++ b/robot.py @@ -310,7 +310,11 @@ class Robot(Job): if not handled: # 7.1 好友请求自动处理 if msg.type == 37: # 好友请求 - self.autoAcceptFriendRequest(msg) + if getattr(self.config, "AUTO_ACCEPT_FRIEND_REQUEST", False): + self.LOG.info("检测到好友请求,自动通过开关已启用,准备同意。") + self.autoAcceptFriendRequest(msg) + else: + self.LOG.info("检测到好友请求,自动通过开关已关闭,保持待处理状态。") return # 7.2 系统消息处理 @@ -457,7 +461,10 @@ class Robot(Job): if nickName: # 添加了好友,更新好友列表 self.allContacts[msg.sender] = nickName[0] - self.sendTextMsg(f"Hi {nickName[0]},我是泡泡,我自动通过了你的好友请求。", msg.sender) + greeting = f"Hi {nickName[0]},我是泡泡,很高兴认识你。" + if getattr(self.config, "AUTO_ACCEPT_FRIEND_REQUEST", False): + greeting = f"Hi {nickName[0]},我是泡泡,我自动通过了你的好友请求。" + self.sendTextMsg(greeting, msg.sender) def newsReport(self) -> None: receivers = self.config.NEWS