예제 #1
0
        public async Task SendTopScores(TimePeriod period, int min = 10, int?max = null)
        {
            if (max == null)
            {
                if (min <= MaxDisplayedScores) // Takes a single number as the max if less than the limit
                {
                    max = min;
                    min = 1;
                }
                else
                {
                    max = min + 9;
                }
            }
            if (min < 1 || max < 1 || max < min)
            {
                await ReplyAsync($"Invalid range of scores. Try `{Prefix}help lb` for more info");

                return;
            }

            int amount = Math.Min(MaxDisplayedScores, (int)max - min + 1);

            var scores = Storage.GetScores(period, amount, min - 1);

            if (scores.Count == 0)
            {
                await ReplyAsync($"No scores found in this range{" and period".If(period != TimePeriod.All)}.");

                return;
            }

            var content = new StringBuilder();

            content.Append($"Displaying best scores {period.Humanized()}\nᅠ\n");

            int maxPosDigits   = max.ToString().Length;
            int maxScoreDigits = scores[0].score.ToString().Length;

            for (int i = 0; i < scores.Count; i++)
            {
                ScoreEntry entry = scores[i];

                string result = $"`{$"{min + i}.".Align(maxPosDigits+1)} {$"({entry.state})".Align(6)} " +
                                $"{$"{entry.score}".Align(maxScoreDigits, right: true)} points in {entry.turns} turns";
                content.AppendLine(result.Align(38) + $"- {entry.GetUsername(Context.Client).Replace("`", "")}`");
            }

            if (max - min + 1 > MaxDisplayedScores)
            {
                content.AppendLine($"*Only {MaxDisplayedScores} scores may be displayed at once*");
            }
            if (scores.Count < amount)
            {
                content.AppendLine("*No more scores could be found*");
            }


            var embed = new EmbedBuilder()
            {
                Title       = "🏆 __**Pac-Man Global Leaderboard**__ 🏆",
                Description = content.ToString().Truncate(2047),
                Color       = Colors.PacManYellow
            };

            await ReplyAsync(embed);
        }