From 6b43a7bb4e6e35b8603b91a4b5d413090be4eb8f Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Thu, 10 Apr 2025 00:18:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20SendForward=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BB=A5=E6=94=AF=E6=8C=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=20GenSen?= =?UTF-8?q?dPkg=20=E5=87=BD=E6=95=B0=E4=BB=A5=E5=A4=84=E7=90=86=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/action.go | 16 ++++++++++++- constants/gocq_event.go | 1 + handler/help/help.go | 6 +++-- model/upstream_message.go | 50 +++++++++++++++++++++++++++------------ 4 files changed, 55 insertions(+), 18 deletions(-) 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, - }, - } } // 事件的消息结构体