Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccb0216484 | ||
|
|
37bf8de132 | ||
|
|
63d50b815c | ||
|
|
81be5a0f70 | ||
|
|
89c504d019 | ||
|
|
14d407eff1 | ||
|
|
d4fcfda112 | ||
|
|
ce11fd40c4 | ||
|
|
454b5f0980 | ||
|
|
2af0719f51 | ||
|
|
699f10e854 | ||
|
|
0430c2203e | ||
|
|
917e96b332 | ||
|
|
e80fe2a7a0 | ||
|
|
dc8a7e7118 | ||
|
|
ac589d2a4c | ||
|
|
6a259b0552 | ||
|
|
6626f45af2 | ||
|
|
4b5d074517 | ||
|
|
e3bb115560 | ||
|
|
3b4862d5bc | ||
|
|
997ad806f0 | ||
|
|
86435e9707 | ||
|
|
b4470b0888 | ||
|
|
500e241f8d | ||
|
|
6c2bf3fc9c | ||
|
|
91d2fc50e2 | ||
|
|
119c2a5359 | ||
|
|
06a64c5e5a |
10
Dockerfile
10
Dockerfile
@@ -6,14 +6,16 @@ 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"
|
||||
|
||||
EXPOSE 19099
|
||||
EXPOSE 8080
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /builder/app ./app
|
||||
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)
|
||||
}
|
||||
26
app/index.go
Normal file
26
app/index.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-wechat/service"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Index
|
||||
// @description: 首页
|
||||
// @param ctx
|
||||
func Index(ctx *gin.Context) {
|
||||
var result = gin.H{
|
||||
"msg": "success",
|
||||
}
|
||||
// 取出所有好友列表
|
||||
friends, groups, err := service.GetAllFriend()
|
||||
if err != nil {
|
||||
result["msg"] = fmt.Sprintf("数据获取失败: %s", err.Error())
|
||||
}
|
||||
result["friends"] = friends
|
||||
result["groups"] = groups
|
||||
// 渲染页面
|
||||
ctx.HTML(http.StatusOK, "index.html", result)
|
||||
}
|
||||
19
common/current/robot.go
Normal file
19
common/current/robot.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package current
|
||||
|
||||
import "go-wechat/model"
|
||||
|
||||
var robotInfo model.RobotUserInfo
|
||||
|
||||
// SetRobotInfo
|
||||
// @description: 设置机器人信息
|
||||
// @param info
|
||||
func SetRobotInfo(info model.RobotUserInfo) {
|
||||
robotInfo = info
|
||||
}
|
||||
|
||||
// GetRobotInfo
|
||||
// @description: 获取机器人信息
|
||||
// @return model.RobotUserInfo
|
||||
func GetRobotInfo() model.RobotUserInfo {
|
||||
return robotInfo
|
||||
}
|
||||
156
common/types/datetime.go
Normal file
156
common/types/datetime.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 默认时间格式
|
||||
const dateTimeFormat = "2006-01-02 15:04:05.000"
|
||||
|
||||
// 可能包含的时间格式
|
||||
var formatMap = map[string]string{
|
||||
"yyyy-mm-dd hh:mm:ss": "2006-01-02 15:04:05",
|
||||
"yyyy-mm-dd hh:mm": "2006-01-02 15:04",
|
||||
"yyyy-mm-dd hh": "2006-01-02 15:04",
|
||||
"yyyy-mm-dd": "2006-01-02",
|
||||
"yyyy-mm": "2006-01",
|
||||
"mm-dd": "01-02",
|
||||
"dd-mm-yy hh:mm:ss": "02-01-06 15:04:05",
|
||||
"yyyy/mm/dd hh:mm:ss": "2006/01/02 15:04:05",
|
||||
"yyyy/mm/dd hh:mm": "2006/01/02 15:04",
|
||||
"yyyy/mm/dd hh": "2006/01/02 15",
|
||||
"yyyy/mm/dd": "2006/01/02",
|
||||
"yyyy/mm": "2006/01",
|
||||
"mm/dd": "01/02",
|
||||
"dd/mm/yy hh:mm:ss": "02/01/06 15:04:05",
|
||||
"yyyy": "2006",
|
||||
"mm": "01",
|
||||
"hh:mm:ss": "15:04:05",
|
||||
"mm:ss": "04:05",
|
||||
}
|
||||
|
||||
// DateTime 自定义时间类型
|
||||
type DateTime time.Time
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (dt *DateTime) Scan(value interface{}) error {
|
||||
// mysql 内部日期的格式可能是 2006-01-02 15:04:05 +0800 CST 格式,所以检出的时候还需要进行一次格式化
|
||||
tTime, _ := time.Parse("2006-01-02 15:04:05 +0800 CST", value.(time.Time).String())
|
||||
*dt = DateTime(tTime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (dt DateTime) Value() (dv driver.Value, err error) {
|
||||
// 0001-01-01 00:00:00 属于空值,遇到空值解析成 null 即可
|
||||
if dt.String() == "0001-01-01 00:00:00.000" {
|
||||
return nil, nil
|
||||
}
|
||||
dv, err = []byte(dt.Format(dateTimeFormat)), nil
|
||||
return
|
||||
}
|
||||
|
||||
// 用于 fmt.Println 和后续验证场景
|
||||
func (dt DateTime) String() string {
|
||||
return dt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// Format 格式化
|
||||
func (dt *DateTime) Format(fm string) string {
|
||||
return time.Time(*dt).Format(fm)
|
||||
}
|
||||
|
||||
// AutoParse 假装是个自动解析时间的函数
|
||||
func (dt DateTime) AutoParse(timeStr string) (t time.Time, err error) {
|
||||
// 循环匹配预设的时间格式
|
||||
for _, v := range formatMap {
|
||||
// 尝试解析,没报错就是解析成功了
|
||||
t, err = time.ParseInLocation(v, timeStr, time.Local)
|
||||
if err == nil {
|
||||
// 错误为空,表示匹配上了
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// After 时间比较
|
||||
func (dt *DateTime) After(now time.Time) bool {
|
||||
return time.Time(*dt).After(now)
|
||||
}
|
||||
|
||||
// Before 时间比较
|
||||
func (dt *DateTime) Before(now time.Time) bool {
|
||||
return time.Time(*dt).Before(now)
|
||||
}
|
||||
|
||||
// IBefore 时间比较
|
||||
func (dt *DateTime) IBefore(now DateTime) bool {
|
||||
return dt.Before(time.Time(now))
|
||||
}
|
||||
|
||||
// SubTime 对比
|
||||
func (dt DateTime) SubTime(t time.Time) time.Duration {
|
||||
return dt.ToTime().Sub(t)
|
||||
}
|
||||
|
||||
// Sub 对比
|
||||
func (dt DateTime) Sub(t DateTime) time.Duration {
|
||||
return dt.ToTime().Sub(t.ToTime())
|
||||
}
|
||||
|
||||
// ToTime 转换为golang的时间类型
|
||||
func (dt DateTime) ToTime() time.Time {
|
||||
return time.Time(dt)
|
||||
}
|
||||
|
||||
// IsNil 是否为空值
|
||||
func (dt DateTime) IsNil() bool {
|
||||
return dt.Format(dateTimeFormat) == "0001-01-01 00:00:00.000"
|
||||
}
|
||||
|
||||
// Unix 实现Unix函数
|
||||
func (dt DateTime) Unix() int64 {
|
||||
return dt.ToTime().Unix()
|
||||
}
|
||||
|
||||
// EndOfCentury 获取本世纪最后时间
|
||||
func (dt DateTime) EndOfCentury() DateTime {
|
||||
yearEnd := time.Now().Local().Year()/100*100 + 99
|
||||
return DateTime(time.Date(yearEnd, 12, 31, 23, 59, 59, 999999999, time.Local))
|
||||
}
|
||||
|
||||
// ======== 序列化 JSON ========
|
||||
|
||||
// MarshalJSON 时间到字符串
|
||||
func (dt DateTime) MarshalJSON() ([]byte, error) {
|
||||
// 过滤掉空数据
|
||||
if dt.IsNil() {
|
||||
return []byte("\"\""), nil
|
||||
}
|
||||
output := fmt.Sprintf(`"%s"`, dt.Format("2006-01-02 15:04:05"))
|
||||
return []byte(output), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON 字符串到时间
|
||||
func (dt *DateTime) UnmarshalJSON(b []byte) (err error) {
|
||||
if len(b) == 2 {
|
||||
*dt = DateTime{}
|
||||
return
|
||||
}
|
||||
// 解析指定的格式
|
||||
var now time.Time
|
||||
if strings.HasPrefix(string(b), "\"") {
|
||||
now, err = dt.AutoParse(string(b)[1 : len(b)-1])
|
||||
} else {
|
||||
now, err = dt.AutoParse(string(b))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
*dt = DateTime(now)
|
||||
return
|
||||
}
|
||||
30
config.yaml
30
config.yaml
@@ -6,6 +6,9 @@ wechat:
|
||||
autoSetCallback: false
|
||||
# 回调IP,如果是Docker运行,本参数必填,如果Docker修改了映射,格式为 ip:port
|
||||
callback: 10.0.0.51
|
||||
# 转发到其他地址
|
||||
forward:
|
||||
- 10.0.0.247:4299
|
||||
|
||||
# 数据库
|
||||
mysql:
|
||||
@@ -16,26 +19,33 @@ mysql:
|
||||
db: wechat
|
||||
|
||||
task:
|
||||
enable: true
|
||||
enable: false
|
||||
syncFriends:
|
||||
enable: true
|
||||
cron: '*/5 * * * *' # 五分钟一次
|
||||
waterGroup:
|
||||
enable: false
|
||||
cron: '30 9 * * *'
|
||||
# 需要发送水群排行榜的群Id
|
||||
groups:
|
||||
- '18958257758@chatroom'
|
||||
- '49448748645@chatroom'
|
||||
# 不计入统计范围的用户Id
|
||||
blacklist:
|
||||
- 'wxid_7788687886912'
|
||||
cron:
|
||||
yesterday: '30 9 * * *' # 每天9:30
|
||||
week: '30 9 * * 1' # 每周一9:30
|
||||
month: '30 9 1 * *' # 每月1号9:30
|
||||
|
||||
# AI回复
|
||||
ai:
|
||||
# 是否启用
|
||||
enable: false
|
||||
# 模型,不填默认gpt-3.5-turbo-0613
|
||||
model: gpt-3.5-turbo-0613
|
||||
# OpenAI Api key
|
||||
apiKey: sk-xxxx
|
||||
# 接口代理域名,不填默认ChatGPT官方地址
|
||||
baseUrl: https://sxxx
|
||||
baseUrl: https://sxxx
|
||||
# 人设
|
||||
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
|
||||
|
||||
# 资源配置
|
||||
resource:
|
||||
# 欢迎新成员表情包
|
||||
welcomeNew:
|
||||
type: emotion
|
||||
path: 58e4150be2bba8f7b71974b10391f9e9
|
||||
|
||||
@@ -3,7 +3,9 @@ package config
|
||||
// ai
|
||||
// @description: AI配置
|
||||
type ai struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用AI
|
||||
ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key
|
||||
BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用AI
|
||||
Model string `json:"model" yaml:"model"` // 模型
|
||||
ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key
|
||||
BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址
|
||||
Personality string `json:"personality" yaml:"personality"` // 人设
|
||||
}
|
||||
|
||||
@@ -5,24 +5,9 @@ var Conf Config
|
||||
// Config
|
||||
// @description: 配置
|
||||
type Config struct {
|
||||
Task task `json:"task" yaml:"task"` // 定时任务配置
|
||||
MySQL mysql `json:"mysql" yaml:"mysql"` // MySQL 配置
|
||||
Wechat wechat `json:"wechat" yaml:"wechat"` // 微信助手
|
||||
Ai ai `json:"ai" yaml:"ai"` // AI配置
|
||||
}
|
||||
|
||||
// task
|
||||
// @description: 定时任务
|
||||
type task struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
SyncFriends struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
Cron string `json:"cron" yaml:"cron"` // 定时任务表达式
|
||||
} `json:"syncFriends" yaml:"syncFriends"` // 同步好友
|
||||
WaterGroup struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
Cron string `json:"cron" yaml:"cron"` // 定时任务表达式
|
||||
Groups []string `json:"groups" yaml:"groups"` // 启用的群Id
|
||||
Blacklist []string `json:"blacklist" yaml:"blacklist"` // 黑名单
|
||||
} `json:"waterGroup" yaml:"waterGroup"` // 水群排行榜
|
||||
Task task `json:"task" yaml:"task"` // 定时任务配置
|
||||
MySQL mysql `json:"mysql" yaml:"mysql"` // MySQL 配置
|
||||
Wechat wechat `json:"wechat" yaml:"wechat"` // 微信助手
|
||||
Ai ai `json:"ai" yaml:"ai"` // AI配置
|
||||
Resource map[string]resourceItem `json:"resource" yaml:"resource"` // 资源配置
|
||||
}
|
||||
|
||||
8
config/resource.go
Normal file
8
config/resource.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
// resourceItem
|
||||
// @description: 资源项
|
||||
type resourceItem struct {
|
||||
Type string `json:"type" yaml:"type"` // 类型
|
||||
Path string `json:"path" yaml:"path"` // 路径
|
||||
}
|
||||
31
config/task.go
Normal file
31
config/task.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
// task
|
||||
// @description: 定时任务
|
||||
type task struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
SyncFriends syncFriends `json:"syncFriends" yaml:"syncFriends"` // 同步好友
|
||||
WaterGroup waterGroup `json:"waterGroup" yaml:"waterGroup"` // 水群排行榜
|
||||
}
|
||||
|
||||
// syncFriends
|
||||
// @description: 同步好友
|
||||
type syncFriends struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
Cron string `json:"cron" yaml:"cron"` // 定时任务表达式
|
||||
}
|
||||
|
||||
// waterGroup
|
||||
// @description: 水群排行榜
|
||||
type waterGroup struct {
|
||||
Enable bool `json:"enable" yaml:"enable"` // 是否启用
|
||||
Cron waterGroupCron `json:"cron" yaml:"cron"` // 定时任务表达式
|
||||
}
|
||||
|
||||
// waterGroupCron
|
||||
// @description: 水群排行榜定时任务
|
||||
type waterGroupCron struct {
|
||||
Yesterday string `json:"yesterday" yaml:"yesterday"` // 昨日排行榜
|
||||
Week string `json:"week" yaml:"week"` // 周排行榜
|
||||
Month string `json:"month" yaml:"month"` // 月排行榜
|
||||
}
|
||||
@@ -5,9 +5,10 @@ import "strings"
|
||||
// wxHelper
|
||||
// @description: 微信助手
|
||||
type wechat struct {
|
||||
Host string `json:"host" yaml:"host"` // 接口地址
|
||||
AutoSetCallback bool `json:"autoSetCallback" yaml:"autoSetCallback"` // 是否自动设置回调地址
|
||||
Callback string `json:"callback" yaml:"callback"` // 回调地址
|
||||
Host string `json:"host" yaml:"host"` // 接口地址
|
||||
AutoSetCallback bool `json:"autoSetCallback" yaml:"autoSetCallback"` // 是否自动设置回调地址
|
||||
Callback string `json:"callback" yaml:"callback"` // 回调地址
|
||||
Forward []string `json:"forward" yaml:"forward"` // 转发地址
|
||||
}
|
||||
|
||||
// Check
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Friend
|
||||
// @description: 好友列表
|
||||
type Friend struct {
|
||||
CustomAccount string `json:"customAccount"` // 微信号
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Pinyin string `json:"pinyin"` // 昵称拼音大写首字母
|
||||
PinyinAll string `json:"pinyinAll"` // 昵称全拼
|
||||
Wxid string `json:"wxid"` // 微信原始Id
|
||||
Wxid string `json:"wxid"` // 微信原始Id
|
||||
CustomAccount string `json:"customAccount"` // 微信号
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Pinyin string `json:"pinyin"` // 昵称拼音大写首字母
|
||||
PinyinAll string `json:"pinyinAll"` // 昵称全拼
|
||||
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"` // 是否正常
|
||||
}
|
||||
|
||||
func (Friend) TableName() string {
|
||||
@@ -19,13 +25,15 @@ func (Friend) TableName() string {
|
||||
// GroupUser
|
||||
// @description: 群成员
|
||||
type GroupUser struct {
|
||||
GroupId string `json:"groupId"` // 群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)"` // 是否群成员
|
||||
LeaveTime *time.Time `json:"leaveTime"` // 离开时间
|
||||
GroupId string `json:"groupId"` // 群Id
|
||||
Wxid string `json:"wxid"` // 微信Id
|
||||
Account string `json:"account"` // 账号
|
||||
HeadImage string `json:"headImage"` // 头像
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
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"` // 是否跳过聊天排行
|
||||
}
|
||||
|
||||
func (GroupUser) TableName() string {
|
||||
|
||||
20
go.mod
20
go.mod
@@ -5,6 +5,7 @@ go 1.21
|
||||
require (
|
||||
github.com/duke-git/lancet/v2 v2.2.7
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-co-op/gocron v1.34.1
|
||||
github.com/go-resty/resty/v2 v2.8.0
|
||||
github.com/sashabaranov/go-openai v1.17.5
|
||||
@@ -14,13 +15,27 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.9.1 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sagikazarmark/locafero v0.3.0 // indirect
|
||||
@@ -30,12 +45,17 @@ require (
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/crypto v0.13.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/net v0.15.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
54
go.sum
54
go.sum
@@ -38,7 +38,13 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
||||
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
@@ -63,15 +69,31 @@ github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0X
|
||||
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||
github.com/go-co-op/gocron v1.34.1 h1:g4Y1ePFin2z4Rbb5gTHNYfj36moY4kU9s0ZmGy/ZddQ=
|
||||
github.com/go-co-op/gocron v1.34.1/go.mod h1:NLi+bkm4rRSy1F8U7iacZOz0xPseMoIOnvabGoSe/no=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
|
||||
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-resty/resty/v2 v2.8.0 h1:J29d0JFWwSWrDCysnOK/YjsPMLQTx0TvgJEHVGvf2L8=
|
||||
github.com/go-resty/resty/v2 v2.8.0/go.mod h1:UCui0cMHekLrSntoMyofdSTaPpinlRHFtPpizuyDW2w=
|
||||
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
@@ -97,6 +119,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -108,8 +131,10 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
@@ -140,9 +165,14 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
@@ -153,10 +183,19 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
@@ -198,11 +237,16 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
@@ -218,6 +262,9 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@@ -226,6 +273,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
@@ -358,9 +406,11 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -525,6 +575,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
@@ -549,5 +602,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
|
||||
@@ -2,39 +2,82 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"go-wechat/client"
|
||||
"go-wechat/config"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/model"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// handleAtMessage
|
||||
// @description: 处理At机器人的消息
|
||||
// @param m
|
||||
func handleAtMessage(m entity.Message) {
|
||||
func handleAtMessage(m model.Message) {
|
||||
if !config.Conf.Ai.Enable {
|
||||
return
|
||||
}
|
||||
|
||||
// 取出所有启用了AI的好友或群组
|
||||
var count int64
|
||||
client.MySQL.Model(&entity.Friend{}).Where("enable_ai IS TRUE").Where("wxid = ?", m.FromUser).Count(&count)
|
||||
if count < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// 预处理一下发送的消息,用正则去掉@机器人的内容
|
||||
re := regexp.MustCompile(`@([^ ]+)`)
|
||||
matches := re.FindStringSubmatch(m.Content)
|
||||
if len(matches) > 0 {
|
||||
// 过滤掉第一个匹配到的
|
||||
m.Content = strings.Replace(m.Content, matches[0], "", 1)
|
||||
}
|
||||
|
||||
// 组装消息体
|
||||
messages := make([]openai.ChatCompletionMessage, 0)
|
||||
if config.Conf.Ai.Personality != "" {
|
||||
// 填充人设
|
||||
messages = append(messages, openai.ChatCompletionMessage{
|
||||
Role: openai.ChatMessageRoleSystem,
|
||||
Content: config.Conf.Ai.Personality,
|
||||
})
|
||||
}
|
||||
// 填充用户消息
|
||||
messages = append(messages, openai.ChatCompletionMessage{
|
||||
Role: openai.ChatMessageRoleUser,
|
||||
Content: m.Content,
|
||||
})
|
||||
|
||||
// 配置模型
|
||||
chatModel := openai.GPT3Dot5Turbo0613
|
||||
if config.Conf.Ai.Model != "" {
|
||||
chatModel = config.Conf.Ai.Model
|
||||
}
|
||||
|
||||
// 默认使用AI回复
|
||||
client := openai.NewClient(config.Conf.Ai.ApiKey)
|
||||
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
|
||||
if config.Conf.Ai.BaseUrl != "" {
|
||||
conf.BaseURL = fmt.Sprintf("%s/v1", config.Conf.Ai.BaseUrl)
|
||||
}
|
||||
client := openai.NewClientWithConfig(conf)
|
||||
resp, err := client.CreateChatCompletion(
|
||||
context.Background(),
|
||||
openai.ChatCompletionRequest{
|
||||
Model: openai.GPT3Dot5Turbo0613,
|
||||
Messages: []openai.ChatCompletionMessage{
|
||||
{
|
||||
Role: openai.ChatMessageRoleUser,
|
||||
Content: m.Content,
|
||||
},
|
||||
},
|
||||
Model: chatModel,
|
||||
Messages: messages,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("OpenAI聊天发起失败: %v", err.Error())
|
||||
utils.SendMessage(m.FromUser, m.GroupUser, "AI炸啦~", 0)
|
||||
return
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
utils.SendMessage(m.FromUser, m.GroupUser, resp.Choices[0].Message.Content, 0)
|
||||
utils.SendMessage(m.FromUser, m.GroupUser, "\n"+resp.Choices[0].Message.Content, 0)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"go-wechat/model"
|
||||
"go-wechat/service"
|
||||
"go-wechat/types"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -23,43 +24,48 @@ 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() {
|
||||
log.Printf("%s -> 开始迎新 -> %s", m.FromUser, m.Content)
|
||||
// 欢迎新成员
|
||||
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,47 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"go-wechat/client"
|
||||
"go-wechat/config"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/model"
|
||||
"go-wechat/utils"
|
||||
"strings"
|
||||
"log"
|
||||
)
|
||||
|
||||
// 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
|
||||
err := client.MySQL.Model(&entity.Friend{}).
|
||||
Where("enable_welcome IS TRUE").
|
||||
Where("wxid = ?", m.FromUser).
|
||||
Count(&count).Error
|
||||
if err != nil {
|
||||
log.Printf("查询是否开启迎新失败: %s", err.Error())
|
||||
return
|
||||
}
|
||||
if count < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// 读取欢迎新成员配置
|
||||
conf, ok := config.Conf.Resource["welcomeNew"]
|
||||
if !ok {
|
||||
// 未配置,跳过
|
||||
return
|
||||
}
|
||||
switch conf.Type {
|
||||
case "text":
|
||||
// 文字类型
|
||||
utils.SendMessage(m.FromUser, "", conf.Path, 0)
|
||||
case "image":
|
||||
// 图片类型
|
||||
utils.SendImage(m.FromUser, conf.Path, 0)
|
||||
case "emotion":
|
||||
// 表情类型
|
||||
utils.SendEmotion(m.FromUser, conf.Path, 0)
|
||||
}
|
||||
}
|
||||
|
||||
31
initialization/wechat.go
Normal file
31
initialization/wechat.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package initialization
|
||||
|
||||
import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go-wechat/common/current"
|
||||
"go-wechat/config"
|
||||
"go-wechat/model"
|
||||
"log"
|
||||
)
|
||||
|
||||
// InitWechatRobotInfo
|
||||
// @description: 初始化微信机器人信息
|
||||
func InitWechatRobotInfo() {
|
||||
// 获取数据
|
||||
var base model.Response[model.RobotUserInfo]
|
||||
_, err := resty.New().R().
|
||||
SetHeader("Content-Type", "application/json;chartset=utf-8").
|
||||
SetResult(&base).
|
||||
Post(config.Conf.Wechat.GetURL("/api/userInfo"))
|
||||
if err != nil {
|
||||
log.Printf("获取机器人信息失败: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("机器人Id: %s", base.Data.WxId)
|
||||
log.Printf("机器人微信号: %s", base.Data.Account)
|
||||
log.Printf("机器人名称: %s", base.Data.Name)
|
||||
|
||||
// 设置为单例
|
||||
current.SetRobotInfo(base.Data)
|
||||
}
|
||||
81
main.go
81
main.go
@@ -1,40 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-wechat/config"
|
||||
"go-wechat/handler"
|
||||
"go-wechat/initialization"
|
||||
"go-wechat/router"
|
||||
"go-wechat/tasks"
|
||||
"go-wechat/tcpserver"
|
||||
"go-wechat/utils"
|
||||
"io"
|
||||
"html/template"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
initialization.InitConfig()
|
||||
tasks.InitTasks()
|
||||
}
|
||||
|
||||
func process(conn net.Conn) {
|
||||
// 处理完关闭连接
|
||||
defer func() {
|
||||
log.Printf("处理完成: -> %s", conn.RemoteAddr())
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err := io.Copy(&buf, conn); err != nil {
|
||||
log.Printf("[%s]返回数据失败,错误信息: %v", conn.RemoteAddr(), err)
|
||||
}
|
||||
log.Printf("[%s]数据长度: %d", conn.RemoteAddr(), buf.Len())
|
||||
go handler.Parse(conn.RemoteAddr(), buf.Bytes())
|
||||
// 将接受到的数据返回给客户端
|
||||
if _, err := conn.Write([]byte("200 OK")); err != nil {
|
||||
log.Printf("[%s]返回数据失败,错误信息: %v", conn.RemoteAddr(), err)
|
||||
}
|
||||
initialization.InitConfig() // 初始化配置
|
||||
initialization.InitWechatRobotInfo() // 初始化机器人信息
|
||||
tasks.InitTasks() // 初始化定时任务
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -45,21 +29,40 @@ func main() {
|
||||
utils.SetCallback(config.Conf.Wechat.Callback)
|
||||
}
|
||||
|
||||
// 建立 tcp 服务
|
||||
listen, err := net.Listen("tcp", "0.0.0.0:19099")
|
||||
if err != nil {
|
||||
log.Printf("listen failed, err:%v", err)
|
||||
return
|
||||
}
|
||||
// 启动TCP服务
|
||||
go tcpserver.Start()
|
||||
|
||||
for {
|
||||
// 等待客户端建立连接
|
||||
conn, err := listen.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accept failed, err:%v", err)
|
||||
continue
|
||||
// 启动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/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
|
||||
}
|
||||
// 启动一个单独的 goroutine 去处理连接
|
||||
go process(conn)
|
||||
// 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 {
|
||||
log.Panicf("服务启动失败:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
model/userinfo.go
Normal file
18
model/userinfo.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// RobotUserInfo
|
||||
// @description: 机器人用户信息
|
||||
type RobotUserInfo struct {
|
||||
WxId string `json:"wxid"` // 微信Id
|
||||
Account string `json:"account"` // 微信号
|
||||
Name string `json:"name"` // 昵称
|
||||
HeadImage string `json:"headImage"` // 头像
|
||||
Mobile string `json:"mobile"` // 手机
|
||||
Signature string `json:"signature"` // 个人签名
|
||||
Country string `json:"country"` // 国家
|
||||
Province string `json:"province"` // 省
|
||||
City string `json:"city"` // 城市
|
||||
CurrentDataPath string `json:"currentDataPath"` // 当前数据目录,登录的账号目录
|
||||
DataSavePath string `json:"dataSavePath"` // 微信保存目录
|
||||
DbKey string `json:"dbKey"` // 数据库的SQLCipher的加密key,可以使用该key配合decrypt.py解密数据库
|
||||
}
|
||||
13
readme.md
13
readme.md
@@ -7,7 +7,7 @@ cd wechat-hook
|
||||
1. 创建配置文件`config.yaml`
|
||||
```shell
|
||||
mkdir config # 先创建一个文件夹保存配置文件,文件名不要变
|
||||
vim config.yaml # 编辑配置文件,内容如下
|
||||
vim config.yaml # 编辑配置文件,内容如下,最新配置请参考项目里的config.yaml文件
|
||||
```
|
||||
```yaml
|
||||
# 微信HOOK配置
|
||||
@@ -34,13 +34,10 @@ task:
|
||||
cron: '0 * * * *'
|
||||
waterGroup:
|
||||
enable: true
|
||||
cron: '30 9 * * *'
|
||||
# 需要发送水群排行榜的群Id
|
||||
groups:
|
||||
- '11111@chatroom' # 自行配置
|
||||
# 不计入统计范围的用户Id
|
||||
blacklist:
|
||||
- 'wxid_xxxx' # 自行配置
|
||||
cron:
|
||||
yesterday: '30 9 * * *' # 每天9:30
|
||||
week: '30 9 * * 1' # 每周一9:30
|
||||
month: '30 9 1 * *' # 每月1号9:30
|
||||
```
|
||||
|
||||
2. 创建`docker-compose.yaml`文件
|
||||
|
||||
29
router/router.go
Normal file
29
router/router.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-wechat/app"
|
||||
)
|
||||
|
||||
// Init
|
||||
// @description: 初始化路由
|
||||
// @param g
|
||||
func Init(g *gin.Engine) {
|
||||
g.GET("/", func(ctx *gin.Context) {
|
||||
// 重定向到index.html
|
||||
ctx.Redirect(302, "/index.html")
|
||||
})
|
||||
|
||||
g.GET("/index.html", app.Index) // 首页
|
||||
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) // 获取群成员列表
|
||||
}
|
||||
52
service/friend.go
Normal file
52
service/friend.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"go-wechat/client"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/vo"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetAllFriend
|
||||
// @description: 取出所有好友
|
||||
// @return friends
|
||||
// @return groups
|
||||
// @return err
|
||||
func GetAllFriend() (friends, groups []vo.FriendItem, err error) {
|
||||
var records []vo.FriendItem
|
||||
err = client.MySQL.
|
||||
Table("t_friend AS tf").
|
||||
Joins("LEFT JOIN t_message AS tm ON tf.wxid = tm.from_user").
|
||||
Select("tf.*", "MAX(tm.create_at) AS last_active_time").
|
||||
Group("tf.wxid").
|
||||
Order("last_active_time DESC").
|
||||
Find(&records).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, record := range records {
|
||||
if strings.HasSuffix(record.Wxid, "@chatroom") {
|
||||
groups = append(groups, record)
|
||||
} else {
|
||||
friends = append(friends, record)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllEnableAI
|
||||
// @description: 取出所有启用了AI的好友或群组
|
||||
// @return []entity.Friend
|
||||
func GetAllEnableAI() (records []entity.Friend, err error) {
|
||||
err = client.MySQL.Where("enable_ai = ?", 1).Find(&records).Error
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllEnableChatRank
|
||||
// @description: 取出所有启用了聊天排行榜的群组
|
||||
// @return records
|
||||
// @return err
|
||||
func GetAllEnableChatRank() (records []entity.Friend, err error) {
|
||||
err = client.MySQL.Where("enable_chat_rank = ?", 1).Where("wxid LIKE '%@chatroom'").Find(&records).Error
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package tasks
|
||||
package friends
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go-wechat/client"
|
||||
"go-wechat/common/constant"
|
||||
"go-wechat/config"
|
||||
"go-wechat/constant"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/model"
|
||||
"gorm.io/gorm"
|
||||
@@ -20,9 +20,9 @@ import (
|
||||
// http客户端
|
||||
var hc = resty.New()
|
||||
|
||||
// syncFriends
|
||||
// Sync
|
||||
// @description: 同步好友列表
|
||||
func syncFriends() {
|
||||
func Sync() {
|
||||
var base model.Response[[]model.FriendItem]
|
||||
|
||||
resp, err := hc.R().
|
||||
@@ -38,6 +38,8 @@ func syncFriends() {
|
||||
tx := client.MySQL.Begin()
|
||||
defer tx.Commit()
|
||||
|
||||
nowIds := []string{}
|
||||
|
||||
for _, friend := range base.Data {
|
||||
if strings.Contains(friend.Wxid, "gh_") || strings.Contains(friend.Wxid, "@openim") {
|
||||
continue
|
||||
@@ -47,6 +49,7 @@ func syncFriends() {
|
||||
continue
|
||||
}
|
||||
log.Printf("昵称: %s -> 类型: %d -> 微信号: %s -> 微信原始Id: %s", friend.Nickname, friend.Type, friend.CustomAccount, friend.Wxid)
|
||||
nowIds = append(nowIds, friend.Wxid)
|
||||
|
||||
// 判断是否存在,不存在的话就新增,存在就修改一下名字
|
||||
var count int64
|
||||
@@ -62,6 +65,7 @@ func syncFriends() {
|
||||
Pinyin: friend.Pinyin,
|
||||
PinyinAll: friend.PinyinAll,
|
||||
Wxid: friend.Wxid,
|
||||
IsOk: true,
|
||||
}).Error
|
||||
if err != nil {
|
||||
log.Printf("新增好友失败: %s", err.Error())
|
||||
@@ -87,6 +91,9 @@ func syncFriends() {
|
||||
}
|
||||
}
|
||||
|
||||
// 清理不在列表中的好友
|
||||
err = tx.Model(&entity.Friend{}).Where("wxid NOT IN (?)", nowIds).Update("is_ok", false).Error
|
||||
|
||||
log.Println("同步好友列表完成")
|
||||
}
|
||||
|
||||
@@ -148,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())
|
||||
@@ -3,6 +3,8 @@ package tasks
|
||||
import (
|
||||
"github.com/go-co-op/gocron"
|
||||
"go-wechat/config"
|
||||
"go-wechat/tasks/friends"
|
||||
"go-wechat/tasks/watergroup"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
@@ -20,14 +22,22 @@ func InitTasks() {
|
||||
|
||||
// 水群排行
|
||||
if config.Conf.Task.WaterGroup.Enable {
|
||||
log.Printf("水群排行任务已启用,执行表达式: %s", config.Conf.Task.WaterGroup.Cron)
|
||||
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron).Do(yesterday)
|
||||
log.Printf("水群排行任务已启用,执行表达式: %+v", config.Conf.Task.WaterGroup.Cron)
|
||||
if config.Conf.Task.WaterGroup.Cron.Yesterday != "" {
|
||||
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Yesterday).Do(watergroup.Yesterday)
|
||||
}
|
||||
if config.Conf.Task.WaterGroup.Cron.Week != "" {
|
||||
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Week).Do(watergroup.Week)
|
||||
}
|
||||
if config.Conf.Task.WaterGroup.Cron.Month != "" {
|
||||
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Month).Do(watergroup.Month)
|
||||
}
|
||||
}
|
||||
|
||||
// 更新好友列表
|
||||
if config.Conf.Task.SyncFriends.Enable {
|
||||
log.Printf("更新好友列表任务已启用,执行表达式: %s", config.Conf.Task.SyncFriends.Cron)
|
||||
_, _ = s.Cron(config.Conf.Task.SyncFriends.Cron).Do(syncFriends)
|
||||
_, _ = s.Cron(config.Conf.Task.SyncFriends.Cron).Do(friends.Sync)
|
||||
}
|
||||
|
||||
// 开启定时任务
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-wechat/client"
|
||||
"go-wechat/config"
|
||||
"go-wechat/entity"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 水群排行榜
|
||||
|
||||
// yesterday
|
||||
// @description: 昨日排行榜
|
||||
func yesterday() {
|
||||
for _, id := range config.Conf.Task.WaterGroup.Groups {
|
||||
dealYesterday(id)
|
||||
}
|
||||
}
|
||||
|
||||
// dealYesterday
|
||||
// @description: 处理请求
|
||||
// @param gid
|
||||
func dealYesterday(gid string) {
|
||||
notifyMsgs := []string{"#昨日水群排行榜"}
|
||||
|
||||
// 获取昨日消息总数
|
||||
var yesterdayMsgCount int64
|
||||
err := client.MySQL.Model(&entity.Message{}).
|
||||
Where("from_user = ?", gid).
|
||||
Where("DATEDIFF(create_at,NOW()) = -1").
|
||||
Count(&yesterdayMsgCount).Error
|
||||
if err != nil {
|
||||
log.Printf("获取昨日消息总数失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("昨日消息总数: %d", yesterdayMsgCount)
|
||||
if yesterdayMsgCount == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("昨日消息总数: %d", yesterdayMsgCount))
|
||||
|
||||
// 返回数据
|
||||
type record struct {
|
||||
GroupUser string
|
||||
Nickname string
|
||||
Count int64
|
||||
}
|
||||
|
||||
var records []record
|
||||
tx := client.MySQL.Table("t_message AS tm").
|
||||
Joins("LEFT JOIN t_group_user AS tgu ON tgu.wxid = tm.group_user AND tm.from_user = tgu.group_id").
|
||||
Select("tm.group_user", "tgu.nickname", "count( 1 ) AS `count`").
|
||||
Where("tm.from_user = ?", gid).
|
||||
Where("tm.type < 10000").
|
||||
Where("DATEDIFF(tm.create_at,NOW()) = -1").
|
||||
Group("tm.group_user, tgu.nickname").Order("`count` DESC").
|
||||
Limit(10)
|
||||
|
||||
// 黑名单
|
||||
blacklist := config.Conf.Task.WaterGroup.Blacklist
|
||||
// 如果有黑名单,过滤掉
|
||||
if len(blacklist) > 0 {
|
||||
tx.Where("tm.group_user NOT IN (?)", blacklist)
|
||||
}
|
||||
|
||||
err = tx.Find(&records).Error
|
||||
|
||||
if err != nil {
|
||||
log.Printf("获取昨日消息失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
for i, r := range records {
|
||||
log.Printf("账号: %s[%s] -> %d", r.Nickname, r.GroupUser, r.Count)
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("#%d: %s -> %d条", i+1, r.Nickname, r.Count))
|
||||
}
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " \n请未上榜的群友多多反思。")
|
||||
|
||||
log.Printf("排行榜: \n%s", strings.Join(notifyMsgs, "\n"))
|
||||
go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n"), 0)
|
||||
}
|
||||
85
tasks/watergroup/month.go
Normal file
85
tasks/watergroup/month.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package watergroup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-wechat/service"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Month
|
||||
// @description: 月排行榜
|
||||
func Month() {
|
||||
groups, err := service.GetAllEnableChatRank()
|
||||
if err != nil {
|
||||
log.Printf("获取启用了聊天排行榜的群组失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
// 消息统计
|
||||
dealMonth(group.Wxid)
|
||||
// 获取上个月月份
|
||||
yd := time.Now().Local().AddDate(0, 0, -1).Format("200601")
|
||||
// 发送词云
|
||||
fileName := fmt.Sprintf("%s_%s.png", yd, group.Wxid)
|
||||
utils.SendImage(group.Wxid, "D:\\Share\\wordcloud\\"+fileName, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// dealMonth
|
||||
// @description: 处理请求
|
||||
// @param gid
|
||||
func dealMonth(gid string) {
|
||||
monthStr := time.Now().Local().AddDate(0, 0, -1).Format("2006年01月")
|
||||
notifyMsgs := []string{fmt.Sprintf("#%s水群排行榜", monthStr)}
|
||||
|
||||
// 获取上月消息总数
|
||||
records, err := getRankData(gid, "month")
|
||||
if err != nil {
|
||||
log.Printf("获取上月消息排行失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("上月消息总数: %+v", records)
|
||||
// 莫得消息,直接返回
|
||||
if len(records) == 0 {
|
||||
log.Printf("上月群[%s]无对话记录", gid)
|
||||
return
|
||||
}
|
||||
// 计算消息总数
|
||||
var msgCount int64
|
||||
for _, v := range records {
|
||||
msgCount += v.Count
|
||||
}
|
||||
// 组装消息总数推送信息
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ %s本群 %d 位朋友共产生 %d 条发言", monthStr, len(records), msgCount))
|
||||
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
for i, r := range records {
|
||||
// 只取前十条
|
||||
if i >= 10 {
|
||||
break
|
||||
}
|
||||
|
||||
log.Printf("账号: %s[%s] -> %d", r.Nickname, r.GroupUser, r.Count)
|
||||
badge := "🏆"
|
||||
switch i {
|
||||
case 0:
|
||||
badge = "🥇"
|
||||
case 1:
|
||||
badge = "🥈"
|
||||
case 2:
|
||||
badge = "🥉"
|
||||
}
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("%s %s -> %d条", badge, r.Nickname, r.Count))
|
||||
}
|
||||
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf(" \n🎉感谢以上群友%s对群活跃做出的卓越贡献,也请未上榜的群友多多反思。", monthStr))
|
||||
|
||||
log.Printf("排行榜: \n%s", strings.Join(notifyMsgs, "\n"))
|
||||
go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n"), 0)
|
||||
}
|
||||
41
tasks/watergroup/utils.go
Normal file
41
tasks/watergroup/utils.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package watergroup
|
||||
|
||||
import "go-wechat/client"
|
||||
|
||||
// rankUser
|
||||
// @description: 排行榜用户
|
||||
type rankUser struct {
|
||||
GroupUser string // 微信Id
|
||||
Nickname string // 昵称
|
||||
Count int64 // 消息数
|
||||
}
|
||||
|
||||
// getRankData
|
||||
// @description: 获取消息排行榜
|
||||
// @param groupId string 群Id
|
||||
// @param d string 模式(yesterday | week | month)
|
||||
// @return rank
|
||||
// @return err
|
||||
func getRankData(groupId, date string) (rank []rankUser, err error) {
|
||||
tx := client.MySQL.Table("t_message AS tm").
|
||||
Joins("LEFT JOIN t_group_user AS tgu ON tgu.wxid = tm.group_user AND tm.from_user = tgu.group_id AND tgu.skip_chat_rank = 0").
|
||||
Select("tm.group_user", "tgu.nickname", "count( 1 ) AS `count`").
|
||||
Where("tm.from_user = ?", groupId).
|
||||
Where("tm.type < 10000").
|
||||
Group("tm.group_user, tgu.nickname").
|
||||
Order("`count` DESC")
|
||||
|
||||
// 根据参数获取不同日期的数据
|
||||
switch date {
|
||||
case "yesterday":
|
||||
tx.Where("DATEDIFF(tm.create_at,NOW()) = -1")
|
||||
case "week":
|
||||
tx.Where("YEARWEEK(date_format(tm.create_at, '%Y-%m-%d')) = YEARWEEK(now()) - 1")
|
||||
case "month":
|
||||
tx.Where("PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(create_at, '%Y%m')) = 1")
|
||||
}
|
||||
|
||||
// 查询指定时间段全部数据
|
||||
err = tx.Find(&rank).Error
|
||||
return
|
||||
}
|
||||
83
tasks/watergroup/week.go
Normal file
83
tasks/watergroup/week.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package watergroup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-wechat/service"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Week
|
||||
// @description: 周排行榜
|
||||
func Week() {
|
||||
groups, err := service.GetAllEnableChatRank()
|
||||
if err != nil {
|
||||
log.Printf("获取启用了聊天排行榜的群组失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
// 消息统计
|
||||
dealWeek(group.Wxid)
|
||||
// 获取上周周数
|
||||
year, weekNo := time.Now().Local().AddDate(0, 0, -1).ISOWeek()
|
||||
// 发送词云
|
||||
fileName := fmt.Sprintf("%d%d_%s.png", year, weekNo, group.Wxid)
|
||||
utils.SendImage(group.Wxid, "D:\\Share\\wordcloud\\"+fileName, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// dealWeek
|
||||
// @description: 处理请求
|
||||
// @param gid
|
||||
func dealWeek(gid string) {
|
||||
notifyMsgs := []string{"#上周水群排行榜"}
|
||||
|
||||
// 获取上周消息总数
|
||||
records, err := getRankData(gid, "week")
|
||||
if err != nil {
|
||||
log.Printf("获取上周消息排行失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("上周消息总数: %+v", records)
|
||||
// 莫得消息,直接返回
|
||||
if len(records) == 0 {
|
||||
log.Printf("上周群[%s]无对话记录", gid)
|
||||
return
|
||||
}
|
||||
// 计算消息总数
|
||||
var msgCount int64
|
||||
for _, v := range records {
|
||||
msgCount += v.Count
|
||||
}
|
||||
// 组装消息总数推送信息
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 上周本群 %d 位朋友共产生 %d 条发言", len(records), msgCount))
|
||||
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
for i, r := range records {
|
||||
// 只取前十条
|
||||
if i >= 10 {
|
||||
break
|
||||
}
|
||||
log.Printf("账号: %s[%s] -> %d", r.Nickname, r.GroupUser, r.Count)
|
||||
badge := "🏆"
|
||||
switch i {
|
||||
case 0:
|
||||
badge = "🥇"
|
||||
case 1:
|
||||
badge = "🥈"
|
||||
case 2:
|
||||
badge = "🥉"
|
||||
}
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("%s %s -> %d条", badge, r.Nickname, r.Count))
|
||||
}
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " \n🎉感谢以上群友上周对群活跃做出的卓越贡献,也请未上榜的群友多多反思。")
|
||||
|
||||
log.Printf("排行榜: \n%s", strings.Join(notifyMsgs, "\n"))
|
||||
go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n"), 0)
|
||||
}
|
||||
85
tasks/watergroup/yesterday.go
Normal file
85
tasks/watergroup/yesterday.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package watergroup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-wechat/service"
|
||||
"go-wechat/utils"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 水群排行榜
|
||||
|
||||
// Yesterday
|
||||
// @description: 昨日排行榜
|
||||
func Yesterday() {
|
||||
groups, err := service.GetAllEnableChatRank()
|
||||
if err != nil {
|
||||
log.Printf("获取启用了聊天排行榜的群组失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
// 消息统计
|
||||
dealYesterday(group.Wxid)
|
||||
// 获取昨日日期
|
||||
yd := time.Now().Local().AddDate(0, 0, -1).Format("20060102")
|
||||
// 发送词云
|
||||
fileName := fmt.Sprintf("%s_%s.png", yd, group.Wxid)
|
||||
utils.SendImage(group.Wxid, "D:\\Share\\wordcloud\\"+fileName, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// dealYesterday
|
||||
// @description: 处理请求
|
||||
// @param gid
|
||||
func dealYesterday(gid string) {
|
||||
notifyMsgs := []string{"#昨日水群排行榜"}
|
||||
|
||||
// 获取昨日消息总数
|
||||
records, err := getRankData(gid, "yesterday")
|
||||
if err != nil {
|
||||
log.Printf("获取昨日消息排行失败, 错误信息: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("昨日消息总数: %+v", records)
|
||||
// 莫得消息,直接返回
|
||||
if len(records) == 0 {
|
||||
log.Printf("昨日群[%s]无对话记录", gid)
|
||||
return
|
||||
}
|
||||
// 计算消息总数
|
||||
var msgCount int64
|
||||
for _, v := range records {
|
||||
msgCount += v.Count
|
||||
}
|
||||
// 组装消息总数推送信息
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 昨日本群 %d 位朋友共产生 %d 条发言", len(records), msgCount))
|
||||
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " ")
|
||||
for i, r := range records {
|
||||
// 只取前十条
|
||||
if i >= 10 {
|
||||
break
|
||||
}
|
||||
log.Printf("账号: %s[%s] -> %d", r.Nickname, r.GroupUser, r.Count)
|
||||
badge := "🏆"
|
||||
switch i {
|
||||
case 0:
|
||||
badge = "🥇"
|
||||
case 1:
|
||||
badge = "🥈"
|
||||
case 2:
|
||||
badge = "🥉"
|
||||
}
|
||||
notifyMsgs = append(notifyMsgs, fmt.Sprintf("%s %s -> %d条", badge, r.Nickname, r.Count))
|
||||
}
|
||||
|
||||
notifyMsgs = append(notifyMsgs, " \n🎉感谢以上群友昨日对群活跃做出的卓越贡献,也请未上榜的群友多多反思。")
|
||||
|
||||
log.Printf("排行榜: \n%s", strings.Join(notifyMsgs, "\n"))
|
||||
go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n"), 0)
|
||||
}
|
||||
25
tcpserver/forward.go
Normal file
25
tcpserver/forward.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package tcpserver
|
||||
|
||||
import (
|
||||
"go-wechat/config"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
// forward
|
||||
// @description: 转发消息
|
||||
func forward(msg []byte) {
|
||||
// 使用socket转发消息
|
||||
for _, s := range config.Conf.Wechat.Forward {
|
||||
conn, err := net.Dial("tcp", s)
|
||||
if err != nil {
|
||||
log.Printf("转发消息失败,错误信息: %v", err)
|
||||
continue
|
||||
}
|
||||
_, err = conn.Write(msg)
|
||||
if err != nil {
|
||||
log.Printf("转发消息失败,错误信息: %v", err)
|
||||
}
|
||||
_ = conn.Close()
|
||||
}
|
||||
}
|
||||
37
tcpserver/handle.go
Normal file
37
tcpserver/handle.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package tcpserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go-wechat/config"
|
||||
"go-wechat/handler"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
// process
|
||||
// @description: 处理连接
|
||||
// @param conn
|
||||
func process(conn net.Conn) {
|
||||
// 处理完关闭连接
|
||||
defer func() {
|
||||
log.Printf("处理完成: -> %s", conn.RemoteAddr())
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err := io.Copy(&buf, conn); err != nil {
|
||||
log.Printf("[%s]返回数据失败,错误信息: %v", conn.RemoteAddr(), err)
|
||||
}
|
||||
log.Printf("[%s]数据长度: %d", conn.RemoteAddr(), buf.Len())
|
||||
go handler.Parse(conn.RemoteAddr(), buf.Bytes())
|
||||
|
||||
// 转发到其他地方去
|
||||
if len(config.Conf.Wechat.Forward) > 0 {
|
||||
go forward(buf.Bytes())
|
||||
}
|
||||
// 将接受到的数据返回给客户端
|
||||
if _, err := conn.Write([]byte("200 OK")); err != nil {
|
||||
log.Printf("[%s]返回数据失败,错误信息: %v", conn.RemoteAddr(), err)
|
||||
}
|
||||
}
|
||||
28
tcpserver/server.go
Normal file
28
tcpserver/server.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package tcpserver
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
// Start
|
||||
// @description: 启动服务
|
||||
func Start() {
|
||||
// 建立 tcp 服务
|
||||
listen, err := net.Listen("tcp", "0.0.0.0:19099")
|
||||
if err != nil {
|
||||
log.Printf("listen failed, err:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
// 等待客户端建立连接
|
||||
conn, err := listen.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accept failed, err:%v", err)
|
||||
continue
|
||||
}
|
||||
// 启动一个单独的 goroutine 去处理连接
|
||||
go process(conn)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import "fmt"
|
||||
|
||||
type MessageType int
|
||||
|
||||
// 微信定义的消息类型
|
||||
const (
|
||||
MsgTypeText MessageType = 1 // 文本消息
|
||||
MsgTypeImage MessageType = 3 // 图片消息
|
||||
|
||||
@@ -2,7 +2,9 @@ package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go-wechat/common/current"
|
||||
"go-wechat/config"
|
||||
"log"
|
||||
"time"
|
||||
@@ -82,3 +84,40 @@ func SendImage(toId, imgPath string, retryCount int) {
|
||||
}
|
||||
log.Printf("发送图片消息结果: %s", resp.String())
|
||||
}
|
||||
|
||||
// SendEmotion
|
||||
// @description: 发送自定义表情包
|
||||
// @param toId string 群或者好友Id
|
||||
// @param emotionHash string 表情包hash(md5值)
|
||||
// @param retryCount int 重试次数
|
||||
func SendEmotion(toId, emotionHash string, retryCount int) {
|
||||
if retryCount > 5 {
|
||||
log.Printf("重试五次失败,停止发送")
|
||||
return
|
||||
}
|
||||
|
||||
// 组装表情包本地地址
|
||||
// 规则:机器人数据目录\FileStorage\CustomEmotion\表情包hash前两位\表情包hash
|
||||
emotionPath := fmt.Sprintf("%sFileStorage\\CustomEmotion\\%s\\%s",
|
||||
current.GetRobotInfo().CurrentDataPath, emotionHash[:2], emotionHash)
|
||||
|
||||
// 组装参数
|
||||
param := map[string]any{
|
||||
"wxid": toId, // 群或好友Id
|
||||
"filePath": emotionPath, // 图片地址
|
||||
}
|
||||
pbs, _ := json.Marshal(param)
|
||||
|
||||
res := resty.New()
|
||||
resp, err := res.R().
|
||||
SetHeader("Content-Type", "application/json;chartset=utf-8").
|
||||
SetBody(string(pbs)).
|
||||
Post(config.Conf.Wechat.GetURL("/api/sendCustomEmotion"))
|
||||
if err != nil {
|
||||
log.Printf("发送表情包消息失败: %s", err.Error())
|
||||
// 休眠五秒后重新发送
|
||||
time.Sleep(5 * time.Second)
|
||||
SendImage(toId, emotionHash, retryCount+1)
|
||||
}
|
||||
log.Printf("发送表情包消息结果: %s", resp.String())
|
||||
}
|
||||
|
||||
190
views/index.html
Normal file
190
views/index.html
Normal file
@@ -0,0 +1,190 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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="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>
|
||||
<body>
|
||||
<div class="p-5 space-y-5">
|
||||
<!-- 如果msg不等于success,显示alert -->
|
||||
{{ if ne .msg "success" }}
|
||||
<div role="alert" class="alert alert-error">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<span>{{ .msg }}</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<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">
|
||||
<!-- 循环好友列表 -->
|
||||
<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>
|
||||
|
||||
<input type="radio" name="friend_tab" role="tab" class="tab" aria-label="群列表" />
|
||||
<div role="tabpanel" class="tab-content p-6">
|
||||
<!-- 循环群列表 -->
|
||||
<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;
|
||||
}
|
||||
143
views/static/js/index.js
Normal file
143
views/static/js/index.js
Normal file
@@ -0,0 +1,143 @@
|
||||
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
|
||||
})
|
||||
}
|
||||
BIN
views/wechat.ico
Normal file
BIN
views/wechat.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 827 B |
34
vo/friend.go
Normal file
34
vo/friend.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
"go-wechat/common/types"
|
||||
)
|
||||
|
||||
// FriendItem
|
||||
// @description: 好友列表数据
|
||||
type FriendItem struct {
|
||||
CustomAccount string // 微信号
|
||||
Nickname string // 昵称
|
||||
Pinyin string // 昵称拼音大写首字母
|
||||
PinyinAll string // 昵称全拼
|
||||
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