1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-04-27 00:05:20 +00:00

Fixed a compile bug

This commit is contained in:
diamondburned (Forefront) 2020-06-19 00:59:44 -07:00
parent 88dd0f8995
commit 01021f0902
2 changed files with 21 additions and 17 deletions

View file

@ -110,6 +110,8 @@ func NewWithStore(token string, store Store) (*State, error) {
return NewFromSession(s, store) return NewFromSession(s, store)
} }
// NewFromSession never returns an error. This API is kept for backwards
// compatibility.
func NewFromSession(s *session.Session, store Store) (*State, error) { func NewFromSession(s *session.Session, store Store) (*State, error) {
state := &State{ state := &State{
Session: s, Session: s,
@ -121,8 +123,8 @@ func NewFromSession(s *session.Session, store Store) (*State, error) {
unavailableGuilds: moreatomic.NewSnowflakeSet(), unavailableGuilds: moreatomic.NewSnowflakeSet(),
unreadyGuilds: moreatomic.NewSnowflakeSet(), unreadyGuilds: moreatomic.NewSnowflakeSet(),
} }
state.hookSession()
return state, state.hookSession() return state, nil
} }
// WithContext returns a shallow copy of State with the context replaced in the // WithContext returns a shallow copy of State with the context replaced in the

View file

@ -17,30 +17,32 @@ func (s *State) hookSession() {
// Run the state handler. // Run the state handler.
s.onEvent(event) s.onEvent(event)
// Always call the event on function exit. Extra events constructed by switch event := event.(type) {
// handlers will be called before the main event, but that's fine.
defer s.Handler.Call(event)
switch e := event.(type) {
case *gateway.ReadyEvent: case *gateway.ReadyEvent:
s.handleReady(e) s.Handler.Call(event)
return s.handleReady(event)
case *gateway.GuildCreateEvent: case *gateway.GuildCreateEvent:
s.handleGuildCreate(e) s.Handler.Call(event)
return s.handleGuildCreate(event)
case *gateway.GuildDeleteEvent: case *gateway.GuildDeleteEvent:
s.handleGuildDelete(e) s.Handler.Call(event)
return s.handleGuildDelete(event)
// https://github.com/discord/discord-api-docs/commit/01665c4 // https://github.com/discord/discord-api-docs/commit/01665c4
case *gateway.MessageCreateEvent: case *gateway.MessageCreateEvent:
if e.Member != nil { if event.Member != nil {
e.Member.User = e.Author event.Member.User = event.Author
} }
s.Handler.Call(event)
case *gateway.MessageUpdateEvent: case *gateway.MessageUpdateEvent:
if e.Member != nil { if event.Member != nil {
e.Member.User = e.Author event.Member.User = event.Author
} }
s.Handler.Call(event)
default:
s.Handler.Call(event)
} }
}) })
} }