Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. public static async Task UpdateVoiceChannel ( SocketVoiceChannel voice ) {
  2.             Game highestGame = new Game ("", "", StreamType.NotStreaming);
  3.  
  4.             if (voice != null && allVoiceChannels.ContainsKey (voice.Id)) {
  5.  
  6.                 if (voice.Name == afkChannel.name)
  7.                     return;
  8.  
  9.                 if (voice.Users.Count () == 0)
  10.                     allVoiceChannels[voice.Id].Unlock (false);
  11.  
  12.                 Dictionary<Game, int> numPlayers = new Dictionary<Game, int> ();
  13.                 List<SocketGuildUser> users = voice.Users.ToList ();
  14.                 foreach (SocketGuildUser user in users) {
  15.  
  16.                     SocketGuildUser forcedUser = Program.GetServer().GetUser (user.Id);
  17.                     if (forcedUser.Game.HasValue) {
  18.                         if (numPlayers.ContainsKey (user.Game.Value)) {
  19.                             numPlayers[forcedUser.Game.Value]++;
  20.                         } else {
  21.                             numPlayers.Add (forcedUser.Game.Value, 1);
  22.                         }
  23.                     }
  24.  
  25.                 }
  26.  
  27.                 int highest = int.MinValue;
  28.  
  29.                 for (int i = 0; i < numPlayers.Count; i++) {
  30.                     KeyValuePair<Game, int> value = numPlayers.ElementAt (i);
  31.  
  32.                     if (value.Value > highest) {
  33.                         highest = value.Value;
  34.                         highestGame = value.Key;
  35.                     }
  36.                 }
  37.  
  38.                 string lockString = allVoiceChannels[voice.Id].IsLocked () ? lockIcon : "";
  39.                 // Trying to optimize API calls here, just to spare those poor souls at the Discord API HQ stuff
  40.                 string newName = highestGame.Name != "" ? lockString + allVoiceChannels[voice.Id].name + " - " + highestGame.Name : lockString + allVoiceChannels[voice.Id].name;
  41.                 if (voice.Name != newName) {
  42.                     ChatLogger.Log ("Channel name updated: " + newName);
  43.                     await voice.ModifyAsync ((delegate ( VoiceChannelProperties properties ) { properties.Name = newName; } ));
  44.                 }
  45.                 allVoiceChannels[voice.Id].CheckLocker ();
  46.             }
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement