package echo import ( "encoding/json" "git.lxtend.com/lixiangwuxian/qqbot/constants" "git.lxtend.com/lixiangwuxian/qqbot/handler" "git.lxtend.com/lixiangwuxian/qqbot/model" ) func init() { handler.RegisterHandler("echo", echo, constants.LEVEL_USER) handler.RegisterHelpInform("echo", "echo", "echo 再说一遍") handler.RegisterHandler("echofull", addEchoFullTrigger, constants.LEVEL_USER) handler.RegisterHelpInform("echofull", "echofull", "echofull后,会返回下一条消息的json结构") } func echo(msg model.Message) (reply *model.Reply) { if len(msg.RawMsg) <= 5 { return &model.Reply{} } return &model.Reply{ ReplyMsg: msg.RawMsg[5:], ReferOriginMsg: true, FromMsg: msg, } } func addEchoFullTrigger(msg model.Message) (reply *model.Reply) { handler.RegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId, echoFull) return nil } func echoFull(msg model.Message) (reply *model.Reply, catched bool) { msgBytes, _ := json.Marshal(msg.StructuredMsg) handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId) return &model.Reply{ ReplyMsg: string(msgBytes), ReferOriginMsg: false, FromMsg: msg, }, true }