mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 19:28:54 -05:00
Fancier leaderboard
This commit is contained in:
parent
1049e26b4f
commit
00b39accd9
@ -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.")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user