feat: 在 echo 处理器中添加 echofull 触发器,支持返回消息的 JSON 结构
This commit is contained in:
parent
652647bdc0
commit
e58ae51ed8
@ -50,6 +50,8 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
|
|||||||
reply.ReplyMsg = append([]any{replyMsg}, replyMsgVal...)
|
reply.ReplyMsg = append([]any{replyMsg}, replyMsgVal...)
|
||||||
case string:
|
case string:
|
||||||
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), replyMsgVal)
|
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), replyMsgVal)
|
||||||
|
case []byte:
|
||||||
|
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), replyMsgVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userID := strconv.FormatInt(reply.FromMsg.UserId, 10)
|
userID := strconv.FormatInt(reply.FromMsg.UserId, 10)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package echo
|
package echo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"git.lxtend.com/lixiangwuxian/qqbot/constants"
|
"git.lxtend.com/lixiangwuxian/qqbot/constants"
|
||||||
"git.lxtend.com/lixiangwuxian/qqbot/handler"
|
"git.lxtend.com/lixiangwuxian/qqbot/handler"
|
||||||
"git.lxtend.com/lixiangwuxian/qqbot/model"
|
"git.lxtend.com/lixiangwuxian/qqbot/model"
|
||||||
@ -9,6 +11,8 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
handler.RegisterHandler("echo", echo, constants.LEVEL_USER)
|
handler.RegisterHandler("echo", echo, constants.LEVEL_USER)
|
||||||
handler.RegisterHelpInform("echo", "echo", "echo <message> 再说一遍")
|
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) {
|
func echo(msg model.Message) (reply *model.Reply) {
|
||||||
@ -21,3 +25,17 @@ func echo(msg model.Message) (reply *model.Reply) {
|
|||||||
FromMsg: msg,
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user