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)
async def gitlog(ctx): """ Show the past gitgud history of a user """ query = Query() username = ctx.options.username username = username or query.get_handle(ctx.author.id, ctx.get_guild().id) try: user = await query.get_user(username) username = user.username except TypeError: username = None if username is None: return await ctx.respond("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.get_guild().id) if len(history) == 0: embed = hikari.Embed(description="User have not completed any " "challenge") return await ctx.respond(embed=embed) # paginate pag = lightbulb.utils.EmbedPaginator() for idx, solved in enumerate(history): # problem = solved.problem_id or await query.get_problem(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" pag.add_line(f"[{problem.name}](https://dmoj.ca/problem/{problem.code}) " f"[+{solved.point}] ({days_str})") if idx == 100: break @pag.embed_factory() def build_embed(page_index, content): return hikari.Embed(color=0xFCDB05,).add_field( name=f"Gitgud Log for {username} " f"(page {page_index})", # Can't put total length :/ value=content, inline=True, ) navigator = nav.ButtonNavigator(pag.build_pages()) await navigator.run(ctx)
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)