diff --git a/cogs/economy.py b/cogs/economy.py index baca44a44..2180a5d24 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -122,24 +122,25 @@ class Economy: await self.bot.say("{} You need an account to receive credits.".format(author.mention)) @commands.command() - async def leaderboard(self): - """Prints out the leaderboard""" #Originally coded by Airenkun + async def leaderboard(self, top : int=10): + """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) - topten = bank_sorted[:10] + if len(bank_sorted) < top: + top = len(bank_sorted) + topten = bank_sorted[:top] highscore = "" place = 1 - dashes = "---" for id in topten: - if place > 9: - dashes = "--" - loop = 14 + 8 - len(str(id[1]["balance"])) - len(id[1]["name"]) - highscore += "{}{}{}".format(place,dashes,id[1]["name"]) - for i in range(1,loop+1): - highscore += "-" - highscore += "{}\n".format(id[1]["balance"]) + highscore += str(place).ljust(len(str(top))+1) + highscore += (id[1]["name"]+" ").ljust(23-len(str(id[1]["balance"]))) + highscore += str(id[1]["balance"]) + "\n" place += 1 if highscore: - await self.bot.say(highscore) + await self.bot.say("```py\n"+highscore+"```") else: await self.bot.say("There are no accounts in the bank.")