Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89c504d019 | ||
|
|
14d407eff1 | ||
|
|
d4fcfda112 | ||
|
|
ce11fd40c4 | ||
|
|
454b5f0980 | ||
|
|
2af0719f51 | ||
|
|
699f10e854 | ||
|
|
0430c2203e | ||
|
|
917e96b332 | ||
|
|
e80fe2a7a0 |
10
Dockerfile
10
Dockerfile
@@ -6,8 +6,8 @@ COPY . .
|
||||
#ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
RUN go version
|
||||
RUN go mod download && go build -o app
|
||||
RUN ls -lh && chmod +x ./app
|
||||
RUN go mod download && go build -o wxhelper
|
||||
RUN ls -lh && chmod -R +x ./*
|
||||
|
||||
FROM code.hyxc1.com/open/alpine:3.16.0 as runner
|
||||
LABEL org.opencontainers.image.authors="lxh@cxh.cn"
|
||||
@@ -16,6 +16,6 @@ EXPOSE 19099
|
||||
EXPOSE 8080
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /builder/app ./app
|
||||
COPY ./views ./views
|
||||
CMD ./app
|
||||
COPY --from=builder /builder/wxhelper ./wxhelper
|
||||
COPY --from=builder /builder/views ./views
|
||||
CMD ./wxhelper
|
||||
110
app/friend.go
Normal file
110
app/friend.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-wechat/client"
|
||||
"go-wechat/entity"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// changeStatusParam
|
||||
// @description: 修改状态用的参数集
|
||||
type changeStatusParam struct {
|
||||
WxId string `json:"wxId" binding:"required"`
|
||||
UserId string `json:"userId"`
|
||||
}
|
||||
|
||||
// ChangeEnableAiStatus
|
||||
// @description: 修改是否开启AI
|
||||
// @param ctx
|
||||
func ChangeEnableAiStatus(ctx *gin.Context) {
|
||||
var p changeStatusParam
|
||||
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("`enable_ai`", gorm.Expr(" !`enable_ai`")).Error
|
||||
if err != nil {
|
||||
log.Printf("修改是否开启AI失败:%s", err)
|
||||
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(http.StatusOK, "操作成功")
|
||||
}
|
||||
|
||||
// ChangeEnableGroupRankStatus
|
||||
// @description: 修改是否开启水群排行榜
|
||||
// @param ctx
|
||||
func ChangeEnableGroupRankStatus(ctx *gin.Context) {
|
||||
var p changeStatusParam
|
||||
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("`enable_chat_rank`", gorm.Expr(" !`enable_chat_rank`")).Error
|
||||
if err != nil {
|
||||
log.Printf("修改开启水群排行榜失败:%s", err)
|
||||
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(http.StatusOK, "操作成功")
|
||||
}
|
||||
|
||||
// ChangeEnableWelcomeStatus
|
||||
// @description: 修改是否开启迎新
|
||||
// @param ctx
|
||||
func ChangeEnableWelcomeStatus(ctx *gin.Context) {
|
||||
var p changeStatusParam
|
||||
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("`enable_welcome`", gorm.Expr(" !`enable_welcome`")).Error
|
||||
if err != nil {
|
||||
log.Printf("修改开启迎新失败:%s", err)
|
||||
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(http.StatusOK, "操作成功")
|
||||
}
|
||||
|
||||
// ChangeSkipGroupRankStatus
|
||||
// @description: 修改是否跳过水群排行榜
|
||||
// @param ctx
|
||||
func ChangeSkipGroupRankStatus(ctx *gin.Context) {
|
||||
var p changeStatusParam
|
||||
if err := ctx.ShouldBindJSON(&p); err != nil {
|
||||
ctx.String(http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
log.Printf("待修改的群Id:%s -> %s", p.WxId, p.UserId)
|
||||
|
||||
err := client.MySQL.Model(&entity.GroupUser{}).
|
||||
Where("group_id = ?", p.WxId).
|
||||
Where("wxid = ?", p.UserId).
|
||||
Update("`skip_chat_rank`", gorm.Expr(" !`skip_chat_rank`")).Error
|
||||
if err != nil {
|
||||
log.Printf("修改跳过水群排行榜失败:%s", err)
|
||||
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(http.StatusOK, "操作成功")
|
||||
}
|
||||
30
app/group.go
Normal file
30
app/group.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-wechat/service"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type getGroupUser struct {
|
||||
GroupId string `json:"groupId" form:"groupId" binding:"required"` // 群Id
|
||||
}
|
||||
|
||||
// GetGroupUsers
|
||||
// @description: 获取群成员列表
|
||||
// @param ctx
|
||||
func GetGroupUsers(ctx *gin.Context) {
|
||||
var p getGroupUser
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
ctx.String(http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
// 查询数据
|
||||
records, err := service.GetGroupUsersByGroupId(p.GroupId)
|
||||
if err != nil {
|
||||
ctx.String(http.StatusInternalServerError, "查询失败: %s", err.Error())
|
||||
return
|
||||
}
|
||||
// 暂时先就这样写着,跑通了再改
|
||||
ctx.JSON(http.StatusOK, records)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (dt DateTime) Value() (dv driver.Value, err error) {
|
||||
|
||||
// 用于 fmt.Println 和后续验证场景
|
||||
func (dt DateTime) String() string {
|
||||
return dt.Format(dateTimeFormat)
|
||||
return dt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// Format 格式化
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Friend
|
||||
// @description: 好友列表
|
||||
type Friend struct {
|
||||
Wxid string `json:"wxid"` // 微信原始Id
|
||||
CustomAccount string `json:"customAccount"` // 微信号
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Pinyin string `json:"pinyin"` // 昵称拼音大写首字母
|
||||
PinyinAll string `json:"pinyinAll"` // 昵称全拼
|
||||
Wxid string `json:"wxid"` // 微信原始Id
|
||||
EnableAi bool `json:"enableAI" gorm:"type:tinyint(1) default 0 not null"` // 是否使用AI
|
||||
EnableChatRank bool `json:"enableChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否使用聊天排行
|
||||
EnableWelcome bool `json:"enableWelcome" gorm:"type:tinyint(1) default 0 not null"` // 是否启用迎新
|
||||
IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常
|
||||
}
|
||||
|
||||
@@ -23,11 +26,12 @@ func (Friend) TableName() string {
|
||||
// @description: 群成员
|
||||
type GroupUser struct {
|
||||
GroupId string `json:"groupId"` // 群Id
|
||||
Wxid string `json:"wxid"` // 微信Id
|
||||
Account string `json:"account"` // 账号
|
||||
HeadImage string `json:"headImage"` // 头像
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Wxid string `json:"wxid"` // 微信Id
|
||||
IsMember bool `json:"isMember" gorm:"type:tinyint(1) default 0 not null"` // 是否群成员
|
||||
JoinTime time.Time `json:"joinTime"` // 加入时间
|
||||
LeaveTime *time.Time `json:"leaveTime"` // 离开时间
|
||||
SkipChatRank bool `json:"skipChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否跳过聊天排行
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"go-wechat/client"
|
||||
"go-wechat/config"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/service"
|
||||
"go-wechat/model"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"regexp"
|
||||
@@ -16,26 +17,15 @@ import (
|
||||
// handleAtMessage
|
||||
// @description: 处理At机器人的消息
|
||||
// @param m
|
||||
func handleAtMessage(m entity.Message) {
|
||||
func handleAtMessage(m model.Message) {
|
||||
if !config.Conf.Ai.Enable {
|
||||
return
|
||||
}
|
||||
|
||||
// 取出所有启用了AI的好友或群组
|
||||
us, err := service.GetAllEnableAI()
|
||||
if err != nil {
|
||||
utils.SendMessage(m.FromUser, m.GroupUser, "#系统异常\n"+err.Error(), 0)
|
||||
return
|
||||
}
|
||||
// 判断是否启用,如果没有启用,直接返回
|
||||
var canUse bool
|
||||
for _, u := range us {
|
||||
if u.Wxid == m.FromUser {
|
||||
canUse = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !canUse {
|
||||
var count int64
|
||||
client.MySQL.Model(&entity.Friend{}).Where("enable_ai IS TRUE").Where("wxid = ?", m.FromUser).Count(&count)
|
||||
if count < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -63,9 +53,9 @@ func handleAtMessage(m entity.Message) {
|
||||
})
|
||||
|
||||
// 配置模型
|
||||
model := openai.GPT3Dot5Turbo0613
|
||||
chatModel := openai.GPT3Dot5Turbo0613
|
||||
if config.Conf.Ai.Model != "" {
|
||||
model = config.Conf.Ai.Model
|
||||
chatModel = config.Conf.Ai.Model
|
||||
}
|
||||
|
||||
// 默认使用AI回复
|
||||
@@ -77,7 +67,7 @@ func handleAtMessage(m entity.Message) {
|
||||
resp, err := client.CreateChatCompletion(
|
||||
context.Background(),
|
||||
openai.ChatCompletionRequest{
|
||||
Model: model,
|
||||
Model: chatModel,
|
||||
Messages: messages,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"go-wechat/model"
|
||||
"go-wechat/service"
|
||||
"go-wechat/types"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -23,43 +24,47 @@ func Parse(remoteAddr net.Addr, msg []byte) {
|
||||
return
|
||||
}
|
||||
// 提取出群成员信息
|
||||
groupUser := ""
|
||||
msgStr := m.Content
|
||||
//groupUser := ""
|
||||
//msgStr := m.Content
|
||||
if strings.Contains(m.FromUser, "@") {
|
||||
switch m.Type {
|
||||
case types.MsgTypeRecalled:
|
||||
// 消息撤回
|
||||
case types.MsgTypeSys:
|
||||
// 系统消息
|
||||
go handleSysMessage(m)
|
||||
default:
|
||||
// 默认消息处理
|
||||
groupUser = strings.Split(m.Content, "\n")[0]
|
||||
groupUser = strings.ReplaceAll(groupUser, ":", "")
|
||||
|
||||
// 文字消息单独提出来处理一下
|
||||
msgStr = strings.Join(strings.Split(m.Content, "\n")[1:], "\n")
|
||||
// 群消息,处理一下消息和发信人
|
||||
groupUser := strings.Split(m.Content, "\n")[0]
|
||||
groupUser = strings.ReplaceAll(groupUser, ":", "")
|
||||
// 如果两个id一致,说明是系统发的
|
||||
if m.FromUser != groupUser {
|
||||
m.GroupUser = groupUser
|
||||
}
|
||||
// 用户的操作单独提出来处理一下
|
||||
m.Content = strings.Join(strings.Split(m.Content, "\n")[1:], "\n")
|
||||
}
|
||||
log.Printf("%s\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", remoteAddr, m.FromUser, groupUser, m.Type, msgStr)
|
||||
log.Printf("%s\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", remoteAddr, m.FromUser, m.GroupUser, m.Type, m.Content)
|
||||
|
||||
// 异步处理消息
|
||||
go func() {
|
||||
if m.IsNewUserJoin() {
|
||||
// 欢迎新成员
|
||||
go handleNewUserJoin(m)
|
||||
} else if m.IsAt() {
|
||||
// @机器人的消息
|
||||
go handleAtMessage(m)
|
||||
} else if !strings.Contains(m.FromUser, "@") && m.Type == types.MsgTypeText {
|
||||
// 私聊消息处理
|
||||
utils.SendMessage(m.FromUser, "", "暂未开启私聊AI", 0)
|
||||
}
|
||||
}()
|
||||
|
||||
// 转换为结构体之后入库
|
||||
var ent entity.Message
|
||||
ent.MsgId = m.MsgId
|
||||
ent.CreateTime = m.CreateTime
|
||||
ent.CreateAt = time.Unix(int64(m.CreateTime), 0)
|
||||
ent.Content = msgStr
|
||||
ent.Content = m.Content
|
||||
ent.FromUser = m.FromUser
|
||||
ent.GroupUser = groupUser
|
||||
ent.GroupUser = m.GroupUser
|
||||
ent.ToUser = m.ToUser
|
||||
ent.Type = m.Type
|
||||
ent.DisplayFullContent = m.DisplayFullContent
|
||||
ent.Raw = string(msg)
|
||||
|
||||
// 处理At机器人的消息
|
||||
if strings.HasSuffix(m.DisplayFullContent, "在群聊中@了你") {
|
||||
go handleAtMessage(ent)
|
||||
}
|
||||
|
||||
go service.SaveMessage(ent)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"go-wechat/client"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/model"
|
||||
"go-wechat/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// handleSysMessage
|
||||
// @description: 系统消息处理
|
||||
// handleNewUserJoin
|
||||
// @description: 欢迎新成员
|
||||
// @param m
|
||||
func handleSysMessage(m model.Message) {
|
||||
// 有人进群
|
||||
if strings.Contains(m.Content, "\"邀请\"") && strings.Contains(m.Content, "\"加入了群聊") {
|
||||
// 发一张图乐呵乐呵
|
||||
// 自己欢迎自己图片地址 D:\Share\emoticon\welcome-yourself.gif
|
||||
utils.SendImage(m.FromUser, "D:\\Share\\emoticon\\welcome-yourself.gif", 0)
|
||||
func handleNewUserJoin(m model.Message) {
|
||||
// 判断是否开启迎新
|
||||
var count int64
|
||||
client.MySQL.Model(&entity.Friend{}).Where("enable_welcome IS TRUE").Where("wxid = ?", m.FromUser).Count(&count)
|
||||
if count < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// 发一张图乐呵乐呵
|
||||
|
||||
// 自己欢迎自己图片地址 D:\Share\emoticon\welcome-yourself.gif
|
||||
utils.SendImage(m.FromUser, "D:\\Share\\emoticon\\welcome-yourself.gif", 0)
|
||||
}
|
||||
|
||||
23
main.go
23
main.go
@@ -8,7 +8,10 @@ import (
|
||||
"go-wechat/tasks"
|
||||
"go-wechat/tcpserver"
|
||||
"go-wechat/utils"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -30,14 +33,32 @@ func main() {
|
||||
|
||||
// 启动HTTP服务
|
||||
app := gin.Default()
|
||||
|
||||
// 自定义模板引擎函数
|
||||
app.SetFuncMap(template.FuncMap{
|
||||
"checkSwap": func(flag bool) string {
|
||||
if flag {
|
||||
return "swap-active"
|
||||
}
|
||||
return ""
|
||||
},
|
||||
})
|
||||
|
||||
app.LoadHTMLGlob("views/*.html")
|
||||
app.Static("/assets", "./views/assets")
|
||||
app.Static("/assets", "./views/static")
|
||||
app.StaticFile("/favicon.ico", "./views/wechat.ico")
|
||||
// 404返回数据
|
||||
app.NoRoute(func(ctx *gin.Context) {
|
||||
if strings.HasPrefix(ctx.Request.URL.Path, "/api") {
|
||||
ctx.String(404, "接口不存在")
|
||||
return
|
||||
}
|
||||
// 404直接跳转到首页
|
||||
ctx.Redirect(302, "/index.html")
|
||||
})
|
||||
app.NoMethod(func(ctx *gin.Context) {
|
||||
ctx.String(http.StatusMethodNotAllowed, "不支持的请求方式")
|
||||
})
|
||||
// 初始化路由
|
||||
router.Init(app)
|
||||
if err := app.Run(":8080"); err != nil {
|
||||
|
||||
@@ -1,18 +1,87 @@
|
||||
package model
|
||||
|
||||
import "go-wechat/types"
|
||||
import (
|
||||
"encoding/xml"
|
||||
"go-wechat/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Message
|
||||
// @description: 消息
|
||||
type Message struct {
|
||||
MsgId int64 `json:"msgId" gorm:"primarykey"`
|
||||
MsgId int64 `json:"msgId"`
|
||||
CreateTime int `json:"createTime"`
|
||||
Content string `json:"content"`
|
||||
DisplayFullContent string `json:"displayFullContent" gorm:"-"`
|
||||
DisplayFullContent string `json:"displayFullContent"`
|
||||
FromUser string `json:"fromUser"`
|
||||
GroupUser string `json:"-"`
|
||||
MsgSequence int `json:"msgSequence"`
|
||||
Pid int `json:"pid"`
|
||||
Signature string `json:"signature"`
|
||||
ToUser string `json:"toUser"`
|
||||
Type types.MessageType `json:"type"`
|
||||
}
|
||||
|
||||
// systemMsgDataXml
|
||||
// @description: 微信系统消息的xml结构
|
||||
type systemMsgDataXml struct {
|
||||
SysMsg sysMsg `xml:"sysmsg"`
|
||||
Type string `xml:"type,attr"`
|
||||
}
|
||||
|
||||
// sysMsg
|
||||
// @description: 消息主体
|
||||
type sysMsg struct{}
|
||||
|
||||
// IsPat
|
||||
// @description: 是否是拍一拍消息
|
||||
// @receiver m
|
||||
// @return bool
|
||||
func (m Message) IsPat() bool {
|
||||
// 解析xml
|
||||
var d systemMsgDataXml
|
||||
if err := xml.Unmarshal([]byte(m.Content), &d); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return m.Type == types.MsgTypeRecalled && d.Type == "pat"
|
||||
}
|
||||
|
||||
// IsRevokeMsg
|
||||
// @description: 是否是撤回消息
|
||||
// @receiver m
|
||||
// @return bool
|
||||
func (m Message) IsRevokeMsg() bool {
|
||||
// 解析xml
|
||||
var d systemMsgDataXml
|
||||
if err := xml.Unmarshal([]byte(m.Content), &d); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return m.Type == types.MsgTypeRecalled && d.Type == "revokemsg"
|
||||
}
|
||||
|
||||
// IsNewUserJoin
|
||||
// @description: 是否是新人入群
|
||||
// @receiver m
|
||||
// @return bool
|
||||
func (m Message) IsNewUserJoin() bool {
|
||||
sysFlag := m.Type == types.MsgTypeSys && strings.Contains(m.Content, "\"邀请\"") && strings.Contains(m.Content, "\"加入了群聊")
|
||||
if sysFlag {
|
||||
return true
|
||||
}
|
||||
// 解析另一种情况
|
||||
var d systemMsgDataXml
|
||||
if err := xml.Unmarshal([]byte(m.Content), &d); err != nil {
|
||||
return false
|
||||
}
|
||||
return m.Type == types.MsgTypeSys && d.Type == "delchatroommember"
|
||||
}
|
||||
|
||||
// IsAt
|
||||
// @description: 是否是At机器人的消息
|
||||
// @receiver m
|
||||
// @return bool
|
||||
func (m Message) IsAt() bool {
|
||||
return strings.HasSuffix(m.DisplayFullContent, "在群聊中@了你")
|
||||
}
|
||||
|
||||
@@ -18,4 +18,12 @@ func Init(g *gin.Engine) {
|
||||
g.GET("/test.html", func(ctx *gin.Context) {
|
||||
ctx.HTML(200, "test.html", nil)
|
||||
})
|
||||
|
||||
// 接口
|
||||
api := g.Group("/api")
|
||||
api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态
|
||||
api.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态
|
||||
api.PUT("/grouprank/status", app.ChangeEnableGroupRankStatus) // 修改是否开启水群排行榜状态
|
||||
api.PUT("/grouprank/skip", app.ChangeSkipGroupRankStatus) // 修改是否跳过水群排行榜状态
|
||||
api.GET("/group/users", app.GetGroupUsers) // 获取群成员列表
|
||||
}
|
||||
|
||||
25
service/group.go
Normal file
25
service/group.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"go-wechat/client"
|
||||
"go-wechat/vo"
|
||||
)
|
||||
|
||||
// GetGroupUsersByGroupId
|
||||
// @description: 根据群Id取出群成员列表
|
||||
// @param groupId
|
||||
// @return records
|
||||
// @return err
|
||||
func GetGroupUsersByGroupId(groupId string) (records []vo.GroupUserItem, err error) {
|
||||
err = client.MySQL.
|
||||
Table("t_group_user AS tgu").
|
||||
Joins("LEFT JOIN t_message AS tm ON tm.from_user = tgu.group_id AND tm.group_user = tgu.wxid").
|
||||
//Select("tgu.wxid", "tgu.nickname", "tgu.head_image", "tgu.is_member", "tgu.leave_time",
|
||||
// "tgu.skip_chat_rank", "MAX(tm.create_at) AS last_active_time").
|
||||
Select("tgu.*", "MAX(tm.create_at) AS last_active_time").
|
||||
Where("tgu.group_id = ?", groupId).
|
||||
Group("tgu.group_id, tgu.wxid").
|
||||
Order("tgu.join_time DESC").
|
||||
Find(&records).Error
|
||||
return
|
||||
}
|
||||
@@ -65,6 +65,7 @@ func Sync() {
|
||||
Pinyin: friend.Pinyin,
|
||||
PinyinAll: friend.PinyinAll,
|
||||
Wxid: friend.Wxid,
|
||||
IsOk: true,
|
||||
}).Error
|
||||
if err != nil {
|
||||
log.Printf("新增好友失败: %s", err.Error())
|
||||
@@ -154,6 +155,7 @@ func syncGroupUsers(tx *gorm.DB, gid string) {
|
||||
Nickname: cp.Nickname,
|
||||
Wxid: cp.Wxid,
|
||||
IsMember: true,
|
||||
JoinTime: time.Now().Local(),
|
||||
}).Error
|
||||
if err != nil {
|
||||
log.Printf("新增群成员失败: %s", err.Error())
|
||||
|
||||
@@ -4,6 +4,7 @@ import "fmt"
|
||||
|
||||
type MessageType int
|
||||
|
||||
// 微信定义的消息类型
|
||||
const (
|
||||
MsgTypeText MessageType = 1 // 文本消息
|
||||
MsgTypeImage MessageType = 3 // 图片消息
|
||||
|
||||
244
views/index.html
244
views/index.html
@@ -4,8 +4,12 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>水群助手</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.4.14/dist/full.min.css" rel="stylesheet" type="text/css" />
|
||||
<!-- <link href="https://cdn.jsdelivr.net/npm/daisyui@4.4.14/dist/full.min.css" rel="stylesheet" type="text/css" />-->
|
||||
<link href="assets/css/daisyui-4.4.14-full.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/index.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.5.0/axios.min.js"></script>
|
||||
|
||||
<script src="assets/js/index.js"></script>
|
||||
</head>
|
||||
@@ -19,92 +23,168 @@
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<div class="collapse collapse-arrow bg-base-200">
|
||||
<input type="radio" name="my-accordion-2" checked="checked" />
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
好友列表
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
<div role="tablist" class="tabs tabs-bordered">
|
||||
<input type="radio" name="friend_tab" role="tab" class="tab" aria-label="好友列表" checked />
|
||||
<div role="tabpanel" class="tab-content p-6">
|
||||
<!-- 循环好友列表 -->
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra">
|
||||
<!-- head -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>微信Id</th>
|
||||
<th>微信号</th>
|
||||
<th>昵称</th>
|
||||
<th>最后活跃时间</th>
|
||||
<th>是否在通讯录</th>
|
||||
<th>是否启用AI</th>
|
||||
<th>是否启用水群排行榜</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .friends }}
|
||||
<tr>
|
||||
<td>{{ .Wxid }}</td>
|
||||
<td>{{ .CustomAccount }}</td>
|
||||
<td>{{ .Nickname }}</td>
|
||||
<td>
|
||||
{{ if eq .LastActiveTime.IsNil true }}
|
||||
无数据
|
||||
{{ else }}
|
||||
{{ .LastActiveTime }}
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>{{ .IsOk }}</td>
|
||||
<td>{{ .EnableAi }}</td>
|
||||
<td>{{ .EnableChatRank }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<table class="table table-zebra">
|
||||
<!-- head -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>微信Id</th>
|
||||
<th>微信号</th>
|
||||
<th>昵称</th>
|
||||
<th>最后活跃时间</th>
|
||||
<th>是否在通讯录</th>
|
||||
<th>是否启用AI</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .friends }}
|
||||
<tr>
|
||||
<td>{{ .Wxid }}</td>
|
||||
<td>{{ .CustomAccount }}</td>
|
||||
<td>{{ .Nickname }}</td>
|
||||
<td>
|
||||
{{ if eq .LastActiveTime.IsNil true }}
|
||||
无数据
|
||||
{{ else }}
|
||||
{{ .LastActiveTime }}
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>
|
||||
{{ if eq .IsOk true }}
|
||||
<div class="badge badge-info gap-2">
|
||||
是
|
||||
</div>
|
||||
{{ else }}
|
||||
<div class="badge badge-error gap-2">
|
||||
否
|
||||
</div>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>
|
||||
<label class="swap swap-flip {{ checkSwap .EnableAi }}">
|
||||
<input type="checkbox" onclick="changeAiEnableStatus({{.Wxid}})"/>
|
||||
|
||||
<div class="swap-on">✔️已启用</div>
|
||||
<div class="swap-off">❌已禁用</div>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse collapse-arrow bg-base-200">
|
||||
<input type="radio" name="my-accordion-2" />
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
群列表
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
|
||||
<input type="radio" name="friend_tab" role="tab" class="tab" aria-label="群列表" />
|
||||
<div role="tabpanel" class="tab-content p-6">
|
||||
<!-- 循环群列表 -->
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra">
|
||||
<!-- head -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>群Id</th>
|
||||
<th>昵称</th>
|
||||
<th>最后活跃时间</th>
|
||||
<th>是否在通讯录</th>
|
||||
<th>是否启用AI</th>
|
||||
<th>是否启用水群排行榜</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .groups }}
|
||||
<tr>
|
||||
<td>{{ .Wxid }}</td>
|
||||
<td>{{ .Nickname }}</td>
|
||||
<td>
|
||||
{{ if eq .LastActiveTime.IsNil true }}
|
||||
无数据
|
||||
{{ else }}
|
||||
{{ .LastActiveTime }}
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>{{ .IsOk }}</td>
|
||||
<td>{{ .EnableAi }}</td>
|
||||
<td>{{ .EnableChatRank }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<table class="table table-zebra">
|
||||
<!-- head -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>群Id</th>
|
||||
<th>昵称</th>
|
||||
<th>最后活跃时间</th>
|
||||
<th>是否在通讯录</th>
|
||||
<th>是否启用AI</th>
|
||||
<th>是否启用水群排行榜</th>
|
||||
<th>是否启用迎新</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .groups }}
|
||||
<tr>
|
||||
<td>{{ .Wxid }}</td>
|
||||
<td>{{ .Nickname }}</td>
|
||||
<td>
|
||||
{{ if eq .LastActiveTime.IsNil true }}
|
||||
无数据
|
||||
{{ else }}
|
||||
{{ .LastActiveTime }}
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>
|
||||
{{ if eq .IsOk true }}
|
||||
<div class="badge badge-info gap-2">
|
||||
是
|
||||
</div>
|
||||
{{ else }}
|
||||
<div class="badge badge-error gap-2">
|
||||
否
|
||||
</div>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td>
|
||||
<!-- EnableAi -->
|
||||
<label class="swap swap-flip {{ checkSwap .EnableAi }}">
|
||||
<input type="checkbox" onclick="changeAiEnableStatus({{.Wxid}})"/>
|
||||
|
||||
<div class="swap-on">✔️已启用</div>
|
||||
<div class="swap-off">❌已禁用</div>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<!-- EnableChatRank -->
|
||||
<label class="swap swap-flip {{ checkSwap .EnableChatRank }}">
|
||||
<input type="checkbox" onclick="changeGroupRankEnableStatus({{.Wxid}})"/>
|
||||
|
||||
<div class="swap-on">✔️已启用</div>
|
||||
<div class="swap-off">❌已禁用</div>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<label class="swap swap-flip {{ checkSwap .EnableWelcome }}">
|
||||
<input type="checkbox" onclick="changeWelcomeEnableStatus({{.Wxid}})"/>
|
||||
|
||||
<div class="swap-on">✔️已启用</div>
|
||||
<div class="swap-off">❌已禁用</div>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-link" onclick="getGroupUsers({{.Wxid}}, {{.Nickname}})">查看群成员</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<dialog id="groupUserModal" class="modal">
|
||||
<div class="modal-box w-11/12 max-w-7xl">
|
||||
<!-- <form method="dialog">-->
|
||||
<!-- <button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>-->
|
||||
<!-- </form>-->
|
||||
<h3 class="font-bold text-lg" id="groupUserModalName">我是群名称</h3>
|
||||
<!-- 加载动画 -->
|
||||
|
||||
|
||||
<div class="divider divider-warning">成员列表</div>
|
||||
<!-- 好友列表 -->
|
||||
<table class="table table-zebra">
|
||||
<!-- head -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>微信Id</th>
|
||||
<th>昵称</th>
|
||||
<th>是否群成员</th>
|
||||
<th>加群时间</th>
|
||||
<th>最后活跃时间</th>
|
||||
<th>退群时间</th>
|
||||
<th>是否跳过水群排行榜</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="groupUsers"></tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
</dialog>
|
||||
</body>
|
||||
</html>
|
||||
20
views/static/css/daisyui-4.4.14-full.min.css
vendored
Normal file
20
views/static/css/daisyui-4.4.14-full.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
4
views/static/css/index.css
Normal file
4
views/static/css/index.css
Normal file
@@ -0,0 +1,4 @@
|
||||
/* 隐藏滚动条 */
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
@@ -1 +1,143 @@
|
||||
console.log("打开首页")
|
||||
console.log("打开首页")
|
||||
|
||||
// 改变AI开启状态
|
||||
function changeAiEnableStatus(wxId) {
|
||||
// console.log("修改AI开启状态: ", wxId)
|
||||
|
||||
axios({
|
||||
method: 'put',
|
||||
url: '/api/ai/status',
|
||||
data: {
|
||||
wxId: wxId
|
||||
}
|
||||
}).then(function (response) {
|
||||
console.log(`返回结果: ${JSON.stringify(response)}`);
|
||||
}).catch(function (error) {
|
||||
console.log(`错误信息: ${error}`);
|
||||
alert("修改失败")
|
||||
})
|
||||
}
|
||||
|
||||
// 修改水群排行榜状态
|
||||
function changeGroupRankEnableStatus(wxId) {
|
||||
// console.log("修改水群排行榜开启状态: ", wxId)
|
||||
axios({
|
||||
method: 'put',
|
||||
url: '/api/grouprank/status',
|
||||
data: {
|
||||
wxId: wxId
|
||||
}
|
||||
}).then(function (response) {
|
||||
console.log(`返回结果: ${JSON.stringify(response)}`);
|
||||
}).catch(function (error) {
|
||||
console.log(`错误信息: ${error}`);
|
||||
alert("修改失败")
|
||||
})
|
||||
}
|
||||
|
||||
// 修改欢迎语开启状态
|
||||
function changeWelcomeEnableStatus(wxId) {
|
||||
axios({
|
||||
method: 'put',
|
||||
url: '/api/welcome/status',
|
||||
data: {
|
||||
wxId: wxId
|
||||
}
|
||||
}).then(function (response) {
|
||||
console.log(`返回结果: ${JSON.stringify(response)}`);
|
||||
}).catch(function (error) {
|
||||
console.log(`错误信息: ${error}`);
|
||||
alert("修改失败")
|
||||
})
|
||||
}
|
||||
|
||||
// 修改群成员是否参与排行榜状态
|
||||
function changeUserGroupRankSkipStatus(groupId, userId) {
|
||||
console.log("修改水群排行榜开启状态: ", groupId, userId)
|
||||
axios({
|
||||
method: 'put',
|
||||
url: '/api/grouprank/skip',
|
||||
data: {
|
||||
wxId: groupId,
|
||||
userId: userId
|
||||
}
|
||||
}).then(function (response) {
|
||||
console.log(`返回结果: ${JSON.stringify(response)}`);
|
||||
}).catch(function (error) {
|
||||
console.log(`错误信息: ${error}`);
|
||||
alert("修改失败")
|
||||
})
|
||||
}
|
||||
|
||||
// 获取群成员列表
|
||||
function getGroupUsers(groupId, groupName) {
|
||||
// 获取表格的tbody部分,以便稍后向其中添加行
|
||||
var tbody = document.getElementById("groupUsers");
|
||||
tbody.innerHTML = ""
|
||||
|
||||
// 打开模态框
|
||||
const modal = document.getElementById("groupUserModal");
|
||||
modal.showModal()
|
||||
|
||||
// 设置群名称
|
||||
const groupNameTag = document.getElementById("groupUserModalName");
|
||||
groupNameTag.innerHTML = '<span class="loading loading-dots loading-lg"></span>'
|
||||
|
||||
// 显示加载框
|
||||
// const loading = document.getElementById("groupUserDataLoading");
|
||||
// loading.style.display = "block"
|
||||
|
||||
axios.get('/api/group/users', {
|
||||
params: {
|
||||
groupId: groupId
|
||||
}
|
||||
}).then(function (response) {
|
||||
// console.log(`返回结果: ${JSON.stringify(response)}`);
|
||||
// 渲染群成员列表
|
||||
const groupUsers = response.data
|
||||
// 循环渲染数据
|
||||
for (let i = 0; i < groupUsers.length; i++) {
|
||||
const groupUser = groupUsers[i]
|
||||
|
||||
let row = tbody.insertRow(i); // 插入新行
|
||||
|
||||
// 微信Id
|
||||
let wxId = row.insertCell(0);
|
||||
wxId.innerHTML = groupUser.wxid;
|
||||
|
||||
// 昵称
|
||||
let nickname = row.insertCell(1);
|
||||
nickname.innerHTML = groupUser.nickname;
|
||||
|
||||
// 是否群成员
|
||||
let isMember = row.insertCell(2);
|
||||
if (groupUser.isMember) {
|
||||
isMember.innerHTML = '<div class="badge badge-info gap-2">是</div>';
|
||||
} else {
|
||||
isMember.innerHTML = '<div class="badge badge-error gap-2">否</div>';
|
||||
}
|
||||
|
||||
// 加群时间
|
||||
let joinTime = row.insertCell(3);
|
||||
joinTime.innerHTML = groupUser.joinTime;
|
||||
|
||||
// 最后活跃时间
|
||||
let lastActiveTime = row.insertCell(4);
|
||||
lastActiveTime.innerHTML = groupUser.lastActiveTime;
|
||||
|
||||
// 退群时间
|
||||
let leaveTime = row.insertCell(5);
|
||||
leaveTime.innerHTML = groupUser.leaveTime;
|
||||
|
||||
// 是否跳过水群排行榜
|
||||
let skipChatRank = row.insertCell(6);
|
||||
skipChatRank.innerHTML = `<input type="checkbox" class="toggle toggle-error" ${groupUser.skipChatRank ? 'checked' : ''} onclick="changeUserGroupRankSkipStatus(\'${groupId}\', \'${groupUser.wxid}\')" />`;
|
||||
}
|
||||
}).catch(function (error) {
|
||||
console.log(`错误信息: ${error}`);
|
||||
}).finally(function () {
|
||||
// 隐藏加载框
|
||||
// loading.style.display = "none"
|
||||
groupNameTag.innerHTML = groupName
|
||||
})
|
||||
}
|
||||
15
vo/friend.go
15
vo/friend.go
@@ -14,6 +14,21 @@ type FriendItem struct {
|
||||
Wxid string // 微信原始Id
|
||||
EnableAi bool // 是否使用AI
|
||||
EnableChatRank bool // 是否使用聊天排行
|
||||
EnableWelcome bool // 是否使用迎新
|
||||
IsOk bool // 是否还在通讯库(群聊是要还在群里也算)
|
||||
LastActiveTime types.DateTime // 最后活跃时间
|
||||
}
|
||||
|
||||
// GroupUserItem
|
||||
// @description: 群成员列表数据
|
||||
type GroupUserItem struct {
|
||||
Wxid string `json:"wxid"` // 微信Id
|
||||
Account string `json:"account"` // 账号
|
||||
HeadImage string `json:"headImage"` // 头像
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
IsMember bool `json:"isMember" ` // 是否群成员
|
||||
JoinTime types.DateTime `json:"joinTime"` // 加入时间
|
||||
LastActiveTime types.DateTime `json:"lastActiveTime"` // 最后活跃时间
|
||||
LeaveTime types.DateTime `json:"leaveTime"` // 离开时间
|
||||
SkipChatRank bool `json:"skipChatRank" ` // 是否跳过聊天排行
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user