コード例 #1
0
ファイル: GuildTask.cs プロジェクト: zORg-alex/ZBot
        private async Task TimeoutDisband(PairInSecretRoom pair)
        {
            DateTime?timeout = UpdateTimeout(pair.Users);

            if (pair.Users.Count == 2)
            {
                do
                {
                    DebugLogWrite($" Now: {DateTime.Now} Timeout: {timeout} secrettime: {TimeSpan.FromMilliseconds(SecretRoomTime)}");

                    await Task.Delay(Math.Max((int)(timeout.Value - DateTime.Now).TotalMilliseconds - 61000, 0));

                    if (!PairsInSecretRooms.Contains(pair))
                    {
                        return;                                                         //quit if disbanded outside
                    }
                    timeout = UpdateTimeout(pair.Users);
                    foreach (var p in pair.Users)
                    {
                        _ = p.SendMessageAsync($"{(timeout.Value - DateTime.Now).TotalMinutes.ToString("G2")} min left for {string.Join(", ", pair.Users.Select(p => p.DisplayName))}");
                    }

                    await Task.Delay(Math.Max((int)(timeout.Value - DateTime.Now).TotalMilliseconds + 100, 0));

                    if (!PairsInSecretRooms.Contains(pair))
                    {
                        return;                                                         //quit if disbanded outside
                    }
                    timeout = UpdateTimeout(pair.Users);
                    if (DateTime.Now < timeout.Value)
                    {
                        foreach (var p in pair.Users)
                        {
                            _ = p.SendMessageAsync($"{(timeout.Value - DateTime.Now).TotalMinutes.ToString("G2")} min left for {string.Join(", ", pair.Users.Select(p => p.DisplayName))}").ConfigureAwait(false);
                        }
                    }
                } while (DateTime.Now < timeout.Value);
            }
            //return if timer off
            //else
            DebugLogWriteLine($"Timeout Disbanding {pair.Users[0]} and {pair.Users[1]}");
            foreach (var p in pair.Users.ToArray())
            {
                //Return participants to lobby 0
                ReturnUserToFirstLobbyAvailable(p);
            }
        }
コード例 #2
0
ファイル: GuildTask.cs プロジェクト: zORg-alex/ZBot
        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);
        }
コード例 #3
0
ファイル: GuildTask.cs プロジェクト: zORg-alex/ZBot
        //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) { }
                }
            }
        }