airobot/busi/chat.go
2022-12-13 10:38:33 +08:00

62 lines
1.2 KiB
Go

package busi
import (
"time"
"legu.airobot/lib"
"legu.airobot/pb"
)
//竞技场场景
var _ lib.IScene = (*ChatScene)(nil)
type ChatScene struct {
lib.Action
}
func (f *ChatScene) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "聊天测试",
Desc: "聊天场景压测",
}
}
func (f *ChatScene) Run(ai lib.IRobot) (err error) {
var (
code pb.ErrorCode
userlogin *pb.UserLoginResp
)
//世界聊天
if code = ai.SendMsg("chat", "send", &pb.ChatSendReq{
Channel: pb.ChatChannel_World,
Ctype: pb.ChatType_Text,
Content: "hello! are you good?",
}, &pb.ChatSendResp{}); code != pb.ErrorCode_Success {
ai.Stop()
return
}
time.Sleep(time.Second * 1)
//工会聊天
if resp := ai.Get("user.login"); resp != nil {
userlogin = resp.(*pb.UserLoginResp)
if userlogin.Ex.SociatyId != "" {
if code = ai.SendMsg("chat", "send", &pb.ChatSendReq{
Channel: pb.ChatChannel_Union,
TargetId: userlogin.Ex.SociatyId,
Ctype: pb.ChatType_Text,
Content: "hello! are you good?",
}, &pb.ChatSendResp{}); code != pb.ErrorCode_Success {
ai.Stop()
return
}
time.Sleep(time.Second * 1)
}
}
//好友列表
return
}