feat: 添加 SendForward 函数以支持消息转发,并更新 GenSendPkg 函数以处理转发逻辑
This commit is contained in:
parent
58cc070c81
commit
6b43a7bb4e
@ -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)
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -16,12 +16,21 @@ type SendPkg struct {
|
||||
type UpstreamParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
GroupID int64 `json:"group_id"`
|
||||
Message interface{} `json:"message"`
|
||||
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{
|
||||
@ -31,6 +40,16 @@ func GenSendPkg(userID int64, groupID int64, message interface{}, autoEscape boo
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
if forward {
|
||||
return SendPkg{
|
||||
Action: constants.FORWARD_MSG_SEND,
|
||||
Params: UpstreamParams{
|
||||
UserID: userID,
|
||||
Message: message,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
return SendPkg{
|
||||
Action: constants.GROUP_MSG_SEND,
|
||||
Params: UpstreamParams{
|
||||
@ -41,6 +60,7 @@ func GenSendPkg(userID int64, groupID int64, message interface{}, autoEscape boo
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 事件的消息结构体
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user