def _make_standings_pages(self, contest, problem_indices, handle_standings, deltas=None): pages = [] handle_standings_chunks = paginator.chunkify(handle_standings, _STANDINGS_PER_PAGE) num_chunks = len(handle_standings_chunks) delta_chunks = paginator.chunkify(deltas, _STANDINGS_PER_PAGE) if deltas else [None] * num_chunks if contest.type == 'CF': get_table = functools.partial(self._get_cf_or_ioi_standings_table, mode='cf') elif contest.type == 'ICPC': get_table = self._get_icpc_standings_table elif contest.type == 'IOI': get_table = functools.partial(self._get_cf_or_ioi_standings_table, mode='ioi') else: assert False, f'Unexpected contest type {contest.type}' num_pages = 1 for handle_standings_chunk, delta_chunk in zip(handle_standings_chunks, delta_chunks): header_style, body_style, header, body = get_table(problem_indices, handle_standings_chunk, delta_chunk) t = table.Table(table.Style(header=header_style, body=body_style)) t += table.Header(*header) t += table.Line('\N{EM DASH}') for row in body: t += table.Data(*row) t += table.Line('\N{EM DASH}') page_num_footer = f' # Page: {num_pages} / {num_chunks}' if num_chunks > 1 else '' # We use yaml to get nice colors in the ranklist. content = f'```yaml\n{t}\n{page_num_footer}```' pages.append((content, None)) num_pages += 1 return pages
async def gudgitters(self, ctx): """Show the list of users of gitgud with their scores.""" res = cf_common.user_db.get_gudgitters() res.sort(key=lambda r: r[1], reverse=True) style = table.Style('{:>} {:<} {:<} {:<}') t = table.Table(style) t += table.Header('#', 'Name', 'Handle', 'Rating') t += table.Line() index = 0 for user_id, score in res: member = ctx.guild.get_member(int(user_id)) if member is None: continue if score > 0: handle = cf_common.user_db.get_handle(user_id, ctx.guild.id) user = cf_common.user_db.fetch_cf_user(handle) handle_display = f'{member.display_name} ({score})' rating = user.rating if user.rating is not None else 'Unrated' t += table.Data(index, handle_display, handle, rating) index += 1 if index == 20: break if index > 0: msg = '```\n' + str(t) + '\n```' else: msg = '```No one has completed a gitgud challenge, send ;gitgud to request and ;gotgud to mark it as complete```' await ctx.send(msg)
async def gudgitters(self, ctx): try: converter = commands.MemberConverter() res = cf_common.user_db.get_gudgitters() res.sort(key=lambda r: r[1], reverse=True) style = table.Style('{:>} {:<}') t = table.Table(style) t += table.Header('#', 'Name') t += table.Line() index = 0 for user_id, score in res: try: # in case the person has left the server member = await converter.convert(ctx, user_id) name = member.nick if member.nick else member.name handle_display = f'{name} ({score})' t += table.Data(index, handle_display) index = index + 1 except Exception as e: print(e) msg = '```\n' + str(t) + '\n```' except Exception as e: print(e) msg = 'showhandles error!' await ctx.send(msg)
def make_page(chunk, page_num): style = table.Style('{:>} {:<} {:<}') t = table.Table(style) t += table.Header('#', 'Name', 'Handle') t += table.Line() for index, (member, handle) in enumerate(chunk): t += table.Data(_PER_PAGE * page_num + index, f'{member.display_name}', handle) table_str = f'```\n{t}\n```' embed = discord_common.cf_color_embed(description=table_str) return 'List of contestants', embed
def make_page(chunk, page_num): style = table.Style('{:>} {:<} {:<} {:<}') t = table.Table(style) t += table.Header('#', 'Name', 'Handle', 'Rating') t += table.Line() for index, (member, handle, rating) in enumerate(chunk): rating_str = f'{rating} ({rating2rank(rating).title_abbr})' t += table.Data(_PER_PAGE * page_num + index, f'{member.display_name}', handle, rating_str) table_str = f'```\n{t}\n```' embed = discord_common.cf_color_embed(description=table_str) return 'List of duelists', embed
def make_page(chunk, page_num): style = table.Style("{:>} {:<} {:<}") t = table.Table(style) t += table.Header("#", "Name", "Handle") t += table.Line() for index, (member, handle) in enumerate(chunk): t += table.Data( _PER_PAGE * page_num + index, f"{member.display_name}", handle, ) table_str = f"```\n{t}\n```" embed = discord_common.cf_color_embed(description=table_str) return "List of contestants", embed
def make_page(chunk, page_num): style = table.Style("{:>} {:<} {:<} {:<}") t = table.Table(style) t += table.Header("#", "Name", "Handle", "Rating") t += table.Line() for index, (member, handle, rating) in enumerate(chunk): rating_str = f"{rating} ({rating2rank(rating).title_abbr})" t += table.Data( _PER_PAGE * page_num + index, f"{member.display_name}", handle, rating_str, ) table_str = f"```\n{t}\n```" embed = discord_common.cf_color_embed(description=table_str) return "List of duelists", embed
def _make_pages(users): chunks = paginator.chunkify(users, _HANDLES_PER_PAGE) pages = [] done = 0 style = table.Style('{:>} {:<} {:<} {:<}') for chunk in chunks: t = table.Table(style) t += table.Header('#', 'Name', 'Handle', 'Rating') t += table.Line() for i, (member, handle, rating) in enumerate(chunk): rank = cf.rating2rank(rating) rating_str = 'N/A' if rating is None else str(rating) t += table.Data(i + done, member.display_name, handle, f'{rating_str} ({rank.title_abbr})') table_str = '```\n' + str(t) + '\n```' embed = discord_common.cf_color_embed(description=table_str) pages.append(('Handles of server members', embed)) done += len(chunk) return pages
def _make_pages(users, title): chunks = paginator.chunkify(users, _HANDLES_PER_PAGE) pages = [] done = 0 style = table.Style("{:>} {:<} {:<} {:<}") for chunk in chunks: t = table.Table(style) t += table.Header("#", "Name", "Handle", "Rating") t += table.Line() for i, (member, handle, rating) in enumerate(chunk): name = member.display_name if len(name) > _NAME_MAX_LEN: name = name[: _NAME_MAX_LEN - 1] + "…" rank = cf.rating2rank(rating) rating_str = "N/A" if rating is None else str(rating) t += table.Data(i + done, name, handle, f"{rating_str} ({rank.title_abbr})") table_str = "```\n" + str(t) + "\n```" embed = discord_common.cf_color_embed(description=table_str) pages.append((title, embed)) done += len(chunk) return pages
def _make_pages_gudgitters(users, title): chunks = paginator.chunkify(users, _HANDLES_PER_PAGE) pages = [] done = 0 style = table.Style('{:>} {:<} {:<} {:<}') for chunk in chunks: t = table.Table(style) t += table.Header('#', 'Name', 'Handle', 'Rating') t += table.Line() for i, (member, handle, rating) in enumerate(chunk): name = member if len(name) > _NAME_MAX_LEN: name = name[:_NAME_MAX_LEN - 1] + '…' rank = cf.rating2rank(rating) rating_str = 'N/A' if rating is None else str(rating) t += table.Data(i + done, name, handle, f'{rating_str}') table_str = '```\n' + str(t) + '\n```' embed = discord_common.cf_color_embed(description=table_str) pages.append((title, embed)) done += len(chunk) return pages