Skip to content

Commit

Permalink
feat: 默认GPT模式
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassius0924 committed Mar 20, 2024
1 parent 82b1920 commit c31b866
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/` 文件夹中。
Expand Down
5 changes: 5 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 5 additions & 0 deletions config_cps.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions wechatter/app/routers/wechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ 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
_person.alias = member.alias
session.commit()

session.commit()
logger.info(f"群组 {group.name} 已添加到数据库")
logger.debug(f"群组 {group.name} 已添加到数据库")
else:
# 更新群组信息
_group.update(group)
Expand All @@ -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)
Expand All @@ -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
19 changes: 19 additions & 0 deletions wechatter/message/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions wechatter/models/wechat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c31b866

Please sign in to comment.