diff --git a/cogs/leaderboards.py b/cogs/leaderboards.py index b891442..1d39daf 100644 --- a/cogs/leaderboards.py +++ b/cogs/leaderboards.py @@ -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) diff --git a/cogs/xp.py b/cogs/xp.py index 9d292cb..d805d65 100644 --- a/cogs/xp.py +++ b/cogs/xp.py @@ -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") diff --git a/functions/database/stats.py b/functions/database/stats.py index 43aac01..60d4685 100644 --- a/functions/database/stats.py +++ b/functions/database/stats.py @@ -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()