Compare commits

...

4 Commits

Author SHA1 Message Date
李寻欢
7a5b46858d 🎨 逻辑优化 2024-07-22 09:19:38 +08:00
李寻欢
349d0e6bc0 🎨 逻辑优化 2024-07-22 09:19:17 +08:00
李寻欢
6acc0db583 🎨 优化@所有人判断逻辑 2024-07-22 09:08:02 +08:00
李寻欢
3fbaf1a9ef 🔥 移除短链接生成代码,疑似会引起封号 2024-07-17 08:36:34 +08:00
5 changed files with 47 additions and 49 deletions

View File

@@ -4,7 +4,6 @@ package config
type system struct {
Domain string `json:"domain" yaml:"domain"` // 域名
AlApiToken string `json:"alApiToken" yaml:"alApiToken"` // AL API Token
UrlcApiToken string `json:"urlcApiToken" yaml:"urlcApiToken"` // urlc.cn API Token
NewFriendNotify newFriendNotify `json:"newFriendNotify" yaml:"newFriendNotify"` // 新好友通知
DefaultRule defaultRule `json:"defaultRule" yaml:"defaultRule"` // 默认规则
}

View File

@@ -160,7 +160,11 @@ func (m Message) IsAtAll() bool {
// 转换@用户列表为数组
atUserList := strings.Split(d.AtUserList, ",")
// 判断是否包含@所有人
return slice.Contain(atUserList, "notify@all")
if slice.Contain(atUserList, "notify@all") {
return true
}
// 数据格式变动,再检查一下字符串是否包含 @所有人 字样
return m.IsAt() && strings.Contains(m.Content, "@所有人")
}
// IsPrivateText

View File

@@ -42,6 +42,19 @@ func Sync() {
nowIds := []string{}
// 取出已存在的成员信息
var oldData []entity.Friend
err = tx.Find(&oldData).Error
if err != nil {
log.Printf("查询好友列表失败: %s", err.Error())
return
}
// 将历史数据整理成map
oldMap := make(map[string]bool)
for _, item := range oldData {
oldMap[item.Wxid] = item.IsOk
}
// 新增的成员,用于通知给指定的人
var newItmes = make(map[string]string)
@@ -57,12 +70,7 @@ func Sync() {
nowIds = append(nowIds, friend.Wxid)
// 判断是否存在,不存在的话就新增,存在就修改一下名字
var count int64
err = tx.Model(&entity.Friend{}).Where("wxid = ?", friend.Wxid).Count(&count).Error
if err != nil {
continue
}
if count == 0 {
if _, e := oldMap[friend.Wxid]; !e {
// 新增
err = tx.Create(&entity.Friend{
CustomAccount: friend.CustomAccount,
@@ -120,6 +128,33 @@ func Sync() {
log.Printf("修改好友失败: %s", err.Error())
continue
}
// 如果已存在但是是已退出的群,也通知一下
if !oldMap[friend.Wxid] {
newItmes[friend.Wxid] = friend.Nickname
// 通知一下,初始化完成
if conf, ok := config.Conf.Resource["introduce"]; ok {
// 发送一条新消息
switch conf.Type {
case "text":
// 文字类型
utils.SendMessage(friend.Wxid, "", conf.Path, 0)
case "image":
// 图片类型
utils.SendImage(friend.Wxid, conf.Path, 0)
case "emotion":
// 表情类型
utils.SendEmotion(friend.Wxid, conf.Path, 0)
}
}
// 发送配置网页
if config.Conf.System.Domain != "" {
title := "欢迎使用微信机器人"
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid
utils.SendPublicMsg(friend.Wxid, title, desc, url, 0)
}
}
}
// 群成员,同步一下成员信息

View File

@@ -75,10 +75,7 @@ func getTopData() (data []string) {
}
d.Channel = "百度"
newDatas = append(newDatas, d)
shortUrl := utils.GenShortUrl(d.Url)
if shortUrl != "" {
data = append(data, fmt.Sprintf("标题: %s\n热度: %s\n详情: %s", d.Title, d.Hot, shortUrl))
}
data = append(data, fmt.Sprintf("标题: %s\n热度: %s\n详情: %s", d.Title, d.Hot, d.Url))
}
// 保存新数据到数据库
if len(newDatas) > 0 {

View File

@@ -1,37 +0,0 @@
package utils
import (
"encoding/json"
"github.com/go-resty/resty/v2"
"go-wechat/config"
"go-wechat/model/dto"
"log"
)
// GenShortUrl
// @description: 生成短链接
// @param url
// @return shortUrl
func GenShortUrl(url string) (shortUrl string) {
// 组装参数
param := map[string]any{
"url": url,
}
pbs, _ := json.Marshal(param)
var respData dto.ShortUrlResponse
res := resty.New()
resp, err := res.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetAuthScheme("Token").
SetAuthToken(config.Conf.System.UrlcApiToken).
SetBody(string(pbs)).
Post("https://www.urlc.cn/api/url/add")
if err != nil {
log.Printf("短链接获取失败: %s", err.Error())
return
}
log.Printf("短链接获取结果: %s", resp.String())
_ = json.Unmarshal(resp.Body(), &respData)
return respData.Short
}