Compare commits

..

4 Commits

Author SHA1 Message Date
李寻欢
b49247bf89 🐛 Fix a bug. 2023-12-07 23:27:07 +08:00
李寻欢
8b7487b42b 🎨 优化写法 2023-12-07 23:00:57 +08:00
李寻欢
ac9f68c80d 🎨 打印 sql 语句 2023-12-07 23:00:16 +08:00
李寻欢
43ddd23258 🐛 Fix a bug. 2023-12-07 22:38:49 +08:00
6 changed files with 22 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"go-wechat/config"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
)
@@ -17,7 +18,13 @@ func InitMySQLClient() {
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式
DontSupportRenameColumn: true, // 用 `change` 重命名列
}
conn, err := gorm.Open(mysql.New(mysqlConfig))
// gorm 配置
gormConfig := gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
}
conn, err := gorm.Open(mysql.New(mysqlConfig), &gormConfig)
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {

View File

@@ -8,7 +8,7 @@ wechat:
callback: 10.0.0.51
# 转发到其他地址
forward:
- 10.0.0.247:4299
# - 10.0.0.247:4299
# 数据库
mysql:
@@ -44,8 +44,9 @@ ai:
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
# 资源配置
# map[k]v结构k 会变成全小写,所以这儿不能用大写字母
resource:
# 欢迎新成员表情包
welcomeNew:
welcome-new:
type: emotion
path: 58e4150be2bba8f7b71974b10391f9e9

View File

@@ -1,10 +1,11 @@
package config
var Conf Config
// Conf 配置
var Conf conf
// Config
// @description: 配置
type Config struct {
type conf struct {
Task task `json:"task" yaml:"task"` // 定时任务配置
MySQL mysql `json:"mysql" yaml:"mysql"` // MySQL 配置
Wechat wechat `json:"wechat" yaml:"wechat"` // 微信助手

View File

@@ -24,9 +24,8 @@ func Parse(remoteAddr net.Addr, msg []byte) {
return
}
// 提取出群成员信息
//groupUser := ""
//msgStr := m.Content
if strings.Contains(m.FromUser, "@") {
// Sys类型的消息正文不包含微信 Id所以不需要处理
if m.IsGroup() && m.Type != types.MsgTypeSys {
// 群消息,处理一下消息和发信人
groupUser := strings.Split(m.Content, "\n")[0]
groupUser = strings.ReplaceAll(groupUser, ":", "")

View File

@@ -6,7 +6,6 @@ import (
"go-wechat/entity"
"go-wechat/model"
"go-wechat/utils"
"log"
)
// handleNewUserJoin
@@ -15,20 +14,13 @@ import (
func handleNewUserJoin(m model.Message) {
// 判断是否开启迎新
var count int64
err := client.MySQL.Model(&entity.Friend{}).
Where("enable_welcome IS TRUE").
Where("wxid = ?", m.FromUser).
Count(&count).Error
if err != nil {
log.Printf("查询是否开启迎新失败: %s", err.Error())
return
}
client.MySQL.Model(&entity.Friend{}).Where("enable_welcome IS TRUE").Where("wxid = ?", m.FromUser).Count(&count)
if count < 1 {
return
}
// 读取欢迎新成员配置
conf, ok := config.Conf.Resource["welcomeNew"]
conf, ok := config.Conf.Resource["welcome-new"]
if !ok {
// 未配置,跳过
return

View File

@@ -33,6 +33,10 @@ type systemMsgDataXml struct {
// @description: 消息主体
type sysMsg struct{}
func (m Message) IsGroup() bool {
return strings.HasSuffix(m.FromUser, "@chatroom")
}
// IsPat
// @description: 是否是拍一拍消息
// @receiver m