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

View file

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