mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 09:12:53 +00:00
State: Ready events now automatically reset the state
This commit is contained in:
parent
a7e9439109
commit
f0c73f4c99
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue