Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static async Task UpdateVoiceChannel ( SocketVoiceChannel voice ) {
- Game highestGame = new Game ("", "", StreamType.NotStreaming);
- if (voice != null && allVoiceChannels.ContainsKey (voice.Id)) {
- if (voice.Name == afkChannel.name)
- return;
- if (voice.Users.Count () == 0)
- allVoiceChannels[voice.Id].Unlock (false);
- Dictionary<Game, int> numPlayers = new Dictionary<Game, int> ();
- List<SocketGuildUser> users = voice.Users.ToList ();
- foreach (SocketGuildUser user in users) {
- SocketGuildUser forcedUser = Program.GetServer().GetUser (user.Id);
- if (forcedUser.Game.HasValue) {
- if (numPlayers.ContainsKey (user.Game.Value)) {
- numPlayers[forcedUser.Game.Value]++;
- } else {
- numPlayers.Add (forcedUser.Game.Value, 1);
- }
- }
- }
- int highest = int.MinValue;
- for (int i = 0; i < numPlayers.Count; i++) {
- KeyValuePair<Game, int> value = numPlayers.ElementAt (i);
- if (value.Value > highest) {
- highest = value.Value;
- highestGame = value.Key;
- }
- }
- string lockString = allVoiceChannels[voice.Id].IsLocked () ? lockIcon : "";
- // Trying to optimize API calls here, just to spare those poor souls at the Discord API HQ stuff
- string newName = highestGame.Name != "" ? lockString + allVoiceChannels[voice.Id].name + " - " + highestGame.Name : lockString + allVoiceChannels[voice.Id].name;
- if (voice.Name != newName) {
- ChatLogger.Log ("Channel name updated: " + newName);
- await voice.ModifyAsync ((delegate ( VoiceChannelProperties properties ) { properties.Name = newName; } ));
- }
- allVoiceChannels[voice.Id].CheckLocker ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement