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:
parent
c84d583235
commit
5c78174d1c
@ -73,29 +73,33 @@ 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)
|
||||||
var attr StoredMessageAttribute
|
if grpmsg.AttributeID != 0 {
|
||||||
s.RLock()
|
var attr StoredMessageAttribute
|
||||||
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(grpmsg.AttributeID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(grpmsg.AttributeID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.Attribute = &db.StoredMessageAttribute{
|
if err == nil {
|
||||||
MessageSeq: attr.MessageSeq,
|
ret.Attribute = &db.StoredMessageAttribute{
|
||||||
InternalID: attr.InternalID,
|
MessageSeq: attr.MessageSeq,
|
||||||
SenderUin: attr.SenderUin,
|
InternalID: attr.InternalID,
|
||||||
SenderName: attr.SenderName,
|
SenderUin: attr.SenderUin,
|
||||||
Timestamp: attr.Timestamp,
|
SenderName: attr.SenderName,
|
||||||
|
Timestamp: attr.Timestamp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var quoinf QuotedInfo
|
if grpmsg.QuotedInfoID != 0 {
|
||||||
s.RLock()
|
var quoinf QuotedInfo
|
||||||
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(grpmsg.QuotedInfoID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(grpmsg.QuotedInfoID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.QuotedInfo = &db.QuotedInfo{
|
if err == nil {
|
||||||
PrevID: quoinf.PrevID,
|
ret.QuotedInfo = &db.QuotedInfo{
|
||||||
PrevGlobalID: quoinf.PrevGlobalID,
|
PrevID: quoinf.PrevID,
|
||||||
|
PrevGlobalID: quoinf.PrevGlobalID,
|
||||||
|
}
|
||||||
|
_ = 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,29 +119,33 @@ 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)
|
||||||
var attr StoredMessageAttribute
|
if privmsg.AttributeID != 0 {
|
||||||
s.RLock()
|
var attr StoredMessageAttribute
|
||||||
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(privmsg.AttributeID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3MessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(privmsg.AttributeID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.Attribute = &db.StoredMessageAttribute{
|
if err == nil {
|
||||||
MessageSeq: attr.MessageSeq,
|
ret.Attribute = &db.StoredMessageAttribute{
|
||||||
InternalID: attr.InternalID,
|
MessageSeq: attr.MessageSeq,
|
||||||
SenderUin: attr.SenderUin,
|
InternalID: attr.InternalID,
|
||||||
SenderName: attr.SenderName,
|
SenderUin: attr.SenderUin,
|
||||||
Timestamp: attr.Timestamp,
|
SenderName: attr.SenderName,
|
||||||
|
Timestamp: attr.Timestamp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var quoinf QuotedInfo
|
if privmsg.QuotedInfoID != 0 {
|
||||||
s.RLock()
|
var quoinf QuotedInfo
|
||||||
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(privmsg.QuotedInfoID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(privmsg.QuotedInfoID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.QuotedInfo = &db.QuotedInfo{
|
if err == nil {
|
||||||
PrevID: quoinf.PrevID,
|
ret.QuotedInfo = &db.QuotedInfo{
|
||||||
PrevGlobalID: quoinf.PrevGlobalID,
|
PrevID: quoinf.PrevID,
|
||||||
|
PrevGlobalID: quoinf.PrevGlobalID,
|
||||||
|
}
|
||||||
|
_ = 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,29 +163,33 @@ 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)
|
||||||
var attr StoredGuildMessageAttribute
|
if guildmsg.AttributeID != 0 {
|
||||||
s.RLock()
|
var attr StoredGuildMessageAttribute
|
||||||
err = s.db.Find(Sqlite3GuildMessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(guildmsg.AttributeID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3GuildMessageAttributeTableName, &attr, "WHERE ID="+strconv.FormatInt(guildmsg.AttributeID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.Attribute = &db.StoredGuildMessageAttribute{
|
if err == nil {
|
||||||
MessageSeq: uint64(attr.MessageSeq),
|
ret.Attribute = &db.StoredGuildMessageAttribute{
|
||||||
InternalID: uint64(attr.InternalID),
|
MessageSeq: uint64(attr.MessageSeq),
|
||||||
SenderTinyID: uint64(attr.SenderTinyID),
|
InternalID: uint64(attr.InternalID),
|
||||||
SenderName: attr.SenderName,
|
SenderTinyID: uint64(attr.SenderTinyID),
|
||||||
Timestamp: attr.Timestamp,
|
SenderName: attr.SenderName,
|
||||||
|
Timestamp: attr.Timestamp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var quoinf QuotedInfo
|
if guildmsg.QuotedInfoID != 0 {
|
||||||
s.RLock()
|
var quoinf QuotedInfo
|
||||||
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(guildmsg.QuotedInfoID, 10))
|
s.RLock()
|
||||||
s.RUnlock()
|
err = s.db.Find(Sqlite3QuotedInfoTableName, &quoinf, "WHERE ID="+strconv.FormatInt(guildmsg.QuotedInfoID, 10))
|
||||||
if err == nil {
|
s.RUnlock()
|
||||||
ret.QuotedInfo = &db.QuotedInfo{
|
if err == nil {
|
||||||
PrevID: quoinf.PrevID,
|
ret.QuotedInfo = &db.QuotedInfo{
|
||||||
PrevGlobalID: quoinf.PrevGlobalID,
|
PrevID: quoinf.PrevID,
|
||||||
|
PrevGlobalID: quoinf.PrevGlobalID,
|
||||||
|
}
|
||||||
|
_ = 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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user