qq_bot/handler/echo/echo.go

42 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 <message> 再说一遍")
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)
return &model.Reply{
ReplyMsg: msgBytes,
ReferOriginMsg: false,
FromMsg: msg,
}, true
}