1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

fix: possible id == 0

This commit is contained in:
源文雨 2022-11-09 16:51:12 +08:00
parent c84d583235
commit 5c78174d1c

View File

@ -73,6 +73,7 @@ func (s *database) GetGroupMessageByGlobalID(id int32) (*db.StoredGroupMessage,
ret.GroupCode = grpmsg.GroupCode ret.GroupCode = grpmsg.GroupCode
ret.AnonymousID = grpmsg.AnonymousID ret.AnonymousID = grpmsg.AnonymousID
_ = json.Unmarshal(utils.S2B(grpmsg.Content), &ret.Content) _ = json.Unmarshal(utils.S2B(grpmsg.Content), &ret.Content)
if grpmsg.AttributeID != 0 {
var attr StoredMessageAttribute var attr StoredMessageAttribute
s.RLock() s.RLock()
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(grpmsg.AttributeID, 10)) err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(grpmsg.AttributeID, 10))
@ -86,6 +87,8 @@ func (s *database) GetGroupMessageByGlobalID(id int32) (*db.StoredGroupMessage,
Timestamp: attr.Timestamp, Timestamp: attr.Timestamp,
} }
} }
}
if grpmsg.QuotedInfoID != 0 {
var quoinf QuotedInfo var quoinf QuotedInfo
s.RLock() s.RLock()
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(grpmsg.QuotedInfoID, 10)) err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(grpmsg.QuotedInfoID, 10))
@ -97,6 +100,7 @@ func (s *database) GetGroupMessageByGlobalID(id int32) (*db.StoredGroupMessage,
} }
_ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent) _ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent)
} }
}
return &ret, nil return &ret, nil
} }
@ -115,6 +119,7 @@ func (s *database) GetPrivateMessageByGlobalID(id int32) (*db.StoredPrivateMessa
ret.SessionUin = privmsg.SessionUin ret.SessionUin = privmsg.SessionUin
ret.TargetUin = privmsg.TargetUin ret.TargetUin = privmsg.TargetUin
_ = json.Unmarshal(utils.S2B(privmsg.Content), &ret.Content) _ = json.Unmarshal(utils.S2B(privmsg.Content), &ret.Content)
if privmsg.AttributeID != 0 {
var attr StoredMessageAttribute var attr StoredMessageAttribute
s.RLock() s.RLock()
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(privmsg.AttributeID, 10)) err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(privmsg.AttributeID, 10))
@ -128,6 +133,8 @@ func (s *database) GetPrivateMessageByGlobalID(id int32) (*db.StoredPrivateMessa
Timestamp: attr.Timestamp, Timestamp: attr.Timestamp,
} }
} }
}
if privmsg.QuotedInfoID != 0 {
var quoinf QuotedInfo var quoinf QuotedInfo
s.RLock() s.RLock()
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(privmsg.QuotedInfoID, 10)) err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(privmsg.QuotedInfoID, 10))
@ -139,6 +146,7 @@ func (s *database) GetPrivateMessageByGlobalID(id int32) (*db.StoredPrivateMessa
} }
_ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent) _ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent)
} }
}
return &ret, nil return &ret, nil
} }
@ -155,6 +163,7 @@ func (s *database) GetGuildChannelMessageByID(id string) (*db.StoredGuildChannel
ret.GuildID = uint64(guildmsg.GuildID) ret.GuildID = uint64(guildmsg.GuildID)
ret.ChannelID = uint64(guildmsg.ChannelID) ret.ChannelID = uint64(guildmsg.ChannelID)
_ = json.Unmarshal(utils.S2B(guildmsg.Content), &ret.Content) _ = json.Unmarshal(utils.S2B(guildmsg.Content), &ret.Content)
if guildmsg.AttributeID != 0 {
var attr StoredGuildMessageAttribute var attr StoredGuildMessageAttribute
s.RLock() s.RLock()
err = s.db.Find(Sqlite3GuildMessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(guildmsg.AttributeID, 10)) err = s.db.Find(Sqlite3GuildMessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(guildmsg.AttributeID, 10))
@ -168,6 +177,8 @@ func (s *database) GetGuildChannelMessageByID(id string) (*db.StoredGuildChannel
Timestamp: attr.Timestamp, Timestamp: attr.Timestamp,
} }
} }
}
if guildmsg.QuotedInfoID != 0 {
var quoinf QuotedInfo var quoinf QuotedInfo
s.RLock() s.RLock()
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(guildmsg.QuotedInfoID, 10)) err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(guildmsg.QuotedInfoID, 10))
@ -179,6 +190,7 @@ func (s *database) GetGuildChannelMessageByID(id string) (*db.StoredGuildChannel
} }
_ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent) _ = json.Unmarshal(utils.S2B(quoinf.QuotedContent), &ret.QuotedInfo.QuotedContent)
} }
}
return &ret, nil return &ret, nil
} }
@ -200,6 +212,9 @@ func (s *database) InsertGroupMessage(msg *db.StoredGroupMessage) error {
})) }))
h.Write(utils.S2B(msg.Attribute.SenderName)) h.Write(utils.S2B(msg.Attribute.SenderName))
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredMessageAttribute{ err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredMessageAttribute{
ID: id, ID: id,
@ -226,6 +241,9 @@ func (s *database) InsertGroupMessage(msg *db.StoredGroupMessage) error {
} }
h.Write(content) h.Write(content)
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{ err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{
ID: id, ID: id,
@ -270,6 +288,9 @@ func (s *database) InsertPrivateMessage(msg *db.StoredPrivateMessage) error {
})) }))
h.Write(utils.S2B(msg.Attribute.SenderName)) h.Write(utils.S2B(msg.Attribute.SenderName))
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredMessageAttribute{ err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredMessageAttribute{
ID: id, ID: id,
@ -296,6 +317,9 @@ func (s *database) InsertPrivateMessage(msg *db.StoredPrivateMessage) error {
} }
h.Write(content) h.Write(content)
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{ err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{
ID: id, ID: id,
@ -338,6 +362,9 @@ func (s *database) InsertGuildChannelMessage(msg *db.StoredGuildChannelMessage)
})) }))
h.Write(utils.S2B(msg.Attribute.SenderName)) h.Write(utils.S2B(msg.Attribute.SenderName))
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredGuildMessageAttribute{ err := s.db.Insert(Sqlite3MessageAttributeTableName, &StoredGuildMessageAttribute{
ID: id, ID: id,
@ -364,6 +391,9 @@ func (s *database) InsertGuildChannelMessage(msg *db.StoredGuildChannelMessage)
} }
h.Write(content) h.Write(content)
id := int64(h.Sum64()) id := int64(h.Sum64())
if id == 0 {
id++
}
s.Lock() s.Lock()
err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{ err = s.db.Insert(Sqlite3QuotedInfoTableName, &QuotedInfo{
ID: id, ID: id,