Пример #1
0
    async def private_leaderboard_daily_stats(self,
                                              ctx: commands.Context) -> None:
        """Send an embed with daily completion statistics for the Python Discord leaderboard."""
        try:
            leaderboard = await _helpers.fetch_leaderboard()
        except _helpers.FetchingLeaderboardFailed:
            await ctx.send(":x: Can't fetch leaderboard for stats right now!")
            return

        # The daily stats are serialized as JSON as they have to be cached in Redis
        daily_stats = json.loads(leaderboard["daily_stats"])
        async with ctx.typing():
            lines = [
                "Day   ⭐  ⭐⭐ |   %⭐    %⭐⭐\n================================"
            ]
            for day, stars in daily_stats.items():
                star_one = stars["star_one"]
                star_two = stars["star_two"]
                p_star_one = star_one / leaderboard["number_of_participants"]
                p_star_two = star_two / leaderboard["number_of_participants"]
                lines.append(
                    f"{day:>2}) {star_one:>4}  {star_two:>4} | {p_star_one:>7.2%} {p_star_two:>7.2%}"
                )
            table = "\n".join(lines)
            info_embed = _helpers.get_summary_embed(leaderboard)
            await ctx.send(f"```\n{table}\n```", embed=info_embed)
Пример #2
0
    async def aoc_leaderboard(self, ctx: commands.Context) -> None:
        """Get the current top scorers of the Python Discord Leaderboard."""
        async with ctx.typing():
            try:
                leaderboard = await _helpers.fetch_leaderboard()
            except _helpers.FetchingLeaderboardFailed:
                await ctx.send(":x: Unable to fetch leaderboard!")
                return

            number_of_participants = leaderboard["number_of_participants"]

            top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants)
            header = f"Here's our current top {top_count}! {Emojis.christmas_tree * 3}"

            table = f"```\n{leaderboard['top_leaderboard']}\n```"
            info_embed = _helpers.get_summary_embed(leaderboard)

            await ctx.send(content=f"{header}\n\n{table}", embed=info_embed)