Ejemplo n.º 1
0
    async def scoreboard(self, ctx):
        """
        Displays internal CryptoHack scoreboard.
        """
        limit = 10
        mappings = CryptoHackUserMapping.objects.all()
        scores = [
            (
                escape_md(self.bot.get_user(mapping.discord_user_id).name),
                self._get_cryptohack_score(mapping.cryptohack_user),
            )
            for mapping in mappings
        ][:limit]

        scores = sorted(scores, key=lambda s: s[1].points, reverse=True)
        scoreboard = "\n".join(
            "{0}. **{1}**\t{2}".format(idx + 1, s[0], s[1].points)
            for idx, s in enumerate(scores)
        )
        embed = discord.Embed(
            title="CryptoHack Scoreboard",
            colour=discord.Colour(0xFEB32B),
            url="https://cryptohack.org/",
            description=scoreboard,
            timestamp=datetime.datetime.now(),
        )

        embed.set_thumbnail(url="https://cryptohack.org/static/img/main.png")
        embed.set_footer(
            text="CYberMouflons",
            icon_url="https://i.ibb.co/yW2mYjq/cybermouflons.png",
        )

        await ctx.send(embed=embed)
Ejemplo n.º 2
0
    async def scoreboard(self, ctx):
        """
        Displays internal Hack The Box scoreboard.
        """
        limit = 10
        mappings = HTBUserMapping.objects.all()
        scores = [(
            escape_md(self.bot.get_user(mapping.discord_user_id).name),
            self.api_client.parse_user_stats(mapping.htb_user_id),
        ) for mapping in mappings][:limit]

        scores = sorted(scores, key=lambda s: s[1].points, reverse=True)
        scoreboard = "\n".join(
            "{0}. **{1}**\t{2}".format(idx + 1, s[0], s[1].points)
            for idx, s in enumerate(scores))
        embed = discord.Embed(
            title="Hack The Box Scoreboard",
            colour=discord.Colour(0x7ED321),
            url="https://www.hackthebox.eu",
            description=scoreboard,
            timestamp=datetime.datetime.now(),
        )

        embed.set_thumbnail(
            url="https://forum.hackthebox.eu/uploads/RJZMUY81IQLQ.png")
        embed.set_footer(
            text="CYberMouflons",
            icon_url="https://i.ibb.co/yW2mYjq/cybermouflons.png",
        )

        await ctx.send(embed=embed)
Ejemplo n.º 3
0
    async def solve(self, ctx):
        """
        Marks the current challenge as solved by you. Addition of team mates that helped to solve is optional
        """
        chall_name = ctx.channel.name
        ctf = CTF.objects.get({"name": ctx.channel.category.name})

        # Find challenge in CTF by name
        challenge = next((c for c in ctf.challenges if c.name == chall_name),
                         None)

        if not challenge:
            raise NotInChallengeChannelException
        if challenge.solved_at:
            raise ChallengeAlreadySolvedException(challenge.solved_by)

        challenge.solved_by = [ctx.message.author.name
                               ] + [m.name for m in ctx.message.mentions]
        challenge.solved_at = datetime.datetime.now()
        ctf.save()

        solvers_str = escape_md(
            ", ".join([ctx.message.author.name] +
                      [m.name for m in ctx.message.mentions]))
        await ctx.channel.send(
            "Πελλαμός! {0}! Congrats for solving {1}. Έλα κουφεττούα :candy:".
            format(solvers_str, chall_name))
        general_channel = discord.utils.get(ctx.channel.category.channels,
                                            name="general")
        await general_channel.send(
            f"{solvers_str} solved the {chall_name} challenge! :candy: :candy:"
        )
Ejemplo n.º 4
0
    async def solve(self, ctx):
        """
        Marks the current challenge as solved by you. 
        Addition of team mates that helped to solve is optional
        """
        chall_name = ctx.channel.name
        ctf = CTF.objects.get({"name": ctx.channel.category.name})

        # Find challenge in CTF by name
        challenge = next((c for c in ctf.challenges if c.name == chall_name), None)

        if not challenge:
            raise NotInChallengeChannelException
        if challenge.solved_at:
            raise ChallengeAlreadySolvedException(challenge.solved_by)

        challenge.solved_by = [ctx.message.author.name] + [
            m.name for m in ctx.message.mentions
        ]
        challenge.solved_at = datetime.datetime.now()
        ctf.save()

        solvers_str = escape_md(
            ", ".join(
                [ctx.message.author.name] + [m.name for m in ctx.message.mentions]
            )
        )

        # look for difficulty in challenge's tags
        # default to "none" if no matching difficulty is found
        difficulty = "none"
        tags_lower = [x.lower() for x in challenge.tags]
        for d in DIFFICULTY_REWARDS:
            if d.lower() in tags_lower:
                difficulty = d

        reward = DIFFICULTY_REWARDS[difficulty]
        reward_emoji, reward_text = reward
        if isinstance(reward_text, list):
            reward_text = random.choice(reward_text)

        await ctx.channel.send(
            "Πελλαμός! {0}! Congrats for solving {1}. Έλα {2} {3}".format(
                solvers_str, chall_name, reward_text, reward_emoji
            )
        )

        await ctx.channel.edit(name="\N{CHECK MARK}" + chall_name)
        general_channel = discord.utils.get(
            ctx.channel.category.channels, name="general"
        )
        await general_channel.send(
            f"{solvers_str} solved the {chall_name} challenge! {reward_emoji} {reward_emoji}"
        )
Ejemplo n.º 5
0
 async def getscore(mapping):
     return (
         escape_md(self.bot.get_user(mapping.discord_user_id).name),
         self.api_client.parse_user_stats(mapping.htb_user_id),
     )