state: Fix message.Reactions[].Me not being updated

This commit is contained in:
diamondburned 2023-02-09 21:04:58 -08:00
parent f43b322cec
commit 2c379c90c2
No known key found for this signature in database
GPG Key ID: D78C4471CE776659
1 changed files with 6 additions and 4 deletions

View File

@ -261,16 +261,18 @@ func (s *State) onEvent(iface interface{}) {
}
case *gateway.MessageReactionAddEvent:
var me bool
if u, _ := s.Cabinet.Me(); u != nil {
me = ev.UserID == u.ID
}
s.editMessage(ev.ChannelID, ev.MessageID, func(m *discord.Message) bool {
if i := findReaction(m.Reactions, ev.Emoji); i > -1 {
// Copy the reactions slice so it's not racy.
m.Reactions = append([]discord.Reaction(nil), m.Reactions...)
m.Reactions[i].Count++
m.Reactions[i].Me = me
} else {
var me bool
if u, _ := s.Cabinet.Me(); u != nil {
me = ev.UserID == u.ID
}
old := m.Reactions
m.Reactions = make([]discord.Reaction, 0, len(old)+1)
m.Reactions = append(m.Reactions, old...)