Add percentage to Message counter & leaderboard

pull/21/head
Stijn De Clercq 2020-12-23 00:48:43 +01:00
parent f25bb468b4
commit 6a946559e2
3 changed files with 18 additions and 4 deletions

View File

@ -10,7 +10,6 @@ import math
import requests
# TODO some sort of general leaderboard because all of them are the same
class Leaderboards(commands.Cog):
@ -156,15 +155,20 @@ class Leaderboards(commands.Cog):
async def messages(self, ctx):
s = stats.getAllRows()
boardTop = []
message_count = stats.getTotalMessageCount()
for i, user in enumerate(sorted(s, key=lambda x: x[11], reverse=True)):
if int(user[11]) == 0:
break
perc = round(int(user[11]) * 100 / message_count, 2)
name = self.utilsCog.getDisplayName(ctx, user[0])
if int(user[0]) == int(ctx.author.id):
boardTop.append("**{} ({:,})**".format(name, round(int(user[11]))))
boardTop.append("**{} ({:,} | {}%)**".format(name, round(int(user[11])), perc))
else:
boardTop.append("{} ({:,})".format(name, round(int(user[11]))))
boardTop.append("{} ({:,} | {}%)".format(name, round(int(user[11])), perc))
await self.startPaginated(ctx, boardTop, "Messages Leaderboard")
@leaderboard.command(name="Muttn", aliases=["M", "Mutn", "Mutten"], hidden=True)

View File

@ -22,9 +22,13 @@ class Xp(commands.Cog):
target_stats = stats.getOrAddUser(target.id)
message_count = stats.getTotalMessageCount()
perc = round(int(target_stats[11]) * 100/message_count, 2)
embed = discord.Embed(colour=discord.Colour.blue())
embed.set_author(name=target.display_name, icon_url=target.avatar_url)
embed.add_field(name="Aantal Berichten", value="{}".format(int(target_stats[11])))
embed.add_field(name="Aantal Berichten", value="{} ({}%)".format(int(target_stats[11]), perc))
embed.add_field(name="Level", value=str(xp.calculate_level(target_stats[12])))
embed.add_field(name="XP", value="{:,}".format(int(target_stats[12])))
embed.set_footer(text="*Sinds Didier 2.0 Launch")

View File

@ -107,6 +107,12 @@ def gainXp(user, user_db):
update(user, "last_message", round(time.time()))
def getTotalMessageCount():
r = getAllRows()
return sum(user[11] for user in r)
def getOrAddChannel(channelid: int):
connection = utils.connect()
cursor = connection.cursor()