Compare commits

...

3 Commits

Author SHA1 Message Date
李寻欢
7e545cef95 🐛 Fix a bug. 2023-12-10 09:29:17 +08:00
李寻欢
3fbaf7aeb6 🎨 逻辑优化 2023-12-10 08:19:21 +08:00
李寻欢
3bc95e1317 🎨 逻辑优化 2023-12-10 08:14:09 +08:00
5 changed files with 18 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ wechat:
host: 10.0.0.73:19088
# 是否在启动的时候自动设置hook服务的回调
autoSetCallback: false
# 回调IP如果是Docker运行本参数必填如果Docker修改了映射格式为 ip:port
# 回调IP如果是Docker运行本参数必填(填auto表示自动不适用于 docker 环境)如果Docker修改了映射格式为 ip:port
callback: 10.0.0.51
# 转发到其他地址
forward:

View File

@@ -10,6 +10,7 @@ import (
"go-wechat/config"
"go-wechat/entity"
"go-wechat/model"
"go-wechat/service"
"go-wechat/types"
"go-wechat/utils"
"log"
@@ -54,6 +55,7 @@ func handleAtMessage(m model.Message) {
// 查询发信人前面几条文字信息,组装进来
var oldMessages []entity.Message
client.MySQL.Model(&entity.Message{}).
Where("msg_id != ?", m.MsgId).
Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)").
Where("from_user = ? AND group_user = ? AND display_full_content LIKE ?", m.FromUser, m.GroupUser, "%在群聊中@了你").
Or("to_user = ? AND group_user = ?", m.FromUser, m.GroupUser).
@@ -124,7 +126,7 @@ func handleAtMessage(m model.Message) {
replyMessage.GroupUser = m.GroupUser // 群成员
replyMessage.ToUser = m.FromUser // 收信人是发信人
replyMessage.Type = types.MsgTypeText
client.MySQL.Create(&replyMessage) // 保存入库
service.SaveMessage(replyMessage) // 保存消息
// 发送消息
utils.SendMessage(m.FromUser, m.GroupUser, "\n"+resp.Choices[0].Message.Content, 0)

View File

@@ -16,8 +16,8 @@ wechat:
host: wechat:19088
# 是否在启动的时候自动设置hook服务的回调
autoSetCallback: true
# 回调IP如果是Docker运行本参数必填如果Docker修改了映射格式为 ip:port如果使用项目提供的docker-compsoe.yaml文件启动可以不写
callback:
# 回调IP如果是Docker运行本参数必填如果Docker修改了映射格式为 ip:port如果使用项目提供的docker-compsoe.yaml文件启动可以填`auto`
callback: auto
# 数据库
mysql:

View File

@@ -4,12 +4,18 @@ import (
"go-wechat/client"
"go-wechat/entity"
"log"
"os"
"strconv"
)
// SaveMessage
// @description: 消息入库
// @param msg
func SaveMessage(msg entity.Message) {
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SAVE")); flag {
return
}
// 检查消息是否存在,存在就跳过
var count int64
err := client.MySQL.Model(&entity.Message{}).Where("msg_id = ?", msg.MsgId).Count(&count).Error

View File

@@ -29,9 +29,13 @@ func ClearCallback() {
// @param host
func SetCallback(userHost string) {
// 获取本机IP地址
host := net.ParseIP(netutil.GetInternalIp()).String()
host := userHost
if userHost == "auto" {
host = net.ParseIP(netutil.GetInternalIp()).String()
}
port := 19099
if userHost != "" {
if userHost != "" && userHost != "auto" {
uh := strings.Split(strings.TrimSpace(userHost), ":")
host = uh[0]
if len(uh) == 2 {