Thanks govet.
This commit is contained in:
parent
8164119cac
commit
6c53613186
2 changed files with 21 additions and 21 deletions
31
state.go
31
state.go
|
@ -594,9 +594,16 @@ func (s *State) Message(channelID, messageID string) (*Message, error) {
|
|||
|
||||
// OnReady takes a Ready event and updates all internal state.
|
||||
func (s *State) onReady(se *Session, r *Ready) (err error) {
|
||||
// We must track at least the current user for Voice, if state is
|
||||
// either nil or disabled, we will set a very simple state item.
|
||||
if s == nil || !se.StateEnabled {
|
||||
if s == nil {
|
||||
return ErrNilState
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
// We must track at least the current user for Voice, even
|
||||
// if state is disabled, store the bare essentials.
|
||||
if !se.StateEnabled {
|
||||
ready := Ready{
|
||||
Version: r.Version,
|
||||
SessionID: r.SessionID,
|
||||
|
@ -604,29 +611,11 @@ func (s *State) onReady(se *Session, r *Ready) (err error) {
|
|||
User: r.User,
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
*s = State{
|
||||
TrackChannels: false,
|
||||
TrackEmojis: false,
|
||||
TrackMembers: false,
|
||||
TrackRoles: false,
|
||||
TrackVoice: false,
|
||||
guildMap: make(map[string]*Guild),
|
||||
channelMap: make(map[string]*Channel),
|
||||
}
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
s.Ready = ready
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
s.Ready = *r
|
||||
|
||||
for _, g := range s.Guilds {
|
||||
|
|
11
wsapi.go
11
wsapi.go
|
@ -47,6 +47,17 @@ func (s *Session) Open() (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
// A basic state is a hard requirement for Voice.
|
||||
if s.State == nil {
|
||||
state := NewState()
|
||||
state.TrackChannels = false
|
||||
state.TrackEmojis = false
|
||||
state.TrackMembers = false
|
||||
state.TrackRoles = false
|
||||
state.TrackVoice = false
|
||||
s.State = state
|
||||
}
|
||||
|
||||
if s.wsConn != nil {
|
||||
err = errors.New("Web socket already opened.")
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue