Exemple #1
0
	async def gitlog(self, ctx, username=None):
		"""
		Show the past gitgud history of a user
		"""
		query = Query()
		username = username or query.get_handle(ctx.author.id, ctx.guild.id)
		try:
			user = await query.get_user(username)
			username = user.username
		except TypeError:
			username = None
		if username is None:
			return await ctx.send("You have not entered a valid DMOJ handle or linked with a DMOJ Account")

		gitgud_util = Gitgud_utils()
		history = gitgud_util.get_all(username, ctx.guild.id)


		if len(history) == 0:
			embed = discord.Embed(description="User have not completed any challenge")
			return await ctx.send(embed=embed)
		# paginate
		count = 0
		page_cnt = min(10, len(history)//10 + bool(len(history)%10))
		embeds = []
		content = ""
		paginator = Pagination.CustomEmbedPaginator(ctx, timeout=60, remove_reactions=True)
		paginator.add_reaction('⏮️', "first")
		paginator.add_reaction('⏪', "back")
		paginator.add_reaction('⏩', "next")
		paginator.add_reaction('⏭️', "last")
		for solved in history:
			# print(solved.problem_id)
			problem = await query.get_problem(solved.problem_id)
			days = (datetime.now() - solved.time).days
			if days==0:
				days_str = "today"
			elif days==1:
				days_str = "yesterday"
			else:
				days_str = f"{days} days ago"
			content += f"[{problem.name}](https://dmoj.ca/{problem.code}) [+{solved.point}] ({days_str})\n"
			count += 1
			if count % 10 == 0:
				embed = discord.Embed()
				embed.add_field(name=f"Gitgud Log for {username} (page {count//10}/{page_cnt})", value=content, inline=True)
				embeds.append(embed)
				content = ""
			if count == 100:
				break
		if count % 10 != 0:
			embed = discord.Embed()
			embed.add_field(name=f"Gitlog for {username} (page {count//10 + 1}/{page_cnt})", value=content, inline=True)
			embeds.append(embed)
		return await paginator.run(embeds)
Exemple #2
0
 async def ranking(ctx):
     ranking = get_activity_ranking(ctx.guild.id)
     string = ""
     for i, (user, time) in enumerate(ranking):
         tier = get_tier(i)
         if tier not in string:
             string += f"**{tier}:**\n"
         name = user.split("#")[0]
         string += f"{name}: {pretty_time_delta(time)}\n"
     if string == "":
         string = "Todavía no hay un ranking."
     lines_per_page = 17
     pages = get_pages(string, lines_per_page)
     embeds = [discord.Embed().add_field(name="Ranking", value=page)
               for page in pages]
     paginator = Pagination.CustomEmbedPaginator(ctx, auto_footer=True)
     paginator.add_reaction('⏪', "back")
     paginator.add_reaction('⏩', "next")
     await paginator.run(embeds)
Exemple #3
0
    async def gitlog(self, ctx, username=None):
        '''
        Show the past gitgud history of a user
        '''
        query = Query()
        username = username or query.get_handle(ctx.author.id, ctx.guild.id)
        try:
            user = await query.get_user(username)
            username = user.username
        except TypeError:
            username = None
        if username is None:
            return await ctx.send('You have not entered a valid DMOJ handle '
                                  'or linked with a DMOJ Account')

        gitgud_util = Gitgud_utils()
        history = gitgud_util.get_all(username, ctx.guild.id)

        if len(history) == 0:
            embed = discord.Embed(description='User have not completed any '
                                  'challenge')
            return await ctx.send(embed=embed)
        # paginate
        count = 0
        page_cnt = min(10, len(history) // 10 + bool(len(history) % 10))
        embeds = []
        content = ''
        paginator = Pagination.CustomEmbedPaginator(ctx,
                                                    timeout=60,
                                                    remove_reactions=True)
        paginator.add_reaction('⏮️', 'first')
        paginator.add_reaction('⏪', 'back')
        paginator.add_reaction('⏩', 'next')
        paginator.add_reaction('⏭️', 'last')
        for solved in history:
            problem = await query.get_problem(solved.problem_id)
            days = (datetime.now() - solved.time).days
            if days == 0:
                days_str = 'today'
            elif days == 1:
                days_str = 'yesterday'
            else:
                days_str = f'{days} days ago'
            content += f'[{problem.name}](https://dmoj.ca/problem/{problem.code}) ' \
                       f'[+{solved.point}] ({days_str})\n'
            count += 1
            if count % 10 == 0:
                embed = discord.Embed(color=0xfcdb05, )
                embed.add_field(name=f'Gitgud Log for {username} '
                                f'(page {count//10}/{page_cnt})',
                                value=content,
                                inline=True)
                embeds.append(embed)
                content = ''
            if count == 100:
                break
        if count % 10 != 0:
            embed = discord.Embed()
            embed.add_field(name=f'Gitlog for {username} '
                            f'(page {count//10 + 1}/{page_cnt})',
                            value=content,
                            inline=True)
            embeds.append(embed)
        return await paginator.run(embeds)