diff --git a/action/action.go b/action/action.go index 6876107..58fca9e 100644 --- a/action/action.go +++ b/action/action.go @@ -45,7 +45,7 @@ func (am *actionManager) SendMsg(reply *model.Reply) error { } reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), reply.ReplyMsg) } - sendPkg := model.GenSendPkg(reply.FromMsg.UserId, reply.FromMsg.GroupInfo.GroupId, reply.ReplyMsg, false) + sendPkg := model.GenSendPkg(reply.FromMsg.UserId, reply.FromMsg.GroupInfo.GroupId, reply.ReplyMsg, false, false) sendPkgJson, err := json.Marshal(sendPkg) if err != nil { return err @@ -59,6 +59,20 @@ func (am *actionManager) SendMsg(reply *model.Reply) error { return nil } +func (am *actionManager) SendForward(reply *model.Reply) error { + am.sendMtx.Lock() + defer am.sendMtx.Unlock() + sendPkg := model.GenSendPkg(reply.FromMsg.UserId, reply.FromMsg.GroupInfo.GroupId, reply.ReplyMsg, false, true) + sendPkgJson, err := json.Marshal(sendPkg) + if err != nil { + return err + } + if err = am.botConn.WriteMessage(websocket.TextMessage, sendPkgJson); err != nil { + return err + } + return nil +} + func (am *actionManager) DrawbackMsg(msgId int32) error { withDrawPkg := model.GenDrawbackPkg(msgId) withDrawPkgJson, err := json.Marshal(withDrawPkg) diff --git a/constants/gocq_event.go b/constants/gocq_event.go index f47a8ea..8d755b5 100644 --- a/constants/gocq_event.go +++ b/constants/gocq_event.go @@ -5,4 +5,5 @@ const ( GROUP_MSG = "group" PRIVATE_MSG_SEND = "send_private_msg" GROUP_MSG_SEND = "send_group_msg" + FORWARD_MSG_SEND = "send_forward_msg" ) diff --git a/handler/help/help.go b/handler/help/help.go index 23f25e5..6a3fc1f 100644 --- a/handler/help/help.go +++ b/handler/help/help.go @@ -1,6 +1,7 @@ package help import ( + "git.lxtend.com/qqbot/action" "git.lxtend.com/qqbot/constants" "git.lxtend.com/qqbot/handler" "git.lxtend.com/qqbot/message" @@ -35,9 +36,10 @@ func help(msg model.Message) *model.Reply { nodeMsg.Data.UserID = "123456789" nodeMsg.Data.Nickname = "test" nodeMsg.Data.Content = []any{&textMsg} - return &model.Reply{ + action.ActionManager.SendForward(&model.Reply{ ReplyMsg: []any{&nodeMsg}, ReferOriginMsg: false, FromMsg: msg, - } + }) + return nil } diff --git a/model/upstream_message.go b/model/upstream_message.go index 387e14b..4552b37 100644 --- a/model/upstream_message.go +++ b/model/upstream_message.go @@ -14,32 +14,52 @@ type SendPkg struct { // 上游包的参数结构体 type UpstreamParams struct { - UserID int64 `json:"user_id"` - GroupID int64 `json:"group_id"` - Message interface{} `json:"message"` - AutoEscape bool `json:"auto_escape"` + UserID int64 `json:"user_id"` + GroupID int64 `json:"group_id"` + Message any `json:"message"` + AutoEscape bool `json:"auto_escape"` } -func GenSendPkg(userID int64, groupID int64, message interface{}, autoEscape bool) SendPkg { +func GenSendPkg(userID int64, groupID int64, message any, autoEscape bool, forward bool) SendPkg { if groupID == 0 { + if forward { + return SendPkg{ + Action: constants.FORWARD_MSG_SEND, + Params: UpstreamParams{ + UserID: userID, + Message: message, + }, + } + } else { + return SendPkg{ + Action: constants.PRIVATE_MSG_SEND, + Params: UpstreamParams{ + UserID: userID, + Message: message, + AutoEscape: autoEscape, + }, + } + } + } + if forward { return SendPkg{ - Action: constants.PRIVATE_MSG_SEND, + Action: constants.FORWARD_MSG_SEND, + Params: UpstreamParams{ + UserID: userID, + Message: message, + }, + } + } else { + return SendPkg{ + Action: constants.GROUP_MSG_SEND, Params: UpstreamParams{ UserID: userID, + GroupID: groupID, Message: message, AutoEscape: autoEscape, }, } } - return SendPkg{ - Action: constants.GROUP_MSG_SEND, - Params: UpstreamParams{ - UserID: userID, - GroupID: groupID, - Message: message, - AutoEscape: autoEscape, - }, - } } // 事件的消息结构体