fix: 修改消息结构,将 OriginMsgId 类型从 int32 更改为 string

This commit is contained in:
lixiangwuxian 2025-06-16 14:03:01 +08:00
parent bf1b0f391f
commit e5736ab26f
6 changed files with 11 additions and 8 deletions

View File

@ -42,7 +42,7 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
replyMsg := qq_message.ReplyMessage{ replyMsg := qq_message.ReplyMessage{
Type: "reply", Type: "reply",
Data: qq_message.ReplyMessageData{ Data: qq_message.ReplyMessageData{
ID: int(reply.FromMsg.OriginMsgId), ID: reply.FromMsg.OriginMsgId,
}, },
} }
switch replyMsgVal := reply.ReplyMsg.(type) { switch replyMsgVal := reply.ReplyMsg.(type) {

View File

@ -5,7 +5,7 @@ import "git.lxtend.com/lixiangwuxian/qqbot/qq_message"
type Message struct { type Message struct {
UserId int64 `json:"userId"` UserId int64 `json:"userId"`
GroupInfo GroupInfo `json:"groupInfo"` GroupInfo GroupInfo `json:"groupInfo"`
OriginMsgId int32 `json:"originMsgId"` OriginMsgId string `json:"originMsgId"`
RawMsg string `json:"msg"` RawMsg string `json:"msg"`
StructuredMsg []qq_message.QQMessage `json:"structuredMsg"` StructuredMsg []qq_message.QQMessage `json:"structuredMsg"`
UserNickName string `json:"userNickName"` UserNickName string `json:"userNickName"`

View File

@ -54,7 +54,7 @@ func CreateMessage(messageType string) (QQMessage, error) {
func ParseStructMessages(msgData any) []QQMessage { func ParseStructMessages(msgData any) []QQMessage {
log.Println("解析消息数组:", msgData) log.Println("解析消息数组:", msgData)
switch msgData := msgData.(type) { switch msgData := msgData.(type) {
case []interface{}: case []any:
msgArray := msgData msgArray := msgData
messages := make([]QQMessage, 0, len(msgArray)) messages := make([]QQMessage, 0, len(msgArray))
for _, raw := range msgArray { for _, raw := range msgArray {

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"regexp" "regexp"
"strconv"
"strings" "strings"
) )
@ -20,7 +21,7 @@ type ImageMessageData struct {
Key string `json:"key,omitzero"` Key string `json:"key,omitzero"`
EmojiID string `json:"emoji_id,omitzero"` EmojiID string `json:"emoji_id,omitzero"`
PackageID string `json:"emoji_package_id,omitzero"` PackageID string `json:"emoji_package_id,omitzero"`
SubType string `json:"sub_type,omitzero"` SubType int `json:"sub_type,omitzero"`
FileID string `json:"file_id,omitzero"` FileID string `json:"file_id,omitzero"`
FileSize string `json:"file_size,omitzero"` FileSize string `json:"file_size,omitzero"`
FileUnique string `json:"file_unique,omitzero"` FileUnique string `json:"file_unique,omitzero"`
@ -93,7 +94,7 @@ func (msg *ImageMessage) ParseMessage(data string) error {
msg.Data.Key = attrs["key"] msg.Data.Key = attrs["key"]
msg.Data.EmojiID = attrs["emoji_id"] msg.Data.EmojiID = attrs["emoji_id"]
msg.Data.PackageID = attrs["emoji_package_id"] msg.Data.PackageID = attrs["emoji_package_id"]
msg.Data.SubType = attrs["sub_type"] msg.Data.SubType, _ = strconv.Atoi(attrs["sub_type"])
msg.Data.FileID = attrs["file_id"] msg.Data.FileID = attrs["file_id"]
msg.Data.FileSize = attrs["file_size"] msg.Data.FileSize = attrs["file_size"]
msg.Data.FileUnique = attrs["file_unique"] msg.Data.FileUnique = attrs["file_unique"]

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"strconv"
) )
// ReplyMessage 回复消息 // ReplyMessage 回复消息
@ -13,7 +14,7 @@ type ReplyMessage struct {
} }
type ReplyMessageData struct { type ReplyMessageData struct {
ID int `json:"id"` ID string `json:"id"`
} }
func init() { func init() {
@ -49,6 +50,6 @@ func (msg *ReplyMessage) ParseMessage(data string) error {
if err != nil { if err != nil {
return fmt.Errorf("解析回复ID失败: %v", err) return fmt.Errorf("解析回复ID失败: %v", err)
} }
msg.Data.ID = id msg.Data.ID = strconv.Itoa(id)
return nil return nil
} }

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"net/url" "net/url"
"runtime/debug" "runtime/debug"
"strconv"
"sync" "sync"
"time" "time"
@ -74,7 +75,7 @@ func (c *WebSocketClient) receiveMessages() {
} }
msg := model.Message{ msg := model.Message{
UserId: event.UserID, UserId: event.UserID,
OriginMsgId: event.MessageID, OriginMsgId: strconv.Itoa(int(event.MessageID)),
RawMsg: event.RawMessage, RawMsg: event.RawMessage,
StructuredMsg: qq_message.ParseStructMessages(event.Message), StructuredMsg: qq_message.ParseStructMessages(event.Message),
UserNickName: event.Sender.Nickname, UserNickName: event.Sender.Nickname,