Merge branch 'develop' of https://github.com/bwmarrin/Discordgo into develop

This commit is contained in:
Bruce Marriner 2016-03-11 13:49:57 -06:00
commit f4f68879ab
2 changed files with 13 additions and 20 deletions

View file

@ -460,40 +460,32 @@ func (s *State) MessageRemove(message *Message) error {
return errors.New("Message not found.") return errors.New("Message not found.")
} }
func (s *State) VoiceStateUpdate(update *VoiceStateUpdate) error { func (s *State) voiceStateUpdate(update *VoiceStateUpdate) error {
var exists bool guild, err := s.Guild(update.GuildID)
var guild *Guild if err != nil {
return err
for _, guild = range s.Guilds {
if guild.ID == update.GuildID {
exists = true
break
}
} }
if !exists { s.Lock()
return nil defer s.Unlock()
}
// Handle Leaving Channel // Handle Leaving Channel
if update.ChannelID == "" { if update.ChannelID == "" {
for i, state := range guild.VoiceStates { for i, state := range guild.VoiceStates {
if state.UserID == update.UserID { if state.UserID == update.UserID {
guild.VoiceStates = append(guild.VoiceStates[:i], guild.VoiceStates[i+1:]...) guild.VoiceStates = append(guild.VoiceStates[:i], guild.VoiceStates[i+1:]...)
return nil
} }
} }
} else { } else {
exists := false for i, state := range guild.VoiceStates {
for _, state := range guild.VoiceStates {
if state.UserID == update.UserID { if state.UserID == update.UserID {
state.ChannelID = update.ChannelID guild.VoiceStates[i] = update.VoiceState
exists = true return nil
} }
} }
if !exists { guild.VoiceStates = append(guild.VoiceStates, update.VoiceState)
guild.VoiceStates = append(guild.VoiceStates, update.VoiceState)
}
} }
return nil return nil
@ -561,7 +553,7 @@ func (s *State) onInterface(se *Session, i interface{}) (err error) {
case *MessageDelete: case *MessageDelete:
err = s.MessageRemove(t.Message) err = s.MessageRemove(t.Message)
case *VoiceStateUpdate: case *VoiceStateUpdate:
err = s.VoiceStateUpdate(t) err = s.voiceStateUpdate(t)
} }
return return

View file

@ -241,6 +241,7 @@ type User struct {
Avatar string `json:"Avatar"` Avatar string `json:"Avatar"`
Verified bool `json:"verified"` Verified bool `json:"verified"`
Discriminator string `json:"discriminator"` Discriminator string `json:"discriminator"`
Bot bool `json:"bot"`
} }
// A Settings stores data for a specific users Discord client settings. // A Settings stores data for a specific users Discord client settings.