public static IAsyncEnumerable <Challenge> FuzzyFindChallenge(this IChallenges challenges, string search, bool includeUnstarted = false)
        {
            // Try parsing the string as a challenge ID
            var uid = BalderHash.BalderHash32.Parse(search);

            if (uid.HasValue)
            {
                return(challenges.GetChallenges(id: uid.Value.Value, includeUnstarted: includeUnstarted).Take(1));
            }

            // Try searching for a challenge that matches the name
            return(challenges.GetChallenges(name: $"%{search}%"));
        }
Beispiel #2
0
        public async Task Seed()
        {
            await _skill.Clear();

            await foreach (var challenge in _challenges.GetChallenges().Where(a => a.EndTime.HasValue).OrderBy(a => a.EndTime))
            {
                await _updater.ApplyChallengeResults(challenge.Id);

                // Display updated ranks
                StringBuilder s = new($"{challenge.Name}\n");
                s.Append(string.Join("\n",
                                     await _skill.GetTopRanks(int.MaxValue)
                                     .OrderByDescending(a => a.Rating.ConservativeEstimate)
                                     .SelectAwait(FormatRankInfo)
                                     .ToArrayAsync()
                                     ));

                // Display ranks
                await ReplyAsync(s.ToString());

                await Task.Delay(2000);
            }

            await ReplyAsync("Done.");
        }
Beispiel #3
0
 public async Task ListCompetitions()
 {
     await DisplayItemList(
         _challenges.GetChallenges(),
         () => "No challenges",
         (c, i) => $"`[{((uint)c.Id).BalderHash()}]` {c.Name}" + (c.EndTime.HasValue && c.EndTime > DateTime.UtcNow ? " (Current)" : "")
         );
 }
        public async Task ShowPool()
        {
            var none = true;

            await foreach (var challenge in _challenges.GetChallenges(includeUnstarted: true).Where(a => a.EndTime == null))
            {
                none = false;
                await ReplyAsync($" - {challenge.Name} (`{challenge.Id.BalderHash()}`)");

                await Task.Delay(10);
            }

            if (none)
            {
                await ReplyAsync("No challenges in pool :(");
            }
        }
Beispiel #5
0
        public async Task ShowLeaderboard(string id)
        {
            var uid = BalderHash.BalderHash32.Parse(id);

            if (!uid.HasValue)
            {
                await ReplyAsync("That is not a valid challenge ID.");

                return;
            }

            var c = await _challenges.GetChallenges(id : uid.Value.Value).SingleOrDefaultAsync();

            if (c == null)
            {
                await ReplyAsync("Cannot find a challenge with that ID.");

                return;
            }

            await DisplayChallengeLeaderboard(c);
        }
Beispiel #6
0
        public async Task UpdateCurrentMessage(Message message)
        {
            var currentChallenge = await _challenges.GetCurrentChallenge();

            var challenge = await _challenges.GetChallenges(id : message.ChallengeID).FirstAsync();

            if (challenge == null)
            {
                Console.WriteLine("Message exists for inexistant challenge " + message.ChallengeID);
                await RemoveMessage(message);
            }
            else
            {
                if (!(_client.GetChannel(message.ChannelID) is ISocketMessageChannel channel))
                {
                    Console.WriteLine($"No such channel: {message.ChannelID}");
                    await RemoveMessage(message);

                    return;
                }

                if (!((await channel.GetMessageAsync(message.MessageID)) is IUserMessage msg))
                {
                    Console.WriteLine($"No such message: {message.MessageID}");
                    await RemoveMessage(message);

                    return;
                }

                await msg.ModifyAsync(a => a.Embed = challenge.ToEmbed().Build());

                if (currentChallenge == null || challenge.Id != currentChallenge.Id)
                {
                    await RemoveMessage(message);
                }
            }
        }