75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package robot
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//用户模块 机器人
|
|
type ModuleRobot_Chat struct {
|
|
}
|
|
|
|
func (this *ModuleRobot_Chat) Init() (err error) {
|
|
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Chat) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
}
|
|
return
|
|
}
|
|
func (this *ModuleRobot_Chat) OncePipeline(robot IRobot) (err error) {
|
|
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
usermodule *ModuleRobot_User
|
|
)
|
|
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
|
if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{
|
|
Suser: comm.GetUserBaseInfo(usermodule.user),
|
|
Channel: pb.ChatChannel_World,
|
|
Ctype: pb.ChatType_Text,
|
|
Content: fmt.Sprintf("你好!我是%s", robot.Account()),
|
|
}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_Chat) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
switch comm.TaskType(condconf.Type) {
|
|
case comm.Rtype62:
|
|
var (
|
|
usermodule *ModuleRobot_User
|
|
)
|
|
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
|
if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{
|
|
Suser: comm.GetUserBaseInfo(usermodule.user),
|
|
Channel: pb.ChatChannel_World,
|
|
Ctype: pb.ChatType_Text,
|
|
Content: fmt.Sprintf("你好!我是%s", robot.Account()),
|
|
}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|