1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-19 21:32:49 +00:00

state: Handle Thread events

This commit is contained in:
diamondburned 2022-04-01 04:40:15 -07:00
parent 0cc36ee51e
commit fd59b91de1
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -214,6 +214,30 @@ func (s *State) onEvent(iface interface{}) {
case *gateway.ChannelPinsUpdateEvent: case *gateway.ChannelPinsUpdateEvent:
// not tracked. // not tracked.
case *gateway.ThreadListSyncEvent:
for i := range ev.Threads {
if err := s.Cabinet.ChannelSet(&ev.Threads[i], true); err != nil {
s.stateErr(err, "failed to set a thread in state sync")
}
}
case *gateway.ThreadCreateEvent:
if err := s.Cabinet.ChannelSet(&ev.Channel, false); err != nil {
s.stateErr(err, "failed to create a thread in state")
}
case *gateway.ThreadUpdateEvent:
if err := s.Cabinet.ChannelSet(&ev.Channel, true); err != nil {
s.stateErr(err, "failed to update a thread in state")
}
case *gateway.ThreadDeleteEvent:
if ch, err := s.Cabinet.Channel(ev.ID); err == nil {
if err := s.Cabinet.ChannelRemove(ch); err != nil {
s.stateErr(err, "failed to delete a thread in state")
}
}
case *gateway.MessageCreateEvent: case *gateway.MessageCreateEvent:
if err := s.Cabinet.MessageSet(&ev.Message, false); err != nil { if err := s.Cabinet.MessageSet(&ev.Message, false); err != nil {
s.stateErr(err, "failed to add a message in state") s.stateErr(err, "failed to add a message in state")
@ -456,6 +480,15 @@ func storeGuildCreate(cab *store.Cabinet, guild *gateway.GuildCreateEvent) []err
} }
} }
// Handle guild roles
for _, r := range guild.Roles {
r := r
if err := cab.RoleSet(guild.ID, &r, false); err != nil {
errs(err, "failed to set role in Ready")
}
}
return *stack return *stack
} }