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))
|
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.")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user