🎨 优化迎新逻辑,引入资源概念

This commit is contained in:
李寻欢
2023-12-07 15:58:55 +08:00
parent 63d50b815c
commit 37bf8de132
11 changed files with 156 additions and 15 deletions

View File

@@ -42,6 +42,7 @@ func Parse(remoteAddr net.Addr, msg []byte) {
// 异步处理消息
go func() {
if m.IsNewUserJoin() {
log.Printf("%s -> 开始迎新 -> %s", m.FromUser, m.Content)
// 欢迎新成员
go handleNewUserJoin(m)
} else if m.IsAt() {

View File

@@ -2,9 +2,11 @@ package handler
import (
"go-wechat/client"
"go-wechat/config"
"go-wechat/entity"
"go-wechat/model"
"go-wechat/utils"
"log"
)
// handleNewUserJoin
@@ -13,13 +15,33 @@ import (
func handleNewUserJoin(m model.Message) {
// 判断是否开启迎新
var count int64
_ = client.MySQL.Model(&entity.Friend{}).Where("enable_welcome IS TRUE").Where("wxid = ?", m.FromUser).Count(&count).Error
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
}
if count < 1 {
return
}
// 发一张图乐呵乐呵
// 自己欢迎自己图片地址 D:\Share\emoticon\welcome-yourself.gif
utils.SendImage(m.FromUser, "D:\\Share\\emoticon\\welcome-yourself.gif", 0)
// 读取欢迎新成员配置
conf, ok := config.Conf.Resource["welcomeNew"]
if !ok {
// 未配置,跳过
return
}
switch conf.Type {
case "text":
// 文字类型
utils.SendMessage(m.FromUser, "", conf.Path, 0)
case "image":
// 图片类型
utils.SendImage(m.FromUser, conf.Path, 0)
case "emotion":
// 表情类型
utils.SendEmotion(m.FromUser, conf.Path, 0)
}
}