From 169f1761927b858027ae29678cd1cbc3b9334e2a Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Thu, 10 Apr 2025 00:37:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20SendMsg=20?= =?UTF-8?q?=E5=92=8C=20SendForward=20=E5=87=BD=E6=95=B0=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7ID=E5=92=8C=E7=BE=A4=E7=BB=84ID=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?=E7=81=B5=E6=B4=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/action.go | 21 +++++++++++++++++++-- model/upstream_message.go | 12 ++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/action/action.go b/action/action.go index 954ce8b..20b6f8c 100644 --- a/action/action.go +++ b/action/action.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "strconv" "sync" "time" @@ -46,7 +47,15 @@ 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, false) + userID := strconv.FormatInt(reply.FromMsg.UserId, 10) + if reply.FromMsg.UserId == 0 { + userID = "" + } + groupID := strconv.FormatInt(reply.FromMsg.GroupInfo.GroupId, 10) + if reply.FromMsg.GroupInfo.GroupId == 0 { + groupID = "" + } + sendPkg := model.GenSendPkg(userID, groupID, reply.ReplyMsg, false, false) sendPkgJson, err := json.Marshal(sendPkg) if err != nil { return err @@ -63,7 +72,15 @@ func (am *actionManager) SendMsg(reply *model.Reply) error { 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) + userID := strconv.FormatInt(reply.FromMsg.UserId, 10) + if reply.FromMsg.UserId == 0 { + userID = "" + } + groupID := strconv.FormatInt(reply.FromMsg.GroupInfo.GroupId, 10) + if reply.FromMsg.GroupInfo.GroupId == 0 { + groupID = "" + } + sendPkg := model.GenSendPkg(userID, groupID, reply.ReplyMsg, false, true) sendPkgJson, err := json.Marshal(sendPkg) log.Println(string(sendPkgJson)) if err != nil { diff --git a/model/upstream_message.go b/model/upstream_message.go index 4552b37..f2ad426 100644 --- a/model/upstream_message.go +++ b/model/upstream_message.go @@ -14,14 +14,14 @@ type SendPkg struct { // 上游包的参数结构体 type UpstreamParams struct { - UserID int64 `json:"user_id"` - GroupID int64 `json:"group_id"` - Message any `json:"message"` - AutoEscape bool `json:"auto_escape"` + UserID string `json:"user_id,omitempty"` + GroupID string `json:"group_id,omitempty"` + Message any `json:"message"` + AutoEscape bool `json:"auto_escape,omitempty"` } -func GenSendPkg(userID int64, groupID int64, message any, autoEscape bool, forward bool) SendPkg { - if groupID == 0 { +func GenSendPkg(userID string, groupID string, message any, autoEscape bool, forward bool) SendPkg { + if groupID == "" { if forward { return SendPkg{ Action: constants.FORWARD_MSG_SEND,