feat: 更新 SendMsg 和 SendForward 函数以支持字符串类型的用户ID和群组ID,增强数据处理的灵活性
This commit is contained in:
parent
09b4edf387
commit
169f176192
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -46,7 +47,15 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
|
|||||||
}
|
}
|
||||||
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), reply.ReplyMsg)
|
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)
|
sendPkgJson, err := json.Marshal(sendPkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -63,7 +72,15 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
|
|||||||
func (am *actionManager) SendForward(reply *model.Reply) error {
|
func (am *actionManager) SendForward(reply *model.Reply) error {
|
||||||
am.sendMtx.Lock()
|
am.sendMtx.Lock()
|
||||||
defer am.sendMtx.Unlock()
|
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)
|
sendPkgJson, err := json.Marshal(sendPkg)
|
||||||
log.Println(string(sendPkgJson))
|
log.Println(string(sendPkgJson))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,14 +14,14 @@ type SendPkg struct {
|
|||||||
|
|
||||||
// 上游包的参数结构体
|
// 上游包的参数结构体
|
||||||
type UpstreamParams struct {
|
type UpstreamParams struct {
|
||||||
UserID int64 `json:"user_id"`
|
UserID string `json:"user_id,omitempty"`
|
||||||
GroupID int64 `json:"group_id"`
|
GroupID string `json:"group_id,omitempty"`
|
||||||
Message any `json:"message"`
|
Message any `json:"message"`
|
||||||
AutoEscape bool `json:"auto_escape"`
|
AutoEscape bool `json:"auto_escape,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenSendPkg(userID int64, groupID int64, message any, autoEscape bool, forward bool) SendPkg {
|
func GenSendPkg(userID string, groupID string, message any, autoEscape bool, forward bool) SendPkg {
|
||||||
if groupID == 0 {
|
if groupID == "" {
|
||||||
if forward {
|
if forward {
|
||||||
return SendPkg{
|
return SendPkg{
|
||||||
Action: constants.FORWARD_MSG_SEND,
|
Action: constants.FORWARD_MSG_SEND,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user