2020-06-06 20:47:15 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2020-10-28 22:39:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/gateway"
|
2020-06-06 20:47:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *State) handleReady(ev *gateway.ReadyEvent) {
|
|
|
|
for _, g := range ev.Guilds {
|
|
|
|
// store this so we know when we need to dispatch a belated
|
|
|
|
// GuildReadyEvent
|
|
|
|
if g.Unavailable {
|
|
|
|
s.unreadyGuilds.Add(g.ID)
|
|
|
|
} else {
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildReadyEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildCreateEvent: &g,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *State) handleGuildCreate(ev *gateway.GuildCreateEvent) {
|
2020-11-30 00:57:58 +00:00
|
|
|
switch {
|
2020-06-06 20:47:15 +00:00
|
|
|
// this guild was unavailable, but has come back online
|
2020-11-30 00:57:58 +00:00
|
|
|
case s.unavailableGuilds.Delete(ev.ID):
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildAvailableEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildCreateEvent: ev,
|
|
|
|
})
|
|
|
|
|
2020-11-30 00:57:58 +00:00
|
|
|
// the guild was already unavailable when connecting to the gateway
|
|
|
|
// we can dispatch a belated GuildReadyEvent
|
|
|
|
case s.unreadyGuilds.Delete(ev.ID):
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildReadyEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildCreateEvent: ev,
|
|
|
|
})
|
2020-11-30 00:57:58 +00:00
|
|
|
|
|
|
|
// we don't know this guild, hence we just joined it
|
|
|
|
default:
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildJoinEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildCreateEvent: ev,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *State) handleGuildDelete(ev *gateway.GuildDeleteEvent) {
|
|
|
|
// store this so we can later dispatch a GuildAvailableEvent, once the
|
|
|
|
// guild becomes available again.
|
|
|
|
if ev.Unavailable {
|
|
|
|
s.unavailableGuilds.Add(ev.ID)
|
|
|
|
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildUnavailableEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildDeleteEvent: ev,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// it might have been unavailable before we left
|
|
|
|
s.unavailableGuilds.Delete(ev.ID)
|
|
|
|
|
2020-06-19 07:33:22 +00:00
|
|
|
s.Handler.Call(&GuildLeaveEvent{
|
2020-06-06 20:47:15 +00:00
|
|
|
GuildDeleteEvent: ev,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|