diff --git a/README.md b/README.md index 8754a96..4eafc84 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,14 @@ docker-compose -f docker-compose.yml up | | `from_list_exclude` | 消息转发来源排除列表,不转发此列表的用户和群 | 只在 `from_list` 为 `["%ALL"]` 时生效 | | | `discord_webhook_url` | 消息转发目标 Discord Webhook URL | | +### ⚙️ GPT Mode Person 配置 + +| 配置项 | 解释 | 备注 | +| --- | --- | --- | +| `gpt_mode_person_list` | 默认为 GPT 问答模式的用户列表 | 即带命令关键词的消息会正常触发相对应的命令,其余消息均判断为GPT命令 | +| `gpt_model` | 默认 GPT 问答的模型 | 可选值为 `gpt35`、`gpt4` | + + ## 日志文件 日志文件存放在项目根目录下的 `logs/` 文件夹中。 diff --git a/config.yaml.example b/config.yaml.example index 038ffd0..447f2f3 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -95,3 +95,8 @@ discord_message_forwarding_rule_list: - from_list: [ "%ALL" ] from_list_exclude: [ "" ] webhook_url: "your_discord_webhook_url" + + +# GPT Mode Person +gpt_mode_person_list: [ ] +gpt_mode_model: "gpt4" \ No newline at end of file diff --git a/config_cps.yaml.example b/config_cps.yaml.example index 6ad812f..0a24977 100644 --- a/config_cps.yaml.example +++ b/config_cps.yaml.example @@ -97,3 +97,8 @@ discord_message_forwarding_rule_list: - from_list: [ "%ALL" ] from_list_exclude: [ "" ] webhook_url: "your_discord_webhook_url" + + +# GPT Mode Person +gpt_mode_person_list: [ ] +gpt_mode_model: "gpt4" \ No newline at end of file diff --git a/wechatter/app/routers/wechat.py b/wechatter/app/routers/wechat.py index 03f72dd..d2b900c 100644 --- a/wechatter/app/routers/wechat.py +++ b/wechatter/app/routers/wechat.py @@ -117,7 +117,7 @@ def add_group(group: Group) -> None: _person = DbPerson.from_member_model(member) session.add(_person) session.commit() - logger.info(f"用户 {member.name} 已添加到数据库") + logger.debug(f"用户 {member.name} 已添加到数据库") else: # 更新用户信息 _person.name = member.name @@ -125,7 +125,7 @@ def add_group(group: Group) -> None: session.commit() session.commit() - logger.info(f"群组 {group.name} 已添加到数据库") + logger.debug(f"群组 {group.name} 已添加到数据库") else: # 更新群组信息 _group.update(group) @@ -142,7 +142,7 @@ def add_person(person: Person) -> None: _person = DbPerson.from_model(person) session.add(_person) session.commit() - logger.info(f"用户 {person.name} 已添加到数据库") + logger.debug(f"用户 {person.name} 已添加到数据库") else: # 更新用户信息 _person.update(person) @@ -157,5 +157,5 @@ def add_message(message: Message) -> int: _message = DbMessage.from_model(message) session.add(_message) session.commit() - logger.info(f"消息 {_message.id} 已添加到数据库") + logger.debug(f"消息 {_message.id} 已添加到数据库") return _message.id diff --git a/wechatter/message/message_handler.py b/wechatter/message/message_handler.py index 99117f5..719be0a 100644 --- a/wechatter/message/message_handler.py +++ b/wechatter/message/message_handler.py @@ -136,6 +136,25 @@ def handle_message(self, message_obj: Message): # 开始处理命令 _execute_command(cmd_dict, to, message_obj) else: + # 判断是否配置了默认GPT命令,若有则触发GPT命令 + if ( + message_obj.type != "file" + and not message_obj.is_group + and message_obj.sender_name in config.get("gpt_mode_person_list", []) + ): + cmd_dict["command"] = config.get("gpt_mode_model", "gpt35") + cmd_dict["handler"] = self.commands.get(cmd_dict["command"], {}).get( + "handler", None + ) + cmd_dict["desc"] = self.commands.get(cmd_dict["command"], {}).get( + "desc", "" + ) + cmd_dict["args"] = content + cmd_dict["param_count"] = self.commands.get( + cmd_dict["command"], {} + ).get("param_count", 0) + logger.info(f"默认触发GPT命令:{cmd_dict['command']}") + _execute_command(cmd_dict, to, message_obj) logger.debug("该消息不是命令类型") def __parse_command(self, content: str, is_mentioned: bool, is_group: bool) -> Dict: diff --git a/wechatter/models/wechat/message.py b/wechatter/models/wechat/message.py index 454ac9c..4fac380 100644 --- a/wechatter/models/wechat/message.py +++ b/wechatter/models/wechat/message.py @@ -304,8 +304,8 @@ def sticky_url(self) -> Optional[str]: # 使用 spilt,比正则效率高 url = self.content.split('cdnurl="')[1].split('" designerid')[0] # 将 URL 中的 & 替换为 & - print(url.replace("&", "&")) - return url.replace("&", "&") + # 带上别名参数,使得表情包为原图 + return f'{url.replace("&", "&")}?$alias=sticky.jpg' return None def __str__(self) -> str: