Fancier leaderboard

This commit is contained in:
Twentysix 2016-03-15 01:56:45 +01:00
parent 1049e26b4f
commit 00b39accd9

View File

@ -122,24 +122,25 @@ class Economy:
await self.bot.say("{} You need an account to receive credits.".format(author.mention)) await self.bot.say("{} You need an account to receive credits.".format(author.mention))
@commands.command() @commands.command()
async def leaderboard(self): async def leaderboard(self, top : int=10):
"""Prints out the leaderboard""" #Originally coded by Airenkun """Prints out the leaderboard
Defaults to top 10""" #Originally coded by Airenkun - edited by irdumb
if top < 1:
top = 10
bank_sorted = sorted(self.bank.items(), key=lambda x: x[1]["balance"], reverse=True) bank_sorted = sorted(self.bank.items(), key=lambda x: x[1]["balance"], reverse=True)
topten = bank_sorted[:10] if len(bank_sorted) < top:
top = len(bank_sorted)
topten = bank_sorted[:top]
highscore = "" highscore = ""
place = 1 place = 1
dashes = "---"
for id in topten: for id in topten:
if place > 9: highscore += str(place).ljust(len(str(top))+1)
dashes = "--" highscore += (id[1]["name"]+" ").ljust(23-len(str(id[1]["balance"])))
loop = 14 + 8 - len(str(id[1]["balance"])) - len(id[1]["name"]) highscore += str(id[1]["balance"]) + "\n"
highscore += "{}{}{}".format(place,dashes,id[1]["name"])
for i in range(1,loop+1):
highscore += "-"
highscore += "{}\n".format(id[1]["balance"])
place += 1 place += 1
if highscore: if highscore:
await self.bot.say(highscore) await self.bot.say("```py\n"+highscore+"```")
else: else:
await self.bot.say("There are no accounts in the bank.") await self.bot.say("There are no accounts in the bank.")