1
0
forked from lxh/go-wxhelper

Compare commits

...

74 Commits
hotfix ... main

Author SHA1 Message Date
64a812247a Merge pull request '🐛 Fix a bug.' (#105) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m34s
Reviewed-on: lxh/go-wxhelper#105
2024-08-30 10:07:35 +08:00
9e6d3fad5d 🐛 Fix a bug. 2024-08-30 10:07:03 +08:00
8e2663b85d Merge pull request '🎨 修改邀请入群消息默认响应消息为配置消息' (#104) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m39s
Reviewed-on: lxh/go-wxhelper#104
2024-08-30 08:50:59 +08:00
98a6f1d026 🎨 修改邀请入群消息默认响应消息为配置消息 2024-08-30 08:49:33 +08:00
8968def643 Merge pull request '🎨 修改邀请入群消息默认响应消息为配置消息' (#103) from hotfix into main
Some checks failed
BuildImage / build-image (push) Has been cancelled
Reviewed-on: lxh/go-wxhelper#103
2024-08-29 08:47:06 +08:00
99daff1938 🎨 修改邀请入群消息默认响应消息为配置消息 2024-08-29 08:46:33 +08:00
0dc79274c3 Merge pull request 'hotfix' (#102) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m46s
Reviewed-on: lxh/go-wxhelper#102
2024-08-21 15:53:30 +08:00
7eb8ba9dd8 🐛 修复AI对话限制错误的BUG 2024-08-21 15:53:05 +08:00
f7d153848f Merge pull request 'main' (#101) from main into hotfix
Reviewed-on: lxh/go-wxhelper#101
2024-08-21 10:13:26 +08:00
e0cffb5a2e Merge pull request 'tmp' (#100) from tmp into main
All checks were successful
BuildImage / build-image (push) Successful in 2m49s
Reviewed-on: lxh/go-wxhelper#100
2024-08-21 10:12:39 +08:00
20624e3b46 🎨 配置优化 2024-08-21 10:12:06 +08:00
06f97f26a0 🆕 新增手动发送AI群聊消息总结 2024-08-21 10:11:29 +08:00
ff441aab61 Merge pull request 'tmp' (#99) from tmp into hotfix
Reviewed-on: lxh/go-wxhelper#99
2024-08-20 16:45:06 +08:00
e7358ce88c Merge pull request '🎨 些许优化' (#98) from tmp into main
All checks were successful
BuildImage / build-image (push) Successful in 1m57s
Reviewed-on: lxh/go-wxhelper#98
2024-08-20 16:44:34 +08:00
0251291e4b 🎨 些许优化 2024-08-20 16:43:58 +08:00
038384851b 🔥 重写通讯录和群成员同步逻辑 2024-08-19 16:27:29 +08:00
ec1948c6ce Merge pull request 'hotfix' (#97) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m29s
Reviewed-on: lxh/go-wxhelper#97
2024-08-19 11:49:43 +08:00
f3e2f6e429 🎨 AI对话历史记录数量修改为20条 2024-08-19 11:49:16 +08:00
bc3622464f 🎨 逻辑优化 2024-08-19 11:44:59 +08:00
99a7229c70 🎨 优化页面显示,增加AI对话次数重置提示和联系方式 2024-08-19 09:41:06 +08:00
e8fd8d5f5c Merge pull request '🐛 Fix a bug.' (#96) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m35s
Reviewed-on: lxh/go-wxhelper#96
2024-08-18 07:28:53 +08:00
b02077a42a 🐛 Fix a bug. 2024-08-18 07:23:54 +08:00
28a87a07c0 Merge pull request '🆕 新增每日免费AI对话次数限制' (#95) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m27s
Reviewed-on: lxh/go-wxhelper#95
2024-08-17 13:41:43 +08:00
e673dfa04f 🆕 新增每日免费AI对话次数限制 2024-08-17 13:41:03 +08:00
afa519175b Merge pull request 'hotfix' (#94) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m48s
Reviewed-on: lxh/go-wxhelper#94
2024-08-17 13:16:25 +08:00
88f4069c8e 🆕 新增每日免费AI对话次数限制 2024-08-17 13:16:05 +08:00
e08ad4b438 🆕 新增每日免费AI对话次数限制 2024-08-17 13:14:10 +08:00
cf1be44c9e 🆕 新增每日免费AI对话次数限制 2024-08-17 13:10:31 +08:00
992f02ee1c Merge pull request 'hotfix' (#93) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 2m15s
Reviewed-on: lxh/go-wxhelper#93
2024-07-29 09:16:53 +08:00
fb9a51720e Merge pull request 'hotfix' (#92) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m34s
Reviewed-on: lxh/go-wxhelper#92
2024-07-28 00:59:16 +08:00
c7f1bf8f23 Merge pull request '🎨 优化群聊消息总结逻辑,限制一分钟只处理四个群' (#91) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m43s
Reviewed-on: lxh/go-wxhelper#91
2024-07-27 07:40:07 +08:00
854f1c5491 Merge pull request '🎨 逻辑优化' (#90) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m44s
Reviewed-on: lxh/go-wxhelper#90
2024-07-24 14:12:16 +08:00
2954a42ae2 Merge pull request '🎨 提示语优化' (#89) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m34s
Reviewed-on: lxh/go-wxhelper#89
2024-07-24 06:58:33 +08:00
f48a2c6f24 Merge pull request '🎨 页面优化' (#88) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m53s
Reviewed-on: lxh/go-wxhelper#88
2024-07-23 22:04:08 +08:00
9178613f1d Merge pull request 'hotfix' (#87) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m28s
Reviewed-on: lxh/go-wxhelper#87
2024-07-22 09:20:00 +08:00
791f0a550a Merge pull request '🎨 优化@所有人判断逻辑' (#86) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m54s
Reviewed-on: lxh/go-wxhelper#86
2024-07-22 09:08:44 +08:00
5fac1b56f7 Merge pull request '🔥 移除短链接生成代码,疑似会引起封号' (#85) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m23s
Reviewed-on: lxh/go-wxhelper#85
2024-07-17 08:36:56 +08:00
0f092977ba Merge pull request '🎨 管理指定群组新增模型可选范围限制' (#84) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m33s
Reviewed-on: lxh/go-wxhelper#84
2024-07-16 15:40:20 +08:00
ed791cc501 Merge pull request '🎨 优化热榜的链接为短链' (#83) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m20s
Reviewed-on: lxh/go-wxhelper#83
2024-07-16 13:32:50 +08:00
6761277b1e Merge pull request '🎨 优化热榜的链接为短链' (#82) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#82
2024-07-16 11:59:18 +08:00
0f578e6333 Merge pull request ' 新增功能配置开放' (#81) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m33s
Reviewed-on: lxh/go-wxhelper#81
2024-07-16 11:41:38 +08:00
ae10b76bbc Merge pull request '🎨 逻辑优化' (#80) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m23s
Reviewed-on: lxh/go-wxhelper#80
2024-07-15 15:09:32 +08:00
ba6d5fa98c Merge pull request 'hotfix' (#79) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m35s
Reviewed-on: lxh/go-wxhelper#79
2024-07-15 14:38:04 +08:00
a08966d454 Merge pull request 'hotfix' (#78) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m34s
Reviewed-on: lxh/go-wxhelper#78
2024-07-12 10:04:23 +08:00
6df5816867 Merge pull request '🐛 Fix a bug.' (#77) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#77
2024-07-11 19:37:42 +08:00
534fc904a2 Merge pull request '🐛 Fix a bug.' (#76) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m21s
Reviewed-on: lxh/go-wxhelper#76
2024-07-11 19:32:47 +08:00
f8f2d384f4 Merge pull request 'hotfix' (#75) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m20s
Reviewed-on: lxh/go-wxhelper#75
2024-07-11 15:47:53 +08:00
5b187ff026 Merge pull request '🎨 优化新增加好友或者群之后的响应逻辑' (#74) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#74
2024-07-11 13:56:57 +08:00
3bc33f1d64 Merge pull request '🎨 优化被移除群聊通知逻辑' (#73) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#73
2024-07-11 09:14:18 +08:00
23ca86e75c Merge pull request '🎨 优化被移除群聊通知逻辑' (#72) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#72
2024-07-10 16:32:39 +08:00
bcdf0a45d2 Merge pull request ' 新增被移除群聊通知' (#71) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m27s
Reviewed-on: lxh/go-wxhelper#71
2024-07-10 14:56:49 +08:00
205e34f67e Merge pull request '🎨 逻辑优化' (#70) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m27s
Reviewed-on: lxh/go-wxhelper#70
2024-07-09 08:38:51 +08:00
c0f8169588 Merge pull request '🐛 修复加群通知不提醒的BUG' (#69) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m38s
Reviewed-on: lxh/go-wxhelper#69
2024-07-08 10:58:22 +08:00
d3ec63ff6c Merge pull request 'hotfix' (#68) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#68
2024-07-05 09:44:42 +08:00
f396a7f674 Merge pull request 'hotfix' (#67) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m31s
Reviewed-on: lxh/go-wxhelper#67
2024-07-05 09:17:03 +08:00
df05070e0b Merge pull request '🐛 Fix a bug.' (#66) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m24s
Reviewed-on: lxh/go-wxhelper#66
2024-07-04 21:18:06 +08:00
5afe50975b Merge pull request '🐛 修复修改 AI 模型和角色无法设置为默认的 BUG' (#65) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m58s
Reviewed-on: lxh/go-wxhelper#65
2024-07-04 19:42:42 +08:00
28f111c812 Merge pull request '🔥 修改每日早报接口 Token 为手动配置' (#64) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m19s
Reviewed-on: lxh/go-wxhelper#64
2024-06-24 08:40:53 +08:00
4c08c5caeb Merge pull request '🐛 Fix a bug.' (#63) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m39s
Reviewed-on: lxh/go-wxhelper#63
2024-06-22 08:50:01 +08:00
4fcf1779de Merge pull request '🎨 页面美化' (#62) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m17s
Reviewed-on: lxh/go-wxhelper#62
2024-06-19 14:21:33 +08:00
f946044f13 Merge pull request '🎨 页面美化' (#61) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m21s
Reviewed-on: lxh/go-wxhelper#61
2024-06-19 08:42:35 +08:00
44b8e4a162 Merge pull request '🐛 Fix a bug.' (#60) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m20s
Reviewed-on: lxh/go-wxhelper#60
2024-06-18 17:30:27 +08:00
0452d951a7 Merge pull request 'hotfix' (#59) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m31s
Reviewed-on: lxh/go-wxhelper#59
2024-06-18 17:15:09 +08:00
d8a8bf4efc Merge pull request '🎨 页面优化' (#58) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m38s
Reviewed-on: lxh/go-wxhelper#58
2024-06-17 08:58:51 +08:00
8f6b7cb68d Merge pull request 'hotfix' (#57) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m28s
Reviewed-on: lxh/go-wxhelper#57
2024-06-14 08:36:55 +08:00
72a2e694f8 Merge pull request '🎨 优化好友列表同步处理逻辑' (#56) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m22s
Reviewed-on: lxh/go-wxhelper#56
2024-06-13 07:02:45 +08:00
a13e39dc0a Merge pull request '🎨 优化好友列表同步处理逻辑' (#55) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m31s
Reviewed-on: lxh/go-wxhelper#55
2024-06-12 21:48:04 +08:00
74f19e9d03 Merge pull request 'hotfix' (#54) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 2m9s
Reviewed-on: lxh/go-wxhelper#54
2024-06-06 14:18:58 +08:00
3554c95edc Merge pull request '🎨 消息总结新增传入群名称和过滤排行榜及前一天的总结消息' (#53) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m30s
Reviewed-on: lxh/go-wxhelper#53
2024-05-31 07:27:55 +08:00
db8c460b42 Merge pull request '🎨 优化消息格式' (#52) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m38s
Reviewed-on: lxh/go-wxhelper#52
2024-05-29 14:12:51 +08:00
7747a4b634 Merge pull request '🎨 优化消息格式' (#51) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m51s
Reviewed-on: lxh/go-wxhelper#51
2024-05-20 08:36:12 +08:00
2226ec7e63 Merge pull request 'hotfix' (#50) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m35s
Reviewed-on: lxh/go-wxhelper#50
2024-05-16 00:13:43 +08:00
b0be537c5d Merge pull request '🆕 新增清理不活跃成员功能' (#49) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m31s
Reviewed-on: lxh/go-wxhelper#49
2024-05-15 17:20:12 +08:00
9670c0b2fe Merge pull request 'hotfix' (#48) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m45s
Reviewed-on: lxh/go-wxhelper#48
2024-05-15 11:15:56 +08:00
29 changed files with 937 additions and 115 deletions

View File

@ -280,3 +280,26 @@ func AutoClearMembers(ctx *gin.Context) {
ctx.String(http.StatusOK, "操作成功") ctx.String(http.StatusOK, "操作成功")
} }
// ChangeAiFreeLimit
// @description: 修改AI免费次数
// @param ctx
func ChangeAiFreeLimit(ctx *gin.Context) {
var p autoClearMembers
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`ai_free_limit`", p.Days).Error
if err != nil {
log.Printf("修改AI免费次数失败%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}

56
app/other.go Normal file
View File

@ -0,0 +1,56 @@
package app
import (
"fmt"
"github.com/gin-gonic/gin"
"go-wechat/model/vo"
"go-wechat/service"
"go-wechat/utils"
"log"
"net/http"
)
// SendAiSummary
// @description: 发送AI摘要
// @param ctx
func SendAiSummary(ctx *gin.Context) {
// 获取群Id
groupId := ctx.Query("id")
if groupId == "" {
ctx.String(http.StatusForbidden, "群Id不能为空")
return
}
// 取出群名称
groupInfo, err := service.GetFriendInfoById(groupId)
if err != nil {
ctx.String(http.StatusInternalServerError, "获取群信息失败")
return
}
// 获取对话记录
var records []vo.TextMessageItem
if records, err = service.GetTextMessagesById(groupId); err != nil {
log.Printf("获取群[%s]对话记录失败, 错误信息: %v", groupId, err)
ctx.String(http.StatusInternalServerError, "获取群对话记录失败")
return
}
if len(records) < 10 {
ctx.String(http.StatusForbidden, "群对话记录不足10条建议自己看")
return
}
// 组装对话记录为字符串
var replyMsg string
replyMsg, err = utils.GetAiSummary(groupInfo.Nickname, records)
if err != nil {
log.Printf("群聊记录总结失败: %v", err.Error())
ctx.String(http.StatusInternalServerError, "群聊消息总结失败,错误信息: "+err.Error())
return
}
replyMsg = fmt.Sprintf("#昨日消息总结\n又是一天过去了让我们一起来看看昨儿群友们都聊了什么有趣的话题吧~\n\n%s", replyMsg)
log.Printf("群[%s]对话记录总结成功,总结内容: %s", groupInfo.Nickname, replyMsg)
_ = utils.SendMessage(groupId, "", replyMsg, 0)
ctx.String(http.StatusOK, "操作完成")
}

View File

@ -4,7 +4,7 @@ system:
alApiToken: xxx alApiToken: xxx
# urlc.cn的Token用来生成短链接 # urlc.cn的Token用来生成短链接
urlcApiToken: xxx urlcApiToken: xxx
# 系统访问域名 # 系统访问域名,必须是包括 http[s]:// 的完整域名
domain: https://wechat.abc.com domain: https://wechat.abc.com
# 添加新好友或群之后通知给指定的人 # 添加新好友或群之后通知给指定的人
newFriendNotify: newFriendNotify:
@ -25,11 +25,13 @@ system:
news: true news: true
# 热榜 # 热榜
hotTop: true hotTop: true
# 每天免费 AI 次数限制
aiFreeLimit: 50
# 微信HOOK配置 # 微信HOOK配置
wechat: wechat:
# 微信HOOK接口地址 # 微信HOOK接口地址
host: 10.0.0.79:19088 host: 10.0.0.79:19098
# 微信容器映射出来的vnc页面地址没有就不填 # 微信容器映射出来的vnc页面地址没有就不填
# vncUrl: http://192.168.1.175:19087/vnc_lite.html # vncUrl: http://192.168.1.175:19087/vnc_lite.html
# 是否在启动的时候自动设置hook服务的回调 # 是否在启动的时候自动设置hook服务的回调
@ -59,9 +61,9 @@ task:
hotTop: hotTop:
enable: true enable: true
cron: '0 */1 * * *' # 每小时一次 cron: '0 */1 * * *' # 每小时一次
syncFriends: syncFriends: # 逻辑已修改,每天大半夜同步一次即可(主要是用以修正数据),平时会根据收到的消息针对性同步
enable: false enable: false
cron: '*/5 * * * *' # 五分钟一次 cron: '0 4 * * *' # 每天4:00
groupSummary: groupSummary:
enable: false enable: false
cron: '30 0 * * *' # 每天0:30 cron: '30 0 * * *' # 每天0:30
@ -79,7 +81,7 @@ mq:
enable: false enable: false
# RabbitMQ配置 # RabbitMQ配置
rabbitmq: rabbitmq:
host: 10.0.0.247 host: 10.0.0.31
port: 5672 port: 5672
user: wechat user: wechat
password: wechat123 password: wechat123
@ -100,6 +102,7 @@ ai:
# 人设 # 人设
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。 personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
models: models:
- name: 默认
- name: ChatGPT-4 - name: ChatGPT-4
model: gpt-4 model: gpt-4
canManager: false canManager: false
@ -137,3 +140,7 @@ resource:
wordcloud: wordcloud:
type: image type: image
path: D:\Share\wordcloud\%s path: D:\Share\wordcloud\%s
# 邀请入群消息回复
invitation-join-group:
type: text
path: "您的邀请消息已收到啦,正在通知我的主人来同意请求。在我加群之后将会进行初始化操作,直到收到我主动发送的消息就是初始化完成咯,在那之前请耐心等待喔~"

View File

@ -22,4 +22,5 @@ type defaultRule struct {
Welcome bool `json:"welcome" yaml:"welcome"` // 是否启用欢迎新成员 Welcome bool `json:"welcome" yaml:"welcome"` // 是否启用欢迎新成员
News bool `json:"news" yaml:"news"` // 是否启用每日早报 News bool `json:"news" yaml:"news"` // 是否启用每日早报
HotTop bool `json:"hotTop" yaml:"hotTop"` // 是否启用热门话题 HotTop bool `json:"hotTop" yaml:"hotTop"` // 是否启用热门话题
AiFreeLimit int `json:"aiFreeLimit" yaml:"aiFreeLimit"` // AI免费次数
} }

View File

@ -6,7 +6,6 @@ import (
plugin "go-wechat/plugin" plugin "go-wechat/plugin"
"go-wechat/plugin/plugins" "go-wechat/plugin/plugins"
"go-wechat/service" "go-wechat/service"
"go-wechat/types"
) )
// Plugin // Plugin
@ -31,11 +30,11 @@ func Plugin() {
}, plugins.NotifyInvitationJoinGroup) }, plugins.NotifyInvitationJoinGroup)
// 被移除群聊通知到配置用户 // 被移除群聊通知到配置用户
dispatcher.RegisterHandler(func(m *dto.Message) bool { dispatcher.RegisterHandler(func(m *dto.Message) bool {
return m.Type == types.MsgTypeSys return m.IsRemoveFromChatroom()
}, plugins.NotifyRemoveFromChatroom) }, plugins.NotifyRemoveFromChatroom)
// 响应好友添加成功消息 // 响应好友添加成功消息
dispatcher.RegisterHandler(func(m *dto.Message) bool { dispatcher.RegisterHandler(func(m *dto.Message) bool {
return m.Type == types.MsgTypeSys return m.IsNewFriendAdd() || m.IsJoinToGroup() || m.IsOldFriendBack()
}, plugins.ReplyNewFriend) }, plugins.ReplyNewFriend)
// 私聊指令消息 // 私聊指令消息

View File

@ -12,6 +12,8 @@ import (
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
"os"
"strconv"
"strings" "strings"
"time" "time"
) )
@ -22,6 +24,13 @@ func init() {
initialization.Plugin() // 注册插件 initialization.Plugin() // 注册插件
tasks.InitTasks() // 初始化定时任务 tasks.InitTasks() // 初始化定时任务
mq.Init() // 初始化MQ mq.Init() // 初始化MQ
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SEND")); flag {
log.Printf("已设置环境变量DONT_SEND不发送消息")
}
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SAVE")); flag {
log.Printf("已设置环境变量DONT_SAVE不保存消息")
}
} }
func main() { func main() {

View File

@ -219,3 +219,62 @@ func (m Message) IsInvitationJoinGroup() (flag bool, str string) {
} }
return return
} }
// IsNewFriendAdd
// @description: 是否是新好友添加消息
// @receiver m
// @return flag
func (m Message) IsNewFriendAdd() (flag bool) {
if m.Type != types.MsgTypeSys {
return
}
return strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。")
}
// IsOldFriendBack
// @description: 是否是老好友回归消息
// @receiver m
// @return flag
func (m Message) IsOldFriendBack() (flag bool) {
if m.Type != types.MsgTypeSys {
return
}
return m.Content == "以上是打招呼的内容"
}
// IsJoinToGroup
// @description: 是否是加入群聊消息
// @receiver m
// @return flag
func (m Message) IsJoinToGroup() (flag bool) {
if m.Type != types.MsgTypeSys {
return
}
flag = strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:")
if flag {
return
}
return strings.Contains(m.Content, "\"邀请你和\"") && strings.Contains(m.Content, "\"加入了群聊")
}
// IsRemoveFromChatroom
// @description: 是否是被移出群聊消息
// @receiver m
// @return flag
func (m Message) IsRemoveFromChatroom() (flag bool) {
if m.Type != types.MsgTypeSys {
return
}
return strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊")
}
// IsChangeGroupName
// @description: 是否是修改群名称消息
// @receiver m
// @return flag
func (m Message) IsChangeGroupName() (flag bool) {
if m.Type != types.MsgTypeSys {
return
}
return strings.HasPrefix(m.Content, "\"修改群名为“")
}

View File

@ -25,6 +25,8 @@ type Friend struct {
ClearMember int `json:"clearMember"` // 清理成员配置(多少天未活跃的) ClearMember int `json:"clearMember"` // 清理成员配置(多少天未活跃的)
IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常 IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常
UsedTokens int `json:"usedTokens"` // 已使用的AI Token数量 UsedTokens int `json:"usedTokens"` // 已使用的AI Token数量
AiFreeLimit int `json:"aiFreeLimit"` // AI免费次数
AiUsedToday int `json:"aiUsedToday"` // 今日已使用的AI次数
} }
func (Friend) TableName() string { func (Friend) TableName() string {

View File

@ -24,6 +24,8 @@ type FriendItem struct {
EnableHotTop bool // 是否启用热搜 EnableHotTop bool // 是否启用热搜
ClearMember int // 清理成员配置(多少天未活跃的) ClearMember int // 清理成员配置(多少天未活跃的)
IsOk bool // 是否还在通讯库(群聊是要还在群里也算) IsOk bool // 是否还在通讯库(群聊是要还在群里也算)
AiFreeLimit int // AI免费次数
AiUsedToday int // 今日已使用的AI次数
} }
// GroupUserItem // GroupUserItem

View File

@ -19,6 +19,12 @@ import (
"time" "time"
) )
// 已经通知过的群组或者好友map
var notifyMap = make(map[string]bool)
// 拉取最近消息条数
const fetchMessageCount = 20
// AI // AI
// @description: AI消息 // @description: AI消息
// @param m // @param m
@ -37,6 +43,23 @@ func AI(m *plugin.MessageContext) {
if !friendInfo.EnableAi { if !friendInfo.EnableAi {
return return
} }
if friendInfo.AiFreeLimit > 0 && friendInfo.AiUsedToday >= friendInfo.AiFreeLimit {
if notifyMap[m.FromUser] {
return
}
_ = utils.SendMessage(m.FromUser, "", fmt.Sprintf("本群今天的免费次数已经用完啦,明天再来找我聊天吧~\n每天限制%d次0点自动重置", friendInfo.AiFreeLimit), 0)
notifyMap[m.FromUser] = true
return
} else {
notifyMap[m.FromUser] = false
}
var err error
defer func() {
if err == nil {
service.UpdateAiUsedToday(m.FromUser)
}
}()
// 预处理一下发送的消息,用正则去掉@机器人的内容 // 预处理一下发送的消息,用正则去掉@机器人的内容
re := regexp.MustCompile(`@([^| ]+)`) re := regexp.MustCompile(`@([^| ]+)`)
@ -132,17 +155,17 @@ func AI(m *plugin.MessageContext) {
if err != nil { if err != nil {
log.Printf("OpenAI聊天发起失败: %v", err.Error()) log.Printf("OpenAI聊天发起失败: %v", err.Error())
utils.SendMessage(m.FromUser, m.GroupUser, "AI聊天初始化失败我已经通知我主人来修啦请稍候一下下喔", 0) _ = utils.SendMessage(m.FromUser, m.GroupUser, "AI聊天初始化失败我已经通知我主人来修啦请稍候一下下喔", 0)
return return
} }
// 返回消息为空 // 返回消息为空
if len(resp.Choices) == 0 || resp.Choices[0].Message.Content == "" { if len(resp.Choices) == 0 || resp.Choices[0].Message.Content == "" {
utils.SendMessage(m.FromUser, m.GroupUser, "AI似乎抽风了没有告诉我你需要的回答~", 0) _ = utils.SendMessage(m.FromUser, m.GroupUser, "AI似乎抽风了没有告诉我你需要的回答~", 0)
return return
} }
// 异步更新一下已使用的AI次数 // 异步更新一下已使用的AI tokens
go service.UpdateUsedAiTokens(m.FromUser, resp.Usage.TotalTokens) go service.UpdateUsedAiTokens(m.FromUser, resp.Usage.TotalTokens)
// 保存一下AI 返回的消息,消息 Id 使用传入 Id 的负数 // 保存一下AI 返回的消息,消息 Id 使用传入 Id 的负数
@ -162,7 +185,7 @@ func AI(m *plugin.MessageContext) {
if m.GroupUser != "" { if m.GroupUser != "" {
replyMsg = "\n" + resp.Choices[0].Message.Content replyMsg = "\n" + resp.Choices[0].Message.Content
} }
utils.SendMessage(m.FromUser, m.GroupUser, replyMsg, 0) err = utils.SendMessage(m.FromUser, m.GroupUser, replyMsg, 0)
} }
// getGroupUserMessages // getGroupUserMessages
@ -179,7 +202,7 @@ func getGroupUserMessages(msgId int64, groupId, groupUserId string) (records []e
Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)"). Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)").
Where(subQuery). Where(subQuery).
Order("create_at desc"). Order("create_at desc").
Limit(4).Find(&records) Limit(fetchMessageCount).Find(&records)
return return
} }
@ -195,6 +218,6 @@ func getUserPrivateMessages(userId string) (records []entity.Message) {
Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)"). Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)").
Where(subQuery). Where(subQuery).
Order("create_at desc"). Order("create_at desc").
Limit(4).Find(&records) Limit(fetchMessageCount).Find(&records)
return return
} }

View File

@ -2,28 +2,41 @@ package plugins
import ( import (
"fmt" "fmt"
"go-wechat/client"
"go-wechat/config" "go-wechat/config"
"go-wechat/model/entity"
"go-wechat/plugin" "go-wechat/plugin"
"go-wechat/service" "go-wechat/service"
"go-wechat/utils" "go-wechat/utils"
"strings"
) )
// NotifyInvitationJoinGroup // NotifyInvitationJoinGroup
// @description: 通知邀请入群消息到配置用户 // @description: 通知邀请入群消息到配置用户
// @param m // @param m
func NotifyInvitationJoinGroup(m *plugin.MessageContext) { func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
// 先回复一条固定句子 // 先回复一条固定消息
utils.SendMessage(m.FromUser, m.GroupUser, "您的邀请消息已收到啦,正在通知我的主人来同意请求。在我加群之后将会进行初始化操作,直到收到我主动发送的消息就是初始化完成咯,在那之前请耐心等待喔~", 0) if conf, e := config.Conf.Resource["invitation-join-group"]; e {
// 发送一条新消息
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)
}
}
// 如果是邀请进群,推送到配置的用户 // 推送到配置的用户
if flag, dec := m.IsInvitationJoinGroup(); flag { _, dec := m.IsInvitationJoinGroup()
for _, user := range config.Conf.System.NewFriendNotify.ToUser { for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" { if user != "" {
// 发送一条新消息 // 发送一条新消息
dec = fmt.Sprintf("#邀请入群提醒\n\n%s", dec) dec = fmt.Sprintf("#邀请入群提醒\n\n%s", dec)
utils.SendMessage(user, "", dec, 0) _ = utils.SendMessage(user, "", dec, 0)
}
} }
} }
} }
@ -32,8 +45,6 @@ func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
// @description: 被移除群聊通知到配置用户 // @description: 被移除群聊通知到配置用户
// @param m // @param m
func NotifyRemoveFromChatroom(m *plugin.MessageContext) { func NotifyRemoveFromChatroom(m *plugin.MessageContext) {
// 如果是被移出群聊,推送到配置的用户
if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") {
// 调用一下退出群聊接口,防止被移出后还能从好友列表接口拉到相关信息 // 调用一下退出群聊接口,防止被移出后还能从好友列表接口拉到相关信息
utils.QuitChatroom(m.FromUser, 0) utils.QuitChatroom(m.FromUser, 0)
@ -48,8 +59,10 @@ func NotifyRemoveFromChatroom(m *plugin.MessageContext) {
for _, user := range config.Conf.System.NewFriendNotify.ToUser { for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" { if user != "" {
// 发送一条新消息 // 发送一条新消息
utils.SendMessage(user, "", msg, 0) _ = utils.SendMessage(user, "", msg, 0)
}
} }
} }
// 修改is_ok状态
client.MySQL.Model(&entity.Friend{}).Where("wxid = ?", m.FromUser).Update("is_ok", false)
} }

View File

@ -2,17 +2,30 @@ package plugins
import ( import (
"go-wechat/plugin" "go-wechat/plugin"
"go-wechat/service"
"go-wechat/utils" "go-wechat/utils"
"strings" "time"
) )
// ReplyNewFriend // ReplyNewFriend
// @description: 响应好友添加成功消息 // @description: 响应好友添加成功消息
// @param m // @param m
func ReplyNewFriend(m *plugin.MessageContext) { func ReplyNewFriend(m *plugin.MessageContext) {
isNewFriend := strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。") if m.IsNewFriendAdd() || m.IsJoinToGroup() {
isNewChatroom := strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:") _ = utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化请稍等几分钟初始化完成之后我将主动告知您。", 0)
if isNewFriend || isNewChatroom {
utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化请稍等几分钟初始化完成之后我将主动告知您。", 0)
} }
if m.IsOldFriendBack() {
_ = utils.SendMessage(m.FromUser, "", "嘿,我的朋友,你为何要离我而去?又为何去而复返?", 0)
}
go func() {
// 等待5秒
time.Sleep(5 * time.Second)
// 刷新好友列表
service.SyncFriend()
// 如果是加入群,刷新群成员列表
if m.IsJoinToGroup() {
service.SyncGroupMembers(m.FromUser)
}
}()
} }

View File

@ -5,6 +5,7 @@ import (
"go-wechat/config" "go-wechat/config"
"go-wechat/model/entity" "go-wechat/model/entity"
"go-wechat/plugin" "go-wechat/plugin"
"go-wechat/service"
"go-wechat/utils" "go-wechat/utils"
) )
@ -28,7 +29,7 @@ func WelcomeNew(m *plugin.MessageContext) {
switch conf.Type { switch conf.Type {
case "text": case "text":
// 文字类型 // 文字类型
utils.SendMessage(m.FromUser, "", conf.Path, 0) _ = utils.SendMessage(m.FromUser, "", conf.Path, 0)
case "image": case "image":
// 图片类型 // 图片类型
utils.SendImage(m.FromUser, conf.Path, 0) utils.SendImage(m.FromUser, conf.Path, 0)
@ -36,4 +37,7 @@ func WelcomeNew(m *plugin.MessageContext) {
// 表情类型 // 表情类型
utils.SendEmotion(m.FromUser, conf.Path, 0) utils.SendEmotion(m.FromUser, conf.Path, 0)
} }
// 刷新群成员列表
go service.SyncGroupMembers(m.FromUser)
} }

View File

@ -26,7 +26,9 @@ func Init(g *gin.Engine) {
api := g.Group("/api") api := g.Group("/api")
api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态 api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态
api.POST("/ai/model", app.ChangeUseAiModel) // 修改使用的AI模型 api.POST("/ai/model", app.ChangeUseAiModel) // 修改使用的AI模型
api.POST("/ai/free", app.ChangeAiFreeLimit) // 修改AI免费次数
api.POST("/ai/assistant", app.ChangeUseAiAssistant) // 修改使用的AI助手 api.POST("/ai/assistant", app.ChangeUseAiAssistant) // 修改使用的AI助手
api.POST("/ai/summary", app.SendAiSummary) // 手动发送AI聊天总结
api.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态 api.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态
api.PUT("/command/status", app.ChangeEnableCommandStatus) // 修改是否开启指令状态 api.PUT("/command/status", app.ChangeEnableCommandStatus) // 修改是否开启指令状态
api.PUT("/news/status", app.ChangeEnableNewsStatus) // 修改是否开启早报状态 api.PUT("/news/status", app.ChangeEnableNewsStatus) // 修改是否开启早报状态

View File

@ -152,3 +152,25 @@ func UpdateUsedAiTokens(wxId string, tokens int) {
log.Printf("更新AI使用次数失败, 错误信息: %v", err) log.Printf("更新AI使用次数失败, 错误信息: %v", err)
} }
} }
// UpdateAiUsedToday
// @description: 更新AI今日使用次数
// @param wxId
func UpdateAiUsedToday(wxId string) {
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", wxId).
Update("`ai_used_today`", gorm.Expr(" `ai_used_today` + 1")).Error
if err != nil {
log.Printf("更新AI今日使用次数失败, 错误信息: %v", err)
}
}
// ClearAiUsedToday
// @description: 清空AI今日使用次数
func ClearAiUsedToday() {
err := client.MySQL.Model(&entity.Friend{}).Where("is_ok = 1").
Update("`ai_used_today`", 0).Error
if err != nil {
log.Printf("清空AI今日使用次数失败, 错误信息: %v", err)
}
}

257
service/friendsync.go Normal file
View File

@ -0,0 +1,257 @@
package service
import (
"go-wechat/client"
"go-wechat/common/types"
"go-wechat/config"
"go-wechat/model/entity"
"go-wechat/utils"
"log"
"strings"
"time"
)
// SyncFriend
// @description: 同步好友列表
func SyncFriend() {
// 获取好友列表
friends, err := utils.GetFriendList()
if err != nil {
log.Printf("获取好友列表失败: %s", err.Error())
return
}
// 当前获取到的成员Id用于后续设置is_ok状态
nowIds := make([]string, 0)
// 取出已存在的成员信息
var oldData []entity.Friend
err = client.MySQL.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 notifyMap = make(map[string]string)
// 开启事务
tx := client.MySQL.Begin()
defer tx.Commit()
// 循环获取到的好友列表
for _, item := range friends {
// 填充当前存在的账号
nowIds = append(nowIds, item.Wxid)
// 判断是否已经存在
if _, ok := oldMap[item.Wxid]; ok {
// 已存在,修改
pm := map[string]any{
"nickname": item.Nickname,
"custom_account": item.CustomAccount,
"pinyin": item.Pinyin,
"pinyin_all": item.PinyinAll,
"is_ok": true,
}
err = tx.Model(&entity.Friend{}).Where("wxid = ?", item.Wxid).Updates(pm).Error
if err != nil {
log.Printf("修改好友失败: %s", err.Error())
continue
}
// 如果已存在但是是已退出的群,也通知一下
if !oldMap[item.Wxid] {
notifyMap[item.Wxid] = item.Nickname + " #秽土转生"
// 通知一下,初始化完成
if conf, e := config.Conf.Resource["introduce"]; e {
// 发送一条新消息
switch conf.Type {
case "text":
// 文字类型
_ = utils.SendMessage(item.Wxid, "", conf.Path, 0)
case "image":
// 图片类型
utils.SendImage(item.Wxid, conf.Path, 0)
case "emotion":
// 表情类型
utils.SendEmotion(item.Wxid, conf.Path, 0)
}
}
// 发送配置网页
if config.Conf.System.Domain != "" {
title := "欢迎使用微信机器人(切勿转发)"
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
url := utils.GetManagerUrl(item.Wxid)
utils.SendPublicMsg(item.Wxid, title, desc, url, 0)
}
}
} else {
// 新增
err = tx.Create(&entity.Friend{
CustomAccount: item.CustomAccount,
Nickname: item.Nickname,
Pinyin: item.Pinyin,
PinyinAll: item.PinyinAll,
Wxid: item.Wxid,
IsOk: true,
EnableAi: config.Conf.System.DefaultRule.Ai,
EnableChatRank: config.Conf.System.DefaultRule.ChatRank,
EnableSummary: config.Conf.System.DefaultRule.Summary,
EnableWelcome: config.Conf.System.DefaultRule.Welcome,
EnableNews: config.Conf.System.DefaultRule.News,
EnableHotTop: config.Conf.System.DefaultRule.HotTop,
AiFreeLimit: config.Conf.System.DefaultRule.AiFreeLimit,
ClearMember: 0,
LastActive: types.DateTime(time.Now().Local()),
}).Error
if err != nil {
log.Printf("新增好友失败: %s", err.Error())
continue
}
notifyMap[item.Wxid] = item.Nickname
if conf, e := config.Conf.Resource["introduce"]; e {
// 发送一条新消息
switch conf.Type {
case "text":
// 文字类型
_ = utils.SendMessage(item.Wxid, "", conf.Path, 0)
case "image":
// 图片类型
utils.SendImage(item.Wxid, conf.Path, 0)
case "emotion":
// 表情类型
utils.SendEmotion(item.Wxid, conf.Path, 0)
}
}
// 发送配置网页
if config.Conf.System.Domain != "" {
title := "欢迎使用微信机器人(切勿转发)"
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
url := utils.GetManagerUrl(item.Wxid)
utils.SendPublicMsg(item.Wxid, title, desc, url, 0)
}
}
}
// 通知有新成员
if len(notifyMap) > 0 && config.Conf.System.NewFriendNotify.Enable {
// 组装成一句话
msg := []string{"#新好友通知\n"}
for wxId, nickname := range notifyMap {
msg = append(msg, "微信Id: "+wxId+"\n昵称: "+nickname)
}
for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" {
// 发送一条新消息
_ = utils.SendMessage(user, "", strings.Join(msg, "\n-------\n"), 0)
}
}
}
// 清理不在列表中的好友
clearPm := map[string]any{
"is_ok": false,
}
err = tx.Model(&entity.Friend{}).Where("wxid NOT IN (?)", nowIds).Updates(clearPm).Error
if err != nil {
log.Printf("清理好友失败: %s", err.Error())
}
log.Println("同步好友列表完成")
}
// SyncGroupMembers
// @description: 同步群成员
// @param wxId
func SyncGroupMembers(wxId string) {
membersIds, admin, err := utils.GetGroupMembers(wxId)
if err != nil {
return
}
// 修改不在数组的群成员状态为不在
pm := map[string]any{
"is_member": false,
"leave_time": time.Now().Local(),
}
err = client.MySQL.Model(&entity.GroupUser{}).
Where("group_id = ?", wxId).
Where("is_member IS TRUE").
Where("wxid NOT IN (?)", membersIds).
Updates(pm).Error
if err != nil {
log.Printf("修改群成员状态失败: %s", err.Error())
return
}
// 取出当前数据库存在的成员信息
var oldData []entity.GroupUser
err = client.MySQL.Model(&entity.GroupUser{}).
Where("group_id = ?", wxId).
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.IsMember
}
// 循环获取到的群成员列表
for _, wxid := range membersIds {
// 如果历史数据中存在,且是成员,跳过
if isMember, ok := oldMap[wxid]; ok && isMember {
continue
}
// 获取成员信息
cp, e := utils.GetContactProfile(wxid)
if e != nil {
log.Printf("获取成员信息失败: %s", e.Error())
continue
}
if cp.Wxid != "" {
if _, ok := oldMap[wxid]; ok {
// 历史数据中存在,修改
// 修改
gupm := map[string]any{
"account": cp.Account,
"head_image": cp.HeadImage,
"nickname": cp.Nickname,
"is_member": true,
"is_admin": cp.Wxid == admin,
"leave_time": nil,
}
err = client.MySQL.Model(&entity.GroupUser{}).Where("group_id = ?", wxId).Where("wxid = ?", wxid).Updates(gupm).Error
if err != nil {
log.Printf("修改群成员失败: %s", err.Error())
continue
}
} else {
// 新增的
// 新增
err = client.MySQL.Create(&entity.GroupUser{
GroupId: wxId,
Account: cp.Account,
HeadImage: cp.HeadImage,
Nickname: cp.Nickname,
Wxid: cp.Wxid,
IsMember: true,
IsAdmin: cp.Wxid == admin,
JoinTime: time.Now().Local(),
LastActive: time.Now().Local(),
}).Error
if err != nil {
log.Printf("新增群成员失败: %s", err.Error())
continue
}
}
}
}
}

9
tasks/friends/ai.go Normal file
View File

@ -0,0 +1,9 @@
package friends
import "go-wechat/service"
// ClearAiUsedToday
// @description: 清空AI日使用次数
func ClearAiUsedToday() {
service.ClearAiUsedToday()
}

View File

@ -85,6 +85,7 @@ func Sync() {
EnableWelcome: config.Conf.System.DefaultRule.Welcome, EnableWelcome: config.Conf.System.DefaultRule.Welcome,
EnableNews: config.Conf.System.DefaultRule.News, EnableNews: config.Conf.System.DefaultRule.News,
EnableHotTop: config.Conf.System.DefaultRule.HotTop, EnableHotTop: config.Conf.System.DefaultRule.HotTop,
AiFreeLimit: config.Conf.System.DefaultRule.AiFreeLimit,
ClearMember: 0, ClearMember: 0,
LastActive: types.DateTime(time.Now().Local()), LastActive: types.DateTime(time.Now().Local()),
}).Error }).Error
@ -109,9 +110,9 @@ func Sync() {
} }
// 发送配置网页 // 发送配置网页
if config.Conf.System.Domain != "" { if config.Conf.System.Domain != "" {
title := "欢迎使用微信机器人" title := "欢迎使用微信机器人(切勿转发)"
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid url := utils.GetManagerUrl(friend.Wxid)
utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) utils.SendPublicMsg(friend.Wxid, title, desc, url, 0)
} }
@ -149,9 +150,9 @@ func Sync() {
} }
// 发送配置网页 // 发送配置网页
if config.Conf.System.Domain != "" { if config.Conf.System.Domain != "" {
title := "欢迎使用微信机器人" title := "欢迎使用微信机器人(切勿转发)"
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid url := utils.GetManagerUrl(friend.Wxid)
utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) utils.SendPublicMsg(friend.Wxid, title, desc, url, 0)
} }
} }

View File

@ -1,15 +1,11 @@
package summary package summary
import ( import (
"context"
"fmt" "fmt"
"github.com/sashabaranov/go-openai"
"go-wechat/config"
"go-wechat/model/vo" "go-wechat/model/vo"
"go-wechat/service" "go-wechat/service"
"go-wechat/utils" "go-wechat/utils"
"log" "log"
"strings"
"time" "time"
) )
@ -37,63 +33,21 @@ func AiSummary() {
continue continue
} }
// 组装对话记录为字符串 // 组装对话记录为字符串
var content []string var replyMsg string
for _, record := range records { replyMsg, err = utils.GetAiSummary(group.Nickname, records)
content = append(content, fmt.Sprintf(`{"%s": "%s"}--end--`, record.Nickname, strings.ReplaceAll(record.Message, "\n", "。。")))
}
msgTmp := `请帮我总结一下一下的群聊内容的梗概生成的梗概需要尽可能详细需要带上一些聊天关键信息并且带上群友名字
注意他们可能是多个话题请仔细甄别
每一行代表一个人的发言每一行的的格式为 {"{nickname}": "{content}"}--end--
群名称: %s
聊天记录如下:
%s
`
msg := fmt.Sprintf(msgTmp, group.Nickname, strings.Join(content, "\n"))
// AI总结
messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: msg,
},
}
// 默认使用AI回复
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
if config.Conf.Ai.BaseUrl != "" {
conf.BaseURL = fmt.Sprintf("%s/v1", config.Conf.Ai.BaseUrl)
}
ai := openai.NewClientWithConfig(conf)
var resp openai.ChatCompletionResponse
resp, err = ai.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: config.Conf.Ai.SummaryModel,
Messages: messages,
},
)
if err != nil { if err != nil {
log.Printf("群聊记录总结失败: %v", err.Error()) log.Printf("群聊记录总结失败: %v", err.Error())
utils.SendMessage(group.Wxid, "", "#昨日消息总结\n\n群聊消息总结失败错误信息: "+err.Error(), 0) _ = utils.SendMessage(group.Wxid, "", "#昨日消息总结\n\n群聊消息总结失败错误信息: "+err.Error(), 0)
continue continue
} }
// 返回消息为空 replyMsg = fmt.Sprintf("#昨日消息总结\n又是一天过去了让我们一起来看看昨儿群友们都聊了什么有趣的话题吧~\n\n%s", replyMsg)
if resp.Choices[0].Message.Content == "" {
utils.SendMessage(group.Wxid, "", "#昨日消息总结\n\n群聊消息总结失败AI返回结果为空", 0)
continue
}
replyMsg := fmt.Sprintf("#昨日消息总结\n又是一天过去了让我们一起来看看昨儿群友们都聊了什么有趣的话题吧~\n\n%s", resp.Choices[0].Message.Content)
//log.Printf("群[%s]对话记录总结成功,总结内容: %s", group.Wxid, replyMsg) //log.Printf("群[%s]对话记录总结成功,总结内容: %s", group.Wxid, replyMsg)
utils.SendMessage(group.Wxid, "", replyMsg, 0) _ = utils.SendMessage(group.Wxid, "", replyMsg, 0)
// 判断耗时是否达到15秒,不足就等待 // 判断耗时是否达到一分钟,不足就等待
if used := time.Now().Sub(start); used < 15*time.Second { if used := time.Now().Sub(start); used < time.Minute {
time.Sleep(15*time.Second - used) time.Sleep(time.Minute - used)
} }
} }
} }

View File

@ -65,6 +65,8 @@ func InitTasks() {
// 每天0点检查一次处理清理群成员 // 每天0点检查一次处理清理群成员
_, _ = s.Cron("0 0 * * *").Do(cleargroupuser.ClearGroupUser) _, _ = s.Cron("0 0 * * *").Do(cleargroupuser.ClearGroupUser)
// 每天0点清空AI日使用次数
_, _ = s.Cron("0 0 * * *").Do(friends.ClearAiUsedToday)
// 开启定时任务 // 开启定时任务
s.StartAsync() s.StartAsync()

105
utils/friend.go Normal file
View File

@ -0,0 +1,105 @@
package utils
import (
"encoding/json"
"github.com/go-resty/resty/v2"
"go-wechat/common/constant"
"go-wechat/config"
"go-wechat/model/dto"
"log"
"slices"
"strings"
)
// http客户端
var hc = resty.New()
// GetFriendList
// @description: 获取好友列表
// @return friends
// @return err
func GetFriendList() (friends []dto.FriendItem, err error) {
var base dto.Response[[]dto.FriendItem]
resp, err := hc.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetResult(&base).
Post(config.Conf.Wechat.GetURL("/api/getContactList"))
if err != nil {
log.Printf("获取好友列表失败: %s", err.Error())
return
}
log.Printf("获取好友列表结果: %s", resp.String())
// 循环获取到的好友列表
for _, item := range base.Data {
// 跳过特殊账号
// 跳过公众号和企业微信好友
if strings.Contains(item.Wxid, "gh_") || strings.Contains(item.Wxid, "@openim") {
continue
}
// 特殊Id跳过
if slices.Contains(constant.SpecialId, item.Wxid) {
continue
}
// 添加到待返回列表
friends = append(friends, item)
}
return
}
// GetGroupMembers
// @description: 获取指定群成员
// @param wxId 群Id
// @return ids 群成员id数组
// @return members 群成员信息
// @return err 错误信息
func GetGroupMembers(wxId string) (ids []string, admin string, err error) {
var base dto.Response[dto.GroupUser]
// 组装参数
param := map[string]any{
"chatRoomId": wxId, // 群Id
}
pbs, _ := json.Marshal(param)
_, err = hc.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetBody(string(pbs)).
SetResult(&base).
Post(config.Conf.Wechat.GetURL("/api/getMemberFromChatRoom"))
if err != nil {
log.Printf("获取群成员信息失败: %s", err.Error())
return
}
// 昵称Id
ids = strings.Split(base.Data.Members, "^G")
admin = base.Data.Admin
return
}
// GetContactProfile
// @description: 获取联系人信息
// @param wxId 微信Id
// @return info 联系人信息
// @return err 错误信息
func GetContactProfile(wxId string) (info dto.ContactProfile, err error) {
var baseResp dto.Response[dto.ContactProfile]
// 组装参数
param := map[string]any{
"wxid": wxId, // 群Id
}
pbs, _ := json.Marshal(param)
_, err = hc.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetBody(string(pbs)).
SetResult(&baseResp).
Post(config.Conf.Wechat.GetURL("/api/getContactProfile"))
if err != nil {
log.Printf("获取成员详情失败: %s", err.Error())
return
}
info = baseResp.Data
return
}

View File

@ -2,11 +2,14 @@ package utils
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"go-wechat/common/current" "go-wechat/common/current"
"go-wechat/config" "go-wechat/config"
"log" "log"
"os"
"strconv"
"time" "time"
) )
@ -15,9 +18,14 @@ import (
// @param toId // @param toId
// @param atId // @param atId
// @param msg // @param msg
func SendMessage(toId, atId, msg string, retryCount int) { func SendMessage(toId, atId, msg string, retryCount int) (err error) {
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SEND")); flag {
return
}
if retryCount > 5 { if retryCount > 5 {
log.Printf("重试五次失败,停止发送") log.Printf("重试五次失败,停止发送")
err = errors.New("重试五次失败,停止发送")
return return
} }
@ -48,9 +56,10 @@ func SendMessage(toId, atId, msg string, retryCount int) {
log.Printf("发送文本消息失败: %s", err.Error()) log.Printf("发送文本消息失败: %s", err.Error())
// 休眠五秒后重新发送 // 休眠五秒后重新发送
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
SendMessage(toId, atId, msg, retryCount+1) return SendMessage(toId, atId, msg, retryCount+1)
} }
log.Printf("发送文本消息结果: %s", resp.String()) log.Printf("发送文本消息结果: %s", resp.String())
return
} }
// SendImage // SendImage
@ -59,6 +68,10 @@ func SendMessage(toId, atId, msg string, retryCount int) {
// @param imgPath string 图片路径 // @param imgPath string 图片路径
// @param retryCount int 重试次数 // @param retryCount int 重试次数
func SendImage(toId, imgPath string, retryCount int) { func SendImage(toId, imgPath string, retryCount int) {
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SEND")); flag {
return
}
if retryCount > 5 { if retryCount > 5 {
log.Printf("重试五次失败,停止发送") log.Printf("重试五次失败,停止发送")
return return
@ -91,6 +104,10 @@ func SendImage(toId, imgPath string, retryCount int) {
// @param emotionHash string 表情包hash(md5值) // @param emotionHash string 表情包hash(md5值)
// @param retryCount int 重试次数 // @param retryCount int 重试次数
func SendEmotion(toId, emotionHash string, retryCount int) { func SendEmotion(toId, emotionHash string, retryCount int) {
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SEND")); flag {
return
}
if retryCount > 5 { if retryCount > 5 {
log.Printf("重试五次失败,停止发送") log.Printf("重试五次失败,停止发送")
return return
@ -197,6 +214,10 @@ func QuitChatroom(chatRoomId string, retryCount int) {
// @param url string 链接 // @param url string 链接
// @param retryCount int 重试次数 // @param retryCount int 重试次数
func SendPublicMsg(wxId, title, digest, url string, retryCount int) { func SendPublicMsg(wxId, title, digest, url string, retryCount int) {
if flag, _ := strconv.ParseBool(os.Getenv("DONT_SEND")); flag {
return
}
if retryCount > 5 { if retryCount > 5 {
log.Printf("重试五次失败,停止发送") log.Printf("重试五次失败,停止发送")
return return

108
utils/summary.go Normal file
View File

@ -0,0 +1,108 @@
package utils
import (
"context"
"errors"
"fmt"
"github.com/sashabaranov/go-openai"
"go-wechat/config"
"go-wechat/model/vo"
"log"
"strings"
)
// GetAiSummary
// @description: AI总结群聊记录
// @param groupName
// @param records
// @return replyMsg
// @return err
func GetAiSummary(groupName string, records []vo.TextMessageItem) (replyMsg string, err error) {
// 组装对话记录为字符串
var content []string
for _, record := range records {
content = append(content, fmt.Sprintf(`{"%s": "%s"}--end--`, record.Nickname, strings.ReplaceAll(record.Message, "\n", "。。")))
}
prompt := `# Role: 数据分析师和信息整理专家
# Background: 用户需要从群聊记录中提取有价值的信息包括技术话题讨论工具分享网站或资源链接
# Profile: 你是一位专业的数据分析师擅长从大量文本中提取关键信息并能够高效地整理和总结内容
# Skills: 数据分析信息提取内容总结网络资源评估
# Goals: 设计一个流程帮助用户识别群聊中的技术话题共享的工具和资源并高效地总结每个话题的要点
# Constrains: 该流程需要简洁明了易于用户理解和操作同时确保不遗漏任何重要信息
# OutputFormat: 结构化的文本总结包含关键讨论点结论等
# Workflow:
## 1. 快速浏览群聊记录
- 通过快速浏览聊天记录初步识别出主要话题
## 2. 识别和分类主要话题
- 识别群聊中的主要话题分类讨论内容
- 每个话题独立提取避免混淆
- 话题识别尽可能准确确保不遗漏重要信息
## 3. 编写总结概括
- 对每个话题进行总结包含以下内容
- 关键讨论点主要的讨论内容和观点
- 参与成员参与讨论的成员的昵称
- 结论得出的结论或共识内容要尽可能详细
## 4. 组织信息
- 以逻辑清晰易于理解的方式组织信息
- 使用结构化文本使总结内容易于阅读
## 5. 生成最终总结
- 根据上述步骤生成每个话题的详细总结
- 确保每个总结完整且有条理
- 返回数据格式为结构化文本方便用户查阅
## 6. 群聊记录消息格式
格式: {"{nickname}": "{content}"}--end--
# Examples:
- 话题技术讨论 - AI在医疗领域的应用
- 关键讨论点讨论了AI在医疗诊断中的应用前景和现有挑战
- 成员张三李四王五
- 结论AI技术有望提高医疗诊断的准确性和效率但数据隐私和模型解释性仍需解决
- 话题美食讨论 - 杭州到底有没有美食
- 关键讨论点讨论了杭州的美食有哪些分布地区评价如何
- 成员张三李四王五
- 结论杭州好像没有美食
`
msg := fmt.Sprintf("群名称: %s\n聊天记录如下:\n%s", groupName, strings.Join(content, "\n"))
// AI总结
messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: prompt,
},
{
Role: openai.ChatMessageRoleUser,
Content: msg,
},
}
// 默认使用AI回复
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
if config.Conf.Ai.BaseUrl != "" {
conf.BaseURL = fmt.Sprintf("%s/v1", config.Conf.Ai.BaseUrl)
}
ai := openai.NewClientWithConfig(conf)
var resp openai.ChatCompletionResponse
resp, err = ai.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: config.Conf.Ai.SummaryModel,
Messages: messages,
},
)
if err != nil {
log.Printf("群聊记录总结失败: %v", err.Error())
return
}
// 返回消息为空
if resp.Choices[0].Message.Content == "" {
err = errors.New("AI返回结果为空")
return
}
replyMsg = resp.Choices[0].Message.Content
return
}

21
utils/url.go Normal file
View File

@ -0,0 +1,21 @@
package utils
import (
"encoding/base64"
"fmt"
"go-wechat/config"
)
// GetManagerUrl
// @description: 获取管理页面链接
// @param wxId
// @return newUrl
func GetManagerUrl(wxId string) (url string) {
// 生成管理页面链接
url = fmt.Sprintf("%s/manager.html?id=%s", config.Conf.System.Domain, wxId)
// base64一下
encodeString := base64.StdEncoding.EncodeToString([]byte(url))
// 拼接新链接(这个是一个已备案的域名)
url = "https://redirect.gitee.ltd/?s=" + encodeString
return
}

View File

@ -57,6 +57,9 @@
<!-- 消息总结 --> <!-- 消息总结 -->
{{define "summary"}} {{define "summary"}}
{{ if eq .EnableSummary true }}
<button type="button" class="btn-link float-end text-blue-600" onclick="sendAiSummary({{.Wxid}})">手动发送总结</button>
{{ end }}
<button type="button" <button type="button"
class="{{ if eq .EnableSummary true }}bg-green-600{{ else }}bg-gray-200{{ end }} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2" class="{{ if eq .EnableSummary true }}bg-green-600{{ else }}bg-gray-200{{ end }} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2"
role="switch" aria-checked="false" onclick="changeSummaryEnableStatus({{.Wxid}})"> role="switch" aria-checked="false" onclick="changeSummaryEnableStatus({{.Wxid}})">

View File

@ -94,6 +94,26 @@
</label> </label>
</dd> </dd>
</div> </div>
<!-- 每日 AI 免费次数限制 -->
<div class="flex justify-between gap-x-4 py-3 items-center">
<dt class="text-gray-500">
每日 AI 免费次数
</dt>
<dd class="flex items-start gap-x-2 items-center">
<div class="relative rounded-md">
<label>
<input type="number" id="auto-ai-{{ .Wxid }}" min="0" class="block w-1/2 float-end rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" placeholder="每日 AI 免费次数限制"
value="{{.AiFreeLimit}}"
onblur="changeAiFreeLimit({{.Wxid}}, this.value)"
>
</label>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
<span class="text-gray-500 sm:text-sm" id="price-currency"></span>
</div>
</div>
</dd>
</div>
{{ end }} {{ end }}
<div class="flex justify-between gap-x-4 py-3"> <div class="flex justify-between gap-x-4 py-3">

View File

@ -56,6 +56,7 @@
</div> </div>
{{ if eq .EnableAi true }} {{ if eq .EnableAi true }}
<div class="float-end"> <div class="float-end">
<!-- 模型 -->
<div> <div>
<label> <label>
<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, {{.Wxid}})"> <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, {{.Wxid}})">
@ -68,13 +69,13 @@
</select> </select>
</label> </label>
</div> </div>
<!-- AI角色 -->
<div class="float-end mt-1"> <div class="float-end mt-1">
<label> <label>
<select <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" 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="aiAssistantChange(event, {{.Wxid}})"> onchange="aiAssistantChange(event, {{.Wxid}})">
<option value="" {{ if eq .Prompt <option value="" {{ if eq .Prompt "" }}selected{{ end }}>默认</option>
"" }}selected{{ end }}>默认</option>
{{$usePrompt := .Prompt}} {{$usePrompt := .Prompt}}
{{ range $.assistant }} {{ range $.assistant }}
@ -89,6 +90,26 @@
{{ end }} {{ end }}
</dd> </dd>
</div> </div>
<!-- 每日 AI 免费次数限制 -->
<div class="flex justify-between gap-x-4 py-3 items-center">
<dt class="text-gray-500">
每日 AI 免费次数限制
<span class="text-red-300">(0表示不限)</span>
</dt>
<dd class="flex items-start gap-x-2 items-center">
<div class="relative rounded-md">
<label>
<input type="number" id="auto-ai-{{ .Wxid }}" min="0" class="block w-1/2 float-end rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" placeholder="每日 AI 免费次数限制"
value="{{.AiFreeLimit}}"
onblur="changeAiFreeLimit({{.Wxid}}, this.value)"
>
</label>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
<span class="text-gray-500 sm:text-sm" id="price-currency"></span>
</div>
</div>
</dd>
</div>
<!-- 水群排行榜 --> <!-- 水群排行榜 -->
<div class="flex justify-between gap-x-4 py-3 items-center"> <div class="flex justify-between gap-x-4 py-3 items-center">
<dt class="text-gray-500">水群排行榜</dt> <dt class="text-gray-500">水群排行榜</dt>

View File

@ -81,6 +81,18 @@
{{ end }} {{ end }}
</dd> </dd>
</div> </div>
<!-- 今日 AI 对话已使用次数 -->
<div class="flex justify-between gap-x-4 py-3 items-center">
<dt class="text-gray-500">
今日 AI 对话已使用次数
<br/>
<span class="text-red-300">* 每天0点重置</span>
<p class="text-gray-400">需要扩容请添加微信: _Elixir</p>
</dt>
<dd class="flex items-start gap-x-2">
{{ .info.AiUsedToday }}次{{ if lt 1 .info.AiFreeLimit }}(限制{{ .info.AiFreeLimit }}次){{ end }}
</dd>
</div>
{{$isGroup := checkIsGroup .info.Wxid}} {{$isGroup := checkIsGroup .info.Wxid}}
{{ if eq $isGroup true }} {{ if eq $isGroup true }}

View File

@ -291,3 +291,56 @@ function changeClearMember(wxid, oldVal, newVal) {
window.location.reload(); window.location.reload();
}) })
} }
// 修改每日免费 AI 对话次数
function changeAiFreeLimit(wxid, limitNumber) {
limitNumber = Number(limitNumber)
if (limitNumber < 0) {
alert('值不能小于0')
}
// 请求接口
axios({
method: 'post',
url: '/api/ai/free',
data: {
wxid: wxid,
days: Number(limitNumber)
}
}).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`);
alert(`${response.data}`)
}).catch(function (error) {
console.log(`错误信息: ${error}`);
alert("修改失败")
}).finally(function () {
window.location.reload();
})
}
// 发送AI群聊总结
function sendAiSummary(wxid) {
if (wxid === '') {
alert("wxid不能为空")
return
}
if (!confirm("确定发送AI群聊总结吗?")) {
return
}
// 请求接口
axios({
method: 'post',
url: '/api/ai/summary',
params: {
id: wxid,
}
}).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`);
alert(`${response.data}`)
}).catch(function (error) {
console.log(`错误信息: ${error}`);
alert(`${response.data}`)
}).finally(function () {
window.location.reload();
})
}