Example #1
0
 async def _match_insert_range(self, ctx, first: int, last: int):
     results = []
     for match_id in range(first, last + 1):
         results.append((await MatchManipulator.insert_match(match_id)))
     results = chunks(results, 25)
     for chunk in results:
         await ctx.send("\n".join(chunk))
Example #2
0
 async def usage(self, ctx):
     pipeline = [
         {
             "$unwind": "$participants"
         },
         {
             "$project": {
                 "_id": 0,
                 "participants.hero": 1
             }
         },
     ]
     documents = await (self.testing_games.aggregate(pipeline=pipeline,
                                                     collation={
                                                         "locale": "en",
                                                         "strength": 1
                                                     })).to_list(length=None
                                                                 )
     heroes = [
         hero_name(document["participants"]["hero"])
         for document in documents
     ]
     counter = collections.Counter(heroes)
     unique_picks = len(heroes)
     message = []
     for hero, times in counter.items():
         message.append(
             f"{hero}: **{times}** ({round((times/unique_picks)*100, 2)}%)")
     message = chunks(sorted(message), 50)
     for chunk in message:
         await ctx.send("\n".join(chunk))
     await ctx.send(
         f"Total Hero picks: **{unique_picks}**\nDifferent Heroes from Hero Pool: **{len(counter)}**"
     )
Example #3
0
 async def _usage_avatar(self, ctx, *name):
     avatar_notation = "".join(name)
     # Ehh, required only for the default avatar. Not properly implemented, alt_avatar is an empty string for these.
     cli_name = avatar_notation.split(".")[0]
     pipeline = [
         {
             "$sort": {
                 "participants.nickname": 1
             }
         },
         {
             "$match": {
                 "participants.hero": cli_name
             }
         },
         {
             "$unwind": "$participants"
         },
         {
             "$match": {
                 "participants.alt_avatar": avatar_notation
             }
         },
         {
             "$project": {
                 "_id": 0,
                 "participants.nickname": 1
             }
         },
     ]
     documents = await (self.testing_games.aggregate(pipeline=pipeline,
                                                     collation={
                                                         "locale": "en",
                                                         "strength": 1
                                                     })).to_list(length=None
                                                                 )
     players = [
         document["participants"]["nickname"] for document in documents
     ]
     counter = collections.Counter(players)
     message = []
     for player, times in counter.items():
         message.append(
             f"{discord.utils.escape_markdown(player)}: **{times}**")
     message = chunks(sorted(message), 50)
     for chunk in message:
         await ctx.send("\n".join(chunk))
     await ctx.send(
         f"Times picked: **{len(players)}**\nTimes picked by a unique player: **{len(counter)}**"
     )
Example #4
0
 async def _usage_hero(self, ctx, *name):
     cli_name = cli_hero_name(" ".join(name))
     pipeline = [
         {
             "$sort": {
                 "participants.nickname": 1
             }
         },
         {
             "$match": {
                 "participants.hero": cli_name
             }
         },
         {
             "$unwind": "$participants"
         },
         {
             "$match": {
                 "participants.hero": cli_name
             }
         },
         {
             "$project": {
                 "_id": 0,
                 "participants.nickname": 1
             }
         },
     ]
     documents = await (self.testing_games.aggregate(pipeline=pipeline,
                                                     collation={
                                                         "locale": "en",
                                                         "strength": 1
                                                     })).to_list(length=None
                                                                 )
     players = [
         document["participants"]["nickname"] for document in documents
     ]
     counter = collections.Counter(players)
     message = []
     for player, times in counter.items():
         message.append(
             f"{discord.utils.escape_markdown(player)}: **{times}**")
     message = chunks(sorted(message), 50)
     for chunk in message:
         await ctx.send("\n".join(chunk))
     await ctx.send(
         f"Times picked: **{len(players)}**\nTimes picked by a unique player: **{len(counter)}**"
     )
Example #5
0
 async def _usage_player(self, ctx, nickname: str):
     nickname = nickname.replace("\\", "")
     pipeline = [
         # {"$sort": {"participants.hero": 1}},
         {
             "$match": {
                 "participants.nickname": nickname
             }
         },
         {
             "$unwind": "$participants"
         },
         {
             "$match": {
                 "participants.nickname": nickname
             }
         },
         {
             "$project": {
                 "_id": 0,
                 "participants.hero": 1
             }
         },
     ]
     documents = await (self.testing_games.aggregate(pipeline=pipeline,
                                                     collation={
                                                         "locale": "en",
                                                         "strength": 1
                                                     })).to_list(length=None
                                                                 )
     heroes = [
         hero_name(document["participants"]["hero"])
         for document in documents
     ]
     counter = collections.Counter(heroes)
     message = []
     for hero, times in counter.items():
         message.append(f"{hero}: **{times}**")
     message = chunks(sorted(message), 50)
     for chunk in message:
         await ctx.send("\n".join(chunk))
     await ctx.send(
         f"Total picks: **{len(heroes)}**\nDifferent Heroes picked: **{len(counter)}**"
     )
Example #6
0
    async def leaderboard(self, ctx, leaderboard="points"):
        """Player performance leaderboards."""
        # These words don't conflict so this approach is fine.
        games = leaderboard.lower() == "games"
        rounds = leaderboard.lower() == "rounds"
        points = leaderboard.lower() == "points"
        if points:
            title = "Points Leaderboard"
            find = {"active": True}
            key = "points"
            icon = ICONS["most_kills"]
        elif games:
            title = "Games Leaderboard"
            find = {"active": True}
            key = "total_games"
            icon = ICONS["matches"]
        elif rounds:
            title = "Rounds Leaderboard"
            find = {"active": True}
            key = "total_rounds"
            icon = ICONS["most_assists"]

        async def get_documents(find: dict, key: str) -> list:
            return await (self.db["PLAYERSTATS"].find(find).sort(
                key, pymongo.DESCENDING).to_list(length=None))

        documents = await get_documents(find, key)
        # Set comprehension to remove duplicates.
        values = [x[key] for x in documents]
        for i, val in enumerate(values):
            if val in values[:i]:
                values[i] = -1
        doc_chunks = chunks(documents, 20)
        embeds = []
        for chunk in doc_chunks:
            placements = []
            names = []
            amounts = []
            for player in chunk:
                place = ordinal(values.index(player[key]) + 1)
                name = f"<@!{player['_id']}>"
                amount = str(player[key])
                lines = ["", "", ""]
                lines[0] = place
                lines[1] = name
                lines[2] = amount
                placements.append(lines[0])
                names.append(lines[1])
                amounts.append(lines[2])
            placements = "\n" + "\n".join(placements) + ""
            names = "\n" + "\n".join(names) + ""
            amounts = "\n" + "\n".join(amounts) + ""
            embed = discord.Embed(
                title=title,
                type="rich",
                color=0xFF6600,
                timestamp=ctx.message.created_at,
            )
            embed.add_field(name="Rank", value=placements)
            embed.add_field(name="Player", value=names)
            embed.add_field(name=title.split(" ")[0], value=amounts)

            embed.set_author(name="Heroes of Newerth Trivia",
                             icon_url="https://i.imgur.com/q8KmQtw.png")
            embed.set_thumbnail(url=icon)
            embed.set_footer(icon_url=ICONS["ladder"])
            embeds.append(embed)

        session = EmbedPaginatorSession(self.bot, ctx, *embeds)
        await session.run()
Example #7
0
    async def leaderboard(self, ctx, *leaderboard):
        """Player performance leaderboards."""
        leaderboard = " ".join(leaderboard)
        # These words don't conflict so this approach is fine.
        games = bool("game" in leaderboard)
        bugs = bool("bug" in leaderboard or "report" in leaderboard)
        total = bool("total" in leaderboard or "all" in leaderboard)
        ranks = bool("rank" in leaderboard or "activity" in leaderboard)

        rank_names = {
            7: "Immortal",
            6: "Legendary",
            5: "Diamond",
            4: "Gold",
            3: "Silver",
            2: "Bronze",
            1: "Warning",
            0: "Unranked",
        }

        if total:
            if games:
                title = "Total Games Leaderboard"
                find = {}
                key = "total_games"
            elif bugs:
                title = "Total Bug Reports Leaderboard"
                find = {}
                key = "total_bugs"
        elif games:
            title = "Games Leaderboard"
            find = {"enabled": True}
            key = "games"
        elif bugs:
            title = "Bug Reports Leaderboard"
            find = {"enabled": True}
            key = "bugs"
        elif ranks:
            title = "Activity Ranks Overview"
            find = {"enabled": True}
            key = "rank_id"
        else:
            title = "Earned Tokens Leaderboard"
            find = {"enabled": True}
            key = "tokens"

        async def get_documents(find: dict, key: str) -> list:
            return await (self.testers.find(
                find, {
                    "_id": 0,
                    "nickname": 1,
                    key: 1
                },
                sort=list({key: -1}.items()))).to_list(length=None)

        documents = await get_documents(find, key)
        values = sorted(
            list({document[key]
                  for document in documents}),
            reverse=True)  # Set comprehension to remove duplicates.
        doc_chunks = chunks(documents, 25)

        embeds = []
        for chunk in doc_chunks:
            description = []
            for player in chunk:

                place = ordinal(values.index(player[key]) + 1)
                name = player["nickname"]
                if not ranks:
                    amount = str(player[key])
                    line = (
                        place + (12 - len(place)) * " " + name +
                        (14 - len(name)) *
                        " "  # Align name left. len(name) <= 12
                        + (10 - len(amount)) *
                        " "  # Align amount right. len(amount) <= 5
                        + amount)
                else:
                    rank = rank_names[player[key]]
                    line = name + (14 - len(name)) * " " + (
                        16 - len(rank)) * " " + rank

                description.append(line)
            description = "```\n" + "\n".join(description) + "```"
            embed = discord.Embed(
                title=title,
                type="rich",
                description=description,
                color=0xFF6600,
                timestamp=ctx.message.created_at,
            )
            embed.set_footer(icon_url="https://i.imgur.com/q8KmQtw.png")
            embed.set_author(name="Retail Candidate Testers",
                             icon_url="https://i.imgur.com/Ou1k4lD.png")
            embeds.append(embed)

        session = EmbedPaginatorSession(self.bot, ctx, *embeds)
        await session.run()