예제 #1
0
async def gotgud(ctx):
    query = Query()
    gitgud_util = Gitgud_utils()
    username = query.get_handle(ctx.author.id, ctx.get_guild().id)

    if username is None:
        return await ctx.respond("You are not linked with a DMOJ Account")

    user = await query.get_user(username)
    current = gitgud_util.get_current(username, ctx.get_guild().id)
    closest = -1000
    for key in RATING_TO_POINT:
        if abs(key - user.rating) <= abs(closest - user.rating):
            closest = key

    # convert rating to point and get difference
    rating_point = RATING_TO_POINT[closest]
    if current is None or current.problem_id is None:
        return await ctx.respond("No pending challenges")

    # check if user is scamming the bot :monkey:
    if gitgud_util.has_solved(username, current.problem_id):
        # get closest rating
        closest = -1000
        for key in RATING_TO_POINT:
            if abs(key - user.rating) <= abs(closest - user.rating):
                closest = key
        # convert rating to point and get difference
        rating_point = RATING_TO_POINT[closest]
        point_diff = POINT_VALUES.index(current.point) - POINT_VALUES.index(rating_point)

        point = 10 + 2 * (point_diff)
        point = max(point, 0)

        gitgud_util.insert(username, ctx.get_guild().id, point, current.problem_id, datetime.now())
        gitgud_util.clear(username, ctx.get_guild().id)

        completion_time = datetime.now() - current.time
        # convert from timedelta to readable string
        ret = ""
        cnt = 0
        if completion_time.days // 365 != 0:
            ret += f" {completion_time.days // 365} years"
            cnt += 1
        if completion_time.days % 365 != 0:
            ret += f" {completion_time.days % 365} days"
            cnt += 1
        if completion_time.seconds // 3600 != 0:
            ret += f" {completion_time.seconds // 3600} hours"
            cnt += 1
        if cnt < 3 and completion_time.seconds % 3600 // 60 != 0:
            ret += f" {completion_time.seconds % 3600 // 60} minutes"
            cnt += 1
        if cnt < 3 and completion_time.seconds % 60 != 0:
            ret += f" {completion_time.seconds % 60} seconds"

        return await ctx.respond(f"Challenge took{ret}. " f"{current.handle} gained {point} points")

    else:
        return await ctx.respond("You have not completed the challenge")
예제 #2
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)
예제 #3
0
async def nogud(ctx):
    query = Query()
    gitgud_util = Gitgud_utils()

    username = query.get_handle(ctx.author.id, ctx.get_guild().id)

    if username is None:
        return await ctx.respond("You do not have a linked DMOJ account")

    current = gitgud_util.get_current(username, ctx.get_guild().id)
    if current is None or current.problem_id is None:
        return await ctx.respond("Nothing to cancel")

    gitgud_util.clear(username, ctx.get_guild().id)
    return await ctx.respond("Challenge skipped")
예제 #4
0
파일: gitgud.py 프로젝트: Aaerialys/JOMD
    async def nogud(self, ctx):
        '''
        Cancels any unfinished challenge
        '''
        query = Query()
        gitgud_util = Gitgud_utils()

        username = query.get_handle(ctx.author.id, ctx.guild.id)

        if username is None:
            return await ctx.send('You do not have a linked DMOJ account')

        current = gitgud_util.get_current(username, ctx.guild.id)
        if current is None or current.problem_id is None:
            return await ctx.send('Nothing to cancel')

        gitgud_util.clear(username, ctx.guild.id)
        return await ctx.send('Challenge skipped')
예제 #5
0
파일: gitgud.py 프로젝트: jacklee1792/JOMD
    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)
예제 #6
0
파일: gitgud.py 프로젝트: deruikong/JOMD
	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(f"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 current.point == 0 and await query.solved(username, current.problem_id):
				gitgud_util.clear(username, ctx.guild.id)
			else:
				problem = await query.get_problem(current.problem_id)
				embed = discord.Embed(
					description=f"You currently have an uncompleted challenge, [{problem.name}](https://dmoj.ca/{problem.code})"
				)
				return await ctx.send(embed=embed)

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

		filters = filter_list

		result = await query.get_unsolved_problem(username, ctx.guild.id, 1, filters, points[0], points[1])
		if result is None:
			return await ctx.send("No problems that satisfies the filter")
		return await ctx.send(embed=result)