Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9178613f1d | ||
|
|
7a5b46858d | ||
|
|
349d0e6bc0 | ||
|
|
791f0a550a | ||
|
|
6acc0db583 | ||
|
|
5fac1b56f7 | ||
|
|
3fbaf1a9ef | ||
|
|
0f092977ba | ||
|
|
b794df9b63 |
@@ -102,6 +102,7 @@ ai:
|
||||
models:
|
||||
- name: ChatGPT-4
|
||||
model: gpt-4
|
||||
canManager: false
|
||||
- name: 讯飞星火v3.1
|
||||
model: SparkDesk-v3.1
|
||||
- name: 讯飞星火v3.5
|
||||
@@ -116,8 +117,10 @@ ai:
|
||||
model: StepChat
|
||||
- name: 豆包Lite-4k
|
||||
model: Doubao-lite-4k
|
||||
canManager: true
|
||||
- name: 豆包Pro-4k
|
||||
model: Doubao-pro-4k
|
||||
canManager: true
|
||||
|
||||
# 资源配置
|
||||
# map[k]v结构,k 会变成全小写,所以这儿不能用大写字母
|
||||
|
||||
@@ -17,4 +17,5 @@ type ai struct {
|
||||
type aiModel struct {
|
||||
Name string `json:"name" yaml:"name"` // 模型名称
|
||||
Model string `json:"dto" yaml:"dto"` // 模型代码
|
||||
CanManager bool `json:"canManager" yaml:"canManager"` // 是否可以在manager页面中选择
|
||||
}
|
||||
|
||||
@@ -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"` // 默认规则
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 群成员,同步一下成员信息
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -53,7 +53,7 @@
|
||||
<select class="block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-green-600 sm:text-sm sm:leading-6" onchange="aiModelChange(event, {{.info.Wxid}})">
|
||||
{{$useModel := .info.AiModel}}
|
||||
{{ range $.aiModels }}
|
||||
<option value="{{.Model}}" {{ if eq $useModel .Model}}selected{{ end }}>
|
||||
<option value="{{.Model}}" {{ if eq $useModel .Model}}selected{{ end }} {{ if not .CanManager}}disabled{{ end }}>
|
||||
{{.Name}}
|
||||
</option>
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user