feat: 在 echo 处理器中添加 echofull 触发器,支持返回消息的 JSON 结构

This commit is contained in:
lixiangwuxian 2025-06-18 17:33:35 +08:00
parent 652647bdc0
commit e58ae51ed8
2 changed files with 20 additions and 0 deletions

View File

@ -50,6 +50,8 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
reply.ReplyMsg = append([]any{replyMsg}, replyMsgVal...)
case string:
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)

View File

@ -1,6 +1,8 @@
package echo
import (
"encoding/json"
"git.lxtend.com/lixiangwuxian/qqbot/constants"
"git.lxtend.com/lixiangwuxian/qqbot/handler"
"git.lxtend.com/lixiangwuxian/qqbot/model"
@ -9,6 +11,8 @@ import (
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) {
@ -21,3 +25,17 @@ func echo(msg model.Message) (reply *model.Reply) {
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
}