87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
|
package robot
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"fonchain-fiee/api/accountFiee"
|
||
|
"fonchain-fiee/pkg/common/ws"
|
||
|
"fonchain-fiee/pkg/service"
|
||
|
"fonchain-fiee/pkg/service/asChat/chatCache"
|
||
|
"fonchain-fiee/pkg/service/asChat/dto"
|
||
|
"fonchain-fiee/pkg/service/asChat/logic"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func NewReplyWhenUserJoinSession() IRobotTask {
|
||
|
return &ReplyWhenUserJoinSession{}
|
||
|
}
|
||
|
|
||
|
type ReplyWhenUserJoinSession struct {
|
||
|
Response string
|
||
|
Receiver *accountFiee.ChatUserData
|
||
|
Sender *accountFiee.ChatUserData
|
||
|
Msg string
|
||
|
Resp string
|
||
|
}
|
||
|
|
||
|
func (r ReplyWhenUserJoinSession) Hit(event ws.ListenEventData, sender *accountFiee.ChatUserData) (hit bool) {
|
||
|
if event.EventType != ws.EventUserJoin {
|
||
|
return
|
||
|
}
|
||
|
if event.Client == nil {
|
||
|
return
|
||
|
}
|
||
|
ctx := context.Background()
|
||
|
queryRes, err := service.AccountFieeProvider.GetChatRecordList(ctx, &accountFiee.GetChatRecordListRequest{
|
||
|
Query: &accountFiee.ChatRecordData{
|
||
|
SessionId: event.Client.SessionId,
|
||
|
},
|
||
|
Page: 1,
|
||
|
PageSize: 1,
|
||
|
Order: "created_at desc",
|
||
|
})
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
//如果最近一次的消息也是机器人发送的,就不再发送了
|
||
|
for i, v := range queryRes.List {
|
||
|
if i == 0 {
|
||
|
if v.UserId == sender.ID {
|
||
|
return
|
||
|
} else {
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
hit = true
|
||
|
r.Sender = sender
|
||
|
r.Receiver = event.ChatUser
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (r ReplyWhenUserJoinSession) Run(cache *chatCache.ChatCache) (err error) {
|
||
|
clientSessionId := fmt.Sprintf("%d", r.Receiver.ID)
|
||
|
err = logic.NewMessage(context.Background(), cache, r.Sender, dto.NewMessageRequest{
|
||
|
Waiter: true,
|
||
|
Robot: true,
|
||
|
AtUserId: r.Receiver.ID,
|
||
|
SessionId: clientSessionId,
|
||
|
Message: dto.Message{
|
||
|
MsgType: 1,
|
||
|
Text: r.Resp,
|
||
|
LocalStamp: time.Now().Unix(),
|
||
|
},
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (r ReplyWhenUserJoinSession) RunTime() time.Time {
|
||
|
//TODO implement me
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (r ReplyWhenUserJoinSession) SetResponse(response string) {
|
||
|
//TODO implement me
|
||
|
panic("implement me")
|
||
|
}
|