示例#1
0
        private async Task MatchingTask()
        {
            //Wait some time
            DebugLogWriteLine("MatchingTask started, waiting");
            await Task.Delay(30000);

            if (!Active)
            {
                DebugLogWriteLine("MatchingTask canceled. Set Active to false");
                return;
            }
            //Get all users
            DebugLogWriteLine("MatchingTask Matching");
            DateVoiceLobbies.Clear();
            DateVoiceLobbies.AddRange(GetVoiceLobbies(true));
            RefreshUsersInLobbies();
            //Match users
            //Move pairs
            TryMatchUsers();

            //Removeitself or restart
            DateVoiceLobbies.Clear();
            DateVoiceLobbies.AddRange(GetVoiceLobbies(true));
            RefreshUsersInLobbies();
            if (UsersInLobbies.Count > 4)
            {
                //Restart? if not same gender
                CurrentMatchingTask = MatchingTask();
                _ = CurrentMatchingTask.ConfigureAwait(false);
            }
            else
            {
                CurrentMatchingTask = null;
            }
        }
示例#2
0
        private async Task CombLobbies()
        {
            //Do we really need this?
            //await Task.Delay(1000);
            //Comb lobbies
            DateVoiceLobbies.Clear();
            DateVoiceLobbies.AddRange(GetVoiceLobbies(true));
            DateVoiceLobbies.Where(l => l.Id != DateVoiceLobbies.Last().Id&& l.Users.Count() == 0)
            .ToList()
            .ForEach(async l => {
                DateVoiceLobbies.Remove(l);
                await l.DeleteAsync();
            });
            int i = 0;

            foreach (var l in DateVoiceLobbies.ToArray())
            {
                await l.ModifyAsync(c => c.Name = $"Date Voice Lobby {i++}");
            }
            if (DateVoiceLobbies.Count == 0 || DateVoiceLobbies.Last().Users.Count() > 0)
            {
                //Add empty at the end
                await AddLastEmptyVoiceLobby();
            }

            CurrentCombLobbiesTask = null;
        }
示例#3
0
        /// <summary>
        /// Gets all channels, members in them and set's up event handlers
        /// </summary>
        /// <param name="guild"></param>
        /// <returns></returns>
        internal async Task Initialize(DiscordGuild guild)
        {
            //DebugLogWriteLine($"Initiating {guild} GuildTask... ");
            //Init guild
            Guild   = guild;
            GuildId = guild.Id;
            SecretRoomOverwriteBuilder = new DiscordOverwriteBuilder();
            SecretRoomOverwriteBuilder.For(Guild.EveryoneRole);
            SecretRoomOverwriteBuilder.Deny(Permissions.AccessChannels);
            //PersonalChannelOverwriteBuilder = new DiscordOverwriteBuilder();
            //PersonalChannelOverwriteBuilder.Allow(Permissions.AccessChannels);

            LogChannel = guild.GetChannel(LogChannelId);
            if (LogChannel != null)
            {
                LogMessage = await LogChannel.SendMessageAsync($"Begin of log {DateTime.Now.ToString()}\n");
            }

            //Init RootCategory
            Guild.Channels.TryGetValue(DateCategoryId, out DiscordChannel cat);
            if (cat == null)
            {
                string m = $"Initialize failed. No Category found on + {DateCategoryId}";
                //DebugLogWriteLine(m);
                throw new Exception(m);
            }
            DateRootCategory = cat;
            Guild.Channels.TryGetValue(DateSecretCategoryId, out DiscordChannel secCat);
            DateSecretCategory = secCat;

            //DebugLogWrite("Initiating voice channels... ");
            //VoiceChannels
            DateVoiceLobbies.Clear();
            SecretRooms.Clear();
            DateVoiceLobbies.AddRange(GetVoiceLobbies());
            SecretRooms.AddRange(GetSecretRooms());
            await VoiceChannelsInitAsync().ConfigureAwait(false);

            if (DateVoiceLobbies.Count == 0 || DateVoiceLobbies.All(c => c.Users.Count() > 0))
            {
                await AddLastEmptyVoiceLobby().ConfigureAwait(false);
            }

            //DebugLogWrite("Initiating Emojis... ");
            //GetEmojis
            MaleEmoji   = DiscordEmoji.FromUnicode(DateBot.Instance.Client, MaleEmojiId);
            FemaleEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, FemaleEmojiId);
            OptionEmojis.Clear();
            OptionEmojis.AddRange(OptionEmojiIds.Select(id => DiscordEmoji.FromUnicode(DateBot.Instance.Client, id)));
            LikeEmoji       = DiscordEmoji.FromUnicode(DateBot.Instance.Client, LikeEmojiId);
            DisLikeEmoji    = DiscordEmoji.FromUnicode(DateBot.Instance.Client, DisLikeEmojiId);
            TimeEmoji       = DiscordEmoji.FromUnicode(DateBot.Instance.Client, TimeEmojiId);
            CancelLikeEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, CancelLikeEmojiId);

            //DebugLogWrite("Initiating Users in lobbies... ");
            //Check and add users in lobbies
            foreach (var u in UsersInLobbies.ToArray())
            {
                AddOrGetUserState(u).LastEnteredLobbyTime = DateTime.Now;
            }

            //DebugLogWrite("Initiating Welcome message... ");
            //Check for welcome message TODO add option emojis
            DateTextChannel = Guild.GetChannel(DateTextChannelId);
            await WelcomeMessageInit().ConfigureAwait(false);

            _ = PrivateControlsMessageInit().ConfigureAwait(false);

            //UpdateTimer = new Timer(TimeSpan.FromSeconds(30).TotalMilliseconds) { AutoReset = true };
            //UpdateTimer.Elapsed += UpdateTimer_Elapsed;
            //UpdateTimer.Start();

            //DebugLogWrite("finished");
            InitTask    = null;
            Initialized = true;

            if (UsersInLobbies.Count > 0)
            {
                TryStartMatchingTask();
            }
        }