65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package autoReply -----------------------------
 | |
| // @file      : rulerList.go
 | |
| // @author    : JJXu
 | |
| // @contact   : wavingbear@163.com
 | |
| // @time      : 2025/6/13 16:16
 | |
| // -------------------------------------------
 | |
| package robot
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"fonchain-fiee/api/accountFiee"
 | |
| 	"fonchain-fiee/pkg/common/ws"
 | |
| 	"fonchain-fiee/pkg/service/asChat/chatCache"
 | |
| 	"fonchain-fiee/pkg/service/asChat/dto"
 | |
| 	"strings"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| 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
 | |
| }
 | |
| 
 | |
| // 自动回复规则结构转换
 | |
| func ParseReplyRule(data []*dto.ChatAutoReplyData) (joinSessionRules, keywordsRules, noReplyAfterRules []IRobotTask) {
 | |
| 	for _, responseRules := range data {
 | |
| 		responseRules := responseRules
 | |
| 		for ruleName, v := range responseRules.Rules {
 | |
| 			if !v.Enable {
 | |
| 				continue
 | |
| 			}
 | |
| 			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)
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	return
 | |
| }
 |