Files
huangguo_server/web/service/chatrobotser/chatrobot.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

120 lines
3.1 KiB
Go

package chatrobotser
import (
"time"
"91porn-server/common/stderr"
"91porn-server/models/commod"
"91porn-server/models/v/chatrobotmod"
"github.com/jinzhu/copier"
)
// 获取机器人配置列表
func GetRobotConfList(param chatrobotmod.ReqConfList) (code stderr.Code, data interface{}, err error) {
var skip = int64((param.PageNumber - 1) * param.PageSize)
var limit = int64(param.PageSize)
total, cList, err := chatrobotmod.GetRobotConf(param.Type, skip, limit)
if err != nil {
code = stderr.Failure
return
}
if cList == nil {
data = commod.ListResp{List: []chatrobotmod.ChatRobot{}}
} else {
list := make([]chatrobotmod.RespList, len(cList))
for i, v := range cList {
tmp := chatrobotmod.RespList{}
if err = copier.Copy(&tmp, &v); err != nil {
code = stderr.Failure
return
}
list[i] = tmp
}
data = commod.ListResp{List: list, Total: total}
}
code = stderr.Success
return
}
// 添加配置
func AddRobotConf(param chatrobotmod.ReqAdd) (code stderr.Code, data interface{}, err error) {
if code, err = addCheck(param.Type); err != nil || code != stderr.Success {
return
}
switch param.Type {
case chatrobotmod.Comment: // 评论机器人
return addCmtRobotConf(param.Type, param.ReqAddCmt)
default:
code = stderr.RobotTypeInvalid
return
}
}
func addCheck(rType chatrobotmod.EnumRobotType) (stderr.Code, error) {
isExists, err := chatrobotmod.ConfExists(rType)
if err != nil {
return stderr.Failure, err
}
if isExists {
return stderr.RobotTypeExisted, nil
}
return stderr.Success, nil
}
// 新增评论机器人配置
func addCmtRobotConf(rType chatrobotmod.EnumRobotType, param chatrobotmod.ReqAddCmt) (code stderr.Code, data interface{}, err error) {
var now = time.Now()
var doc = chatrobotmod.ChatRobot{
Type: rType,
IsActive: param.IsActive,
CreatedAt: now,
UpdatedAt: now,
CommentRobot: chatrobotmod.CommentRobot{
From: param.From,
To: param.To,
TotalLimit: param.TotalLimit,
PureLimit: param.PureLimit,
Frequency: param.Frequency,
MaxCommentNum: param.MaxCommentNum,
MaxFakeLikes: param.MaxFakeLikes,
MinFakeLikes: param.MinFakeLikes,
MaxFakePlayCount: param.MaxFakePlayCount,
MinFakePlayCount: param.MinFakePlayCount,
},
}
if err = chatrobotmod.Insert(doc); err != nil {
code = stderr.Failure
return
}
code = stderr.Success
return
}
// 更新机器人配置
func UpdateRobotConf(param chatrobotmod.ReqUpdate) (code stderr.Code, data interface{}, err error) {
switch param.Type {
case chatrobotmod.Comment: // 评论机器人
return updateCmtRobotConf(param.Type, param.ReqUpdateCmt)
default:
code = stderr.RobotTypeInvalid
return
}
}
// 更新评论机器人配置
func updateCmtRobotConf(rType chatrobotmod.EnumRobotType, param chatrobotmod.ReqUpdateCmt) (code stderr.Code, data interface{}, err error) {
doc := chatrobotmod.CmtUpdateDoc{}
if err = copier.Copy(&doc, &param); err != nil {
code = stderr.Failure
return
}
doc.UpdatedAt = time.Now()
if err = chatrobotmod.UpdateCmtRobotConf(rType, doc); err != nil {
code = stderr.Failure
return
}
code = stderr.Success
return
}