Browse Source

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

Bruce Marriner 8 years ago
parent
commit
f4f68879ab
2 changed files with 13 additions and 20 deletions
  1. 12 20
      state.go
  2. 1 0
      structs.go

+ 12 - 20
state.go

@@ -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 {
-	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
 	// 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 _, state := range guild.VoiceStates {
+		for i, state := range guild.VoiceStates {
 			if state.UserID == update.UserID {
 			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)
-		}
+		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

+ 1 - 0
structs.go

@@ -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.