2025-06-18 11:47:43 +00:00
|
|
|
package robot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fonchain-fiee/api/accountFiee"
|
|
|
|
"fonchain-fiee/pkg/common/ws"
|
|
|
|
"fonchain-fiee/pkg/service/asChat/chatCache"
|
|
|
|
"fonchain-fiee/pkg/service/asChat/dto"
|
|
|
|
"fonchain-fiee/pkg/service/asChat/logic"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RobotTaskWithKeyworkds struct {
|
2025-06-19 03:02:27 +00:00
|
|
|
title string
|
2025-06-18 11:47:43 +00:00
|
|
|
runTime time.Time
|
|
|
|
Response string
|
|
|
|
Receiver *accountFiee.ChatUserData
|
|
|
|
Sender *accountFiee.ChatUserData
|
|
|
|
Msg string
|
|
|
|
Resp string
|
|
|
|
keywords []string
|
|
|
|
}
|
|
|
|
|
2025-06-19 03:02:27 +00:00
|
|
|
func NewReplyWhenHitKeywords(title string, keywords []string) IRobotTask {
|
|
|
|
return &RobotTaskWithKeyworkds{title: title, keywords: keywords}
|
2025-06-18 11:47:43 +00:00
|
|
|
}
|
|
|
|
func (r *RobotTaskWithKeyworkds) Hit(event ws.ListenEventData, sender *accountFiee.ChatUserData) (hit bool) {
|
|
|
|
if event.EventType != ws.EventChatMessage || event.Msg == "" || event.Client == nil || event.ChatUser == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if event.ChatUser.Role != 1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.Sender = sender
|
|
|
|
r.Receiver = event.ChatUser
|
|
|
|
for _, v := range r.keywords {
|
|
|
|
if strings.Contains(event.Msg, v) {
|
2025-06-19 01:52:34 +00:00
|
|
|
fmt.Printf("关键词比对:%s ----- %s : true", event.Msg, v)
|
2025-06-18 11:47:43 +00:00
|
|
|
hit = true
|
|
|
|
break
|
|
|
|
}
|
2025-06-19 01:52:34 +00:00
|
|
|
fmt.Printf("关键词比对:%s ----- %s: false", event.Msg, v)
|
2025-06-18 11:47:43 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RobotTaskWithKeyworkds) Run(cache *chatCache.ChatCache) (err error) {
|
|
|
|
err = logic.NewMessage(context.Background(), cache, r.Sender, dto.NewMessageRequest{
|
|
|
|
Waiter: true,
|
|
|
|
Robot: true,
|
|
|
|
AtUserId: r.Receiver.ID,
|
|
|
|
SessionId: fmt.Sprintf("%d", r.Receiver.ID),
|
|
|
|
Message: dto.Message{
|
|
|
|
MsgType: 1,
|
|
|
|
Text: r.Resp,
|
|
|
|
LocalStamp: time.Now().Unix(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RobotTaskWithKeyworkds) RunTime() time.Time {
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RobotTaskWithKeyworkds) SetResponse(response string) {
|
|
|
|
r.Resp = response
|
|
|
|
}
|
2025-06-19 03:02:27 +00:00
|
|
|
|
|
|
|
func (r *RobotTaskWithKeyworkds) GetResponse() string {
|
|
|
|
return r.Response
|
|
|
|
}
|
|
|
|
func (r *RobotTaskWithKeyworkds) SetTitle(title string) {
|
|
|
|
r.title = title
|
|
|
|
}
|
|
|
|
func (r *RobotTaskWithKeyworkds) GetTitle() string {
|
|
|
|
return r.title
|
|
|
|
}
|