2023-11-30 17:31:50 +08:00
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-11-30 23:12:38 +08:00
|
|
|
|
"go-wechat/client"
|
2024-07-05 09:32:39 +08:00
|
|
|
|
"go-wechat/model/entity"
|
2023-11-30 23:12:38 +08:00
|
|
|
|
"gorm.io/gorm"
|
2023-11-30 17:31:50 +08:00
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// changeStatusParam
|
|
|
|
|
// @description: 修改状态用的参数集
|
|
|
|
|
type changeStatusParam struct {
|
|
|
|
|
WxId string `json:"wxId" binding:"required"`
|
|
|
|
|
UserId string `json:"userId"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 12:02:33 +08:00
|
|
|
|
// changeUseAiModelParam
|
|
|
|
|
// @description: 修改使用的AI模型用的参数集
|
|
|
|
|
type changeUseAiModelParam struct {
|
2024-07-04 21:17:29 +08:00
|
|
|
|
WxId string `json:"wxid" binding:"required"` // 群Id或微信Id
|
2024-07-11 19:37:27 +08:00
|
|
|
|
Model string `json:"model"` // 模型代码
|
2024-01-31 12:02:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 16:23:09 +08:00
|
|
|
|
// autoClearMembers
|
|
|
|
|
// @description: 自动清理群成员
|
|
|
|
|
type autoClearMembers struct {
|
|
|
|
|
WxId string `json:"wxid" binding:"required"` // 群Id
|
|
|
|
|
Days int `json:"days"` // 多少天未发言
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
// 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)
|
|
|
|
|
|
2023-11-30 23:12:38 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 12:02:33 +08:00
|
|
|
|
// ChangeUseAiModel
|
|
|
|
|
// @description: 修改使用的AI模型
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeUseAiModel(ctx *gin.Context) {
|
|
|
|
|
var p changeUseAiModelParam
|
|
|
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
|
|
|
ctx.String(http.StatusBadRequest, "参数错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err := client.MySQL.Model(&entity.Friend{}).
|
|
|
|
|
Where("wxid = ?", p.WxId).
|
|
|
|
|
Update("`ai_model`", p.Model).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改【%s】的AI模型失败:%s", p.WxId, err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 17:30:50 +08:00
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ChangeUseAiAssistant
|
|
|
|
|
// @description: 修改使用的AI助手
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeUseAiAssistant(ctx *gin.Context) {
|
|
|
|
|
// 此处复用一下结构体
|
|
|
|
|
var p changeUseAiModelParam
|
|
|
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
|
|
|
ctx.String(http.StatusBadRequest, "参数错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err := client.MySQL.Model(&entity.Friend{}).
|
|
|
|
|
Where("wxid = ?", p.WxId).
|
|
|
|
|
Update("`prompt`", p.Model).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改【%s】的AI助手失败:%s", p.WxId, err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 12:02:33 +08:00
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
// 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)
|
|
|
|
|
|
2023-11-30 23:12:38 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 11:37:21 +08:00
|
|
|
|
// ChangeEnableSummaryStatus
|
|
|
|
|
// @description: 修改是否开启聊天记录总结
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeEnableSummaryStatus(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_summary`", gorm.Expr(" !`enable_summary`")).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改开启聊天记录总结失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 14:24:30 +08:00
|
|
|
|
// 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, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 22:20:14 +08:00
|
|
|
|
// ChangeEnableCommandStatus
|
|
|
|
|
// @description: 修改是否开启指令
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeEnableCommandStatus(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_command`", gorm.Expr(" !`enable_command`")).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改指令启用状态失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
// 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)
|
|
|
|
|
|
2023-11-30 23:12:38 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:31:50 +08:00
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
2024-05-15 11:15:15 +08:00
|
|
|
|
|
|
|
|
|
// ChangeEnableNewsStatus
|
|
|
|
|
// @description: 修改是否开启新闻
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeEnableNewsStatus(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_news`", gorm.Expr(" !`enable_news`")).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改早报启用状态失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
2024-06-18 16:23:09 +08:00
|
|
|
|
|
2024-07-15 14:14:24 +08:00
|
|
|
|
// ChangeEnableHotTopStatus
|
|
|
|
|
// @description: 修改是否开启热搜
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeEnableHotTopStatus(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_hot_top`", gorm.Expr(" !`enable_hot_top`")).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改热榜启用状态失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 16:23:09 +08:00
|
|
|
|
// AutoClearMembers
|
|
|
|
|
// @description: 自动清理群成员
|
|
|
|
|
// @param ctx
|
|
|
|
|
func AutoClearMembers(ctx *gin.Context) {
|
|
|
|
|
var p autoClearMembers
|
|
|
|
|
if err := ctx.ShouldBindJSON(&p); err != nil {
|
|
|
|
|
ctx.String(http.StatusBadRequest, "参数错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Printf("待修改的Id:%s", p.WxId)
|
|
|
|
|
|
|
|
|
|
err := client.MySQL.Model(&entity.Friend{}).
|
|
|
|
|
Where("wxid = ?", p.WxId).
|
|
|
|
|
Update("`clear_member`", p.Days).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改自动清理群成员阈值失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|
2024-08-17 13:10:31 +08:00
|
|
|
|
|
|
|
|
|
// ChangeAiFreeLimit
|
|
|
|
|
// @description: 修改AI免费次数
|
|
|
|
|
// @param ctx
|
|
|
|
|
func ChangeAiFreeLimit(ctx *gin.Context) {
|
|
|
|
|
var p autoClearMembers
|
|
|
|
|
if err := ctx.ShouldBindJSON(&p); err != nil {
|
|
|
|
|
ctx.String(http.StatusBadRequest, "参数错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Printf("待修改的Id:%s", p.WxId)
|
|
|
|
|
|
|
|
|
|
err := client.MySQL.Model(&entity.Friend{}).
|
|
|
|
|
Where("wxid = ?", p.WxId).
|
|
|
|
|
Update("`ai_free_limit`", p.Days).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("修改AI免费次数失败:%s", err)
|
|
|
|
|
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.String(http.StatusOK, "操作成功")
|
|
|
|
|
}
|