private async Task <PairInSecretRoom> MoveToPrivateLobbyAsync(UsersPairMatch pair) { //DebugLogWriteLine($"Moving {pair.A} and {pair.B} to room... "); UsersInLobbies.Remove(pair.A.User); UsersInLobbies.Remove(pair.B.User); var privateRoom = await Guild.CreateChannelAsync($"Secret Room {Guid.NewGuid().ToString()}", ChannelType.Voice, DateSecretCategory , overwrites : new DiscordOverwriteBuilder[] { SecretRoomOverwriteBuilder }); SecretRooms.Add(privateRoom); DebugLogWrite("room created... "); var timeout = DateTime.Now.AddMilliseconds(SecretRoomTime); pair.A.State.EnteredPrivateRoomTime = pair.B.State.EnteredPrivateRoomTime = timeout; var p = new PairInSecretRoom() { Users = new List <DiscordMember>() { pair.A.User, pair.B.User }, SecretRoom = privateRoom, Timeout = timeout }; PairsInSecretRooms.Add(p); DebugLogWrite("moving... "); _ = privateRoom.PlaceMemberAsync(pair.A.User).ConfigureAwait(false); _ = privateRoom.PlaceMemberAsync(pair.B.User).ConfigureAwait(false); pair.A.State.AddMatch(pair.B.User.Id); pair.B.State.AddMatch(pair.A.User.Id); DebugLogWrite("finished"); return(p); }
//public void ApplyGenderAndOptionReactions(DiscordUser user, DiscordEmoji emoji) { // AllUserStates.TryGetValue(user.Id, out var uState); // if (uState == null) { // uState = new UserState() { UserId = user.Id }; // AllUserStates.Add(user.Id, uState); // } // if (emoji == MaleEmoji) { // uState.Gender = GenderEnum.Male; // WelcomeMessage.DeleteReactionAsync(MaleEmoji, user); // uState.AgeOptions = 0; // } else if (emoji == FemaleEmoji) { // uState.Gender = GenderEnum.Female; // WelcomeMessage.DeleteReactionAsync(FemaleEmoji, user); // uState.AgeOptions = 0; // } else { // var option = OptionEmojis.IndexOf(emoji); // uState.AgeOptions ^= option; //toggle age group // } //} /// <summary> /// Checks lobbies, cleans them, refreshes users, checks secret rooms updates timeouts, cleans them /// TODO change secret room behaviour /// </summary> /// <returns></returns> async Task VoiceChannelsInitAsync() { //Clean lobbies await CombLobbies().ConfigureAwait(false); //check users in lobbies RefreshUsersInLobbies(); //check secret rooms PairsInSecretRooms.Clear(); foreach (var r in SecretRooms.ToArray()) { if (r.Users.Count() > 1) { var uState = AddOrGetUserState(r.Users.First()); var pair = new PairInSecretRoom() { SecretRoom = r, Users = r.Users.ToList() }; //Try get timeout if (uState != null && uState.EnteredPrivateRoomTime.HasValue) { pair.Timeout = uState.EnteredPrivateRoomTime.Value.AddMilliseconds(SecretRoomTime); } else { pair.Timeout = DateTime.Now; } PairsInSecretRooms.Add(pair); _ = TimeoutDisband(pair) .ConfigureAwait(false); } else { SecretRooms.Remove(r); try { await r.DeleteAsync().ConfigureAwait(false); } catch (Exception) { } } } }