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') 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_display = f'{member.display_name} ({score})' t += table.Data(index, handle_display) index += 1 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)
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 leaderboard(self, placings, num): leaderboard = sorted( ((k, score(v)) for k, v in placings.items() if k != 'N/A'), key=lambda x: x[1], reverse=True) if not leaderboard: return 'Failed to load :<' top = leaderboard[:num] header = ' 1st 2nd 3rd 4th 5th '.split(' ') style = table.Style(header='{:>} {:>} {:>} {:>} {:>} {:>} {:>}', body='{:>} | {:>} {:>} {:>} {:>} {:>} | {:>} pts') t = table.Table(style) t += table.Header(*header) for user, points in top: hist = [placings[user].count(i + 1) for i in range(5)] t += table.Data(user, *hist, points) return str(t)