diff --git a/state/state_events.go b/state/state_events.go index c58e72e..8b1f3c1 100644 --- a/state/state_events.go +++ b/state/state_events.go @@ -50,6 +50,13 @@ func (s *State) hookSession() { func (s *State) onEvent(iface interface{}) { switch ev := iface.(type) { case *gateway.ReadyEvent: + // Reset the store before proceeding. + if resetter, ok := s.Store.(StoreResetter); ok { + if err := resetter.Reset(); err != nil { + s.stateErr(err, "Failed to reset state on READY") + } + } + // Set Ready to the state s.Ready = *ev diff --git a/state/store.go b/state/store.go index 855aa86..90af77a 100644 --- a/state/store.go +++ b/state/store.go @@ -92,6 +92,12 @@ type StoreModifier interface { VoiceStateRemove(guildID discord.GuildID, userID discord.UserID) error } +// StoreResetter is used by the state to reset the store on every Ready event. +type StoreResetter interface { + // Reset resets the store to a new valid instance. + Reset() error +} + // ErrStoreNotFound is an error that a store can use to return when something // isn't in the storage. There is no strict restrictions on what uses this (the // default one does, though), so be advised.