1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-30 18:53:30 +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)
}
// NewFromSession never returns an error. This API is kept for backwards
// compatibility.
func NewFromSession(s *session.Session, store Store) (*State, error) {
state := &State{
Session: s,
@ -121,8 +123,8 @@ func NewFromSession(s *session.Session, store Store) (*State, error) {
unavailableGuilds: moreatomic.NewSnowflakeSet(),
unreadyGuilds: moreatomic.NewSnowflakeSet(),
}
return state, state.hookSession()
state.hookSession()
return state, nil
}
// 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.
s.onEvent(event)
// Always call the event on function exit. Extra events constructed by
// handlers will be called before the main event, but that's fine.
defer s.Handler.Call(event)
switch e := event.(type) {
switch event := event.(type) {
case *gateway.ReadyEvent:
s.handleReady(e)
return
s.Handler.Call(event)
s.handleReady(event)
case *gateway.GuildCreateEvent:
s.handleGuildCreate(e)
return
s.Handler.Call(event)
s.handleGuildCreate(event)
case *gateway.GuildDeleteEvent:
s.handleGuildDelete(e)
return
s.Handler.Call(event)
s.handleGuildDelete(event)
// https://github.com/discord/discord-api-docs/commit/01665c4
case *gateway.MessageCreateEvent:
if e.Member != nil {
e.Member.User = e.Author
if event.Member != nil {
event.Member.User = event.Author
}
s.Handler.Call(event)
case *gateway.MessageUpdateEvent:
if e.Member != nil {
e.Member.User = e.Author
if event.Member != nil {
event.Member.User = event.Author
}
s.Handler.Call(event)
default:
s.Handler.Call(event)
}
})
}