fonchain-fiee/pkg/service/asChat/robot/rulerList.go

65 lines
1.9 KiB
Go
Raw Normal View History

2025-06-14 06:46:01 +00:00
// Package autoReply -----------------------------
// @file : rulerList.go
// @author : JJXu
// @contact : wavingbear@163.com
// @time : 2025/6/13 16:16
// -------------------------------------------
package robot
2025-06-15 08:01:55 +00:00
import (
2025-06-19 01:15:10 +00:00
"fmt"
2025-06-19 03:12:15 +00:00
"fonchain-fiee/api/accountFiee"
"fonchain-fiee/pkg/common/ws"
"fonchain-fiee/pkg/service/asChat/chatCache"
2025-06-15 08:01:55 +00:00
"fonchain-fiee/pkg/service/asChat/dto"
"strings"
2025-06-19 03:12:15 +00:00
"time"
2025-06-15 08:01:55 +00:00
)
2025-06-19 03:12:15 +00:00
type IRobotTask interface {
Hit(event ws.ListenEventData, sender *accountFiee.ChatUserData) (hit bool)
Run(cache *chatCache.ChatCache) error
RunTime() time.Time
SetResponse(response string)
GetResponse() string
SetTitle(title string)
GetTitle() string
}
2025-06-15 08:09:25 +00:00
// 自动回复规则结构转换
2025-06-19 03:02:27 +00:00
func ParseReplyRule(data []*dto.ChatAutoReplyData) (joinSessionRules, keywordsRules, noReplyAfterRules []IRobotTask) {
for _, responseRules := range data {
responseRules := responseRules
for ruleName, v := range responseRules.Rules {
if !v.Enable {
2025-06-15 08:01:55 +00:00
continue
}
2025-06-19 03:02:27 +00:00
switch ruleName {
case "keywords": //关键字回复
var keywords []string
if v.Content == "" {
continue
} else {
keywords = strings.Split(v.Content, ",")
}
fmt.Println("ParseReplyRule 解析keywords:", keywords)
r := NewReplyWhenHitKeywords(responseRules.Title+"-keywords", keywords)
r.SetResponse(responseRules.Response)
keywordsRules = append(keywordsRules, r)
case "joinSession": //加入聊天后回复
r := NewReplyWhenUserJoinSession(responseRules.Title + "-joinSession")
r.SetResponse(responseRules.Response)
joinSessionRules = append(joinSessionRules, r)
case "noReplyAfter": //指定时间没有回复则自动回复
if v.SecondDuration == 0 {
continue
}
r := NewReplyWhenWaiterNoAction(responseRules.Title+"-noReplyAfter", v.SecondDuration)
r.SetResponse(responseRules.Response)
noReplyAfterRules = append(noReplyAfterRules, r)
2025-06-15 08:09:25 +00:00
}
2025-06-15 08:01:55 +00:00
}
}
return
}