Exemplo n.º 1
0
async def gitgud(ctx: lightbulb.Context) -> None:
    # TODO Fix converters for slash commands
    points = ctx.options.points
    filters = ctx.options.filters
    query = Query()
    gitgud_util = Gitgud_utils()
    # get the user's dmoj handle
    username = query.get_handle(ctx.author.id, ctx.get_guild().id)
    # user = await query.get_user(username)

    if username is None:
        return await ctx.respond("You are not linked to a DMOJ Account. " "Please link your account before continuing")

    user = await query.get_user(username)

    if points is None:
        points = [0, 0]
        closest = -1000
        for key in RATING_TO_POINT:
            if abs(key - user.rating) <= abs(closest - user.rating):
                closest = key
        points[0] = RATING_TO_POINT[closest]
        points[1] = points[0]
    # return if the user haven't finished the previous problem
    current = gitgud_util.get_current(username, ctx.get_guild().id)

    if current is not None and current.problem_id is not None:
        if not gitgud_util.has_solved(username, current.problem_id):
            # User has a current problem unsolved
            problem = await query.get_problem(current.problem_id)
            embed = hikari.Embed(
                description=f"You currently have an uncompleted "
                f"challenge, [{problem.name}]"
                f"(https://dmoj.ca/problem/{problem.code})",
                color=0xFCDB05,
            )
            return await ctx.respond(embed=embed)

    filter_list = []
    for filter in filters:
        if filter in SHORTHANDS:
            filter_list.append(SHORTHANDS[filter])

    filters = filter_list

    embed, problem = await gimme_common(username, points, filters)

    if embed is None:
        return await ctx.respond("No problems that satisfies the filter")

    gitgud_util.bind(username, ctx.get_guild().id, problem.code, problem.points, datetime.now())

    embed.description = "Points: %s\nProblem Types ||%s||" % (problem.points, ", ".join(problem.types))

    return await ctx.respond(embed=embed)
Exemplo n.º 2
0
    async def get_unsolved_problem(self,
                                   username,
                                   guild_id,
                                   increment,
                                   types,
                                   low=1,
                                   high=50):
        unsolved = self.get_unsolved_problems(username, types, low, high)

        if len(unsolved) == 0:
            return None
        problem = random.choice(unsolved)
        gitgud_util = Gitgud_utils()
        gitgud_util.bind(username, guild_id, problem.code,
                         problem.points * increment, datetime.now())

        points = str(problem.points)
        if problem.partial:
            points += 'p'

        memory = problem.memory_limit
        if memory >= 1024 * 1024:
            memory = '%dG' % (memory // 1024 // 1024)
        elif memory >= 1024:
            memory = '%dM' % (memory // 1024)
        else:
            memory = '%dK' % (memory)

        embed = discord.Embed(
            title=problem.name,
            url='https://dmoj.ca/problem/%s' % problem.code,
            description='Points: %s\nProblem Types: ||%s||' %
            (points, ', '.join(problem.types)),
            color=0xfcdb05,
        )

        embed.set_thumbnail(url=await self.get_pfp(username))
        embed.add_field(name='Group', value=problem.group, inline=True)
        embed.add_field(name='Time',
                        value='%ss' % problem.time_limit,
                        inline=True)
        embed.add_field(name='Memory', value=memory, inline=True)
        # print(embed)
        return embed
Exemplo n.º 3
0
    async def gitgud(self, ctx, points: typing.Optional[point_range],
                     *filters):
        """
          Recommend a problem and gain point upon completion

        SHORTHANDS:
        - adhoc
        - math
        - bf
        - ctf
        - ds
        - d&c
        - dp
        - geo
        - gt
        - greedy
        - regex
        - string
        """

        filters = list(filters)
        query = Query()
        gitgud_util = Gitgud_utils()
        # get the user's dmoj handle
        username = query.get_handle(ctx.author.id, ctx.guild.id)
        # user = await query.get_user(username)

        if username is None:
            return await ctx.send("You are not linked to a DMOJ Account. "
                                  "Please link your account before continuing")

        user = await query.get_user(username)

        if points is None:
            points = [0, 0]
            closest = -1000
            for key in RATING_TO_POINT:
                if abs(key - user.rating) <= abs(closest - user.rating):
                    closest = key
            points[0] = RATING_TO_POINT[closest]
            points[1] = points[0]
        # return if the user haven't finished the previous problem
        current = gitgud_util.get_current(username, ctx.guild.id)

        if current is not None and current.problem_id is not None:
            if not gitgud_util.has_solved(username, current.problem_id):
                # User has a current problem unsolved
                problem = await query.get_problem(current.problem_id)
                embed = discord.Embed(
                    description=f"You currently have an uncompleted "
                    f"challenge, [{problem.name}]"
                    f"(https://dmoj.ca/problem/{problem.code})",
                    color=0xfcdb05,
                )
                return await ctx.send(embed=embed)

        filter_list = []
        for filter in filters:
            if filter in SHORTHANDS:
                filter_list.append(SHORTHANDS[filter])

        filters = filter_list

        embed, problem = await gimme_common(username, points, filters)

        if embed is None:
            return await ctx.send("No problems that satisfies the filter")

        gitgud_util.bind(username, ctx.guild.id, problem.code, problem.points,
                         datetime.now())

        embed.description = "Points: %s\nProblem Types ||%s||" % \
                            (problem.points, ', '.join(problem.types))

        return await ctx.send(embed=embed)