From 0119b4db85b677c9a25251b193176b3c4ac9a3d1 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Dec 2020 22:09:37 -0500 Subject: [PATCH 1/4] feature (stats cog): added rudimentary leaderboard --- santabot/cogs/stats.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/santabot/cogs/stats.py b/santabot/cogs/stats.py index 9cc68b0..b21fb1a 100644 --- a/santabot/cogs/stats.py +++ b/santabot/cogs/stats.py @@ -145,6 +145,47 @@ async def __make_stats( icon_url=ctx.me.avatar_url )) + # ------------------------------------------------------------------------- + # Discord.py `leaderboard` command + # ------------------------------------------------------------------------- + @commands.command() + async def leaderboard( + self, + ctx: discord.ext.commands.Context, + ): + """Command to get the leaderboard for the server + + Args: + ctx (discord.ext.commands.Context): Discord.py command context. + """ + embed = discord.Embed( + title='Leaderboard', + description='These users have the most presents' + ).set_thumbnail( + url=ctx.guild.icon_url + ) + for i, user_obj in enumerate(self.users_by_present()): + if i > 10: + break + user = self.bot.get_user(user_obj.id) + embed.add_field( + name=f'{i}.', + value=f'{user.owned_present_count} presents' + ) + embed.set_footer( + text='Try "@santa about" to learn more about me', + icon_url=ctx.me.avatar_url + ) + pass + + @orm.db_session + def users_by_present(self): + return orm.select( + u for u in User + ).order_by( + lambda u: u.owned_present_count + ).page(1) + @orm.db_session def calculate_all_time_presents(self) -> int: """Calculate all time number of presents distributed. From fa20b1d98c623b3bb15939318061c4337a606b7d Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Dec 2020 22:11:36 -0500 Subject: [PATCH 2/4] feat (leaderboard): renamed leaderboard to top --- santabot/cogs/stats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/santabot/cogs/stats.py b/santabot/cogs/stats.py index b21fb1a..263e4de 100644 --- a/santabot/cogs/stats.py +++ b/santabot/cogs/stats.py @@ -146,14 +146,14 @@ async def __make_stats( )) # ------------------------------------------------------------------------- - # Discord.py `leaderboard` command + # Discord.py `top` command # ------------------------------------------------------------------------- @commands.command() - async def leaderboard( + async def top( self, ctx: discord.ext.commands.Context, ): - """Command to get the leaderboard for the server + """Command to get the top 10 for the server Args: ctx (discord.ext.commands.Context): Discord.py command context. From 7f99ff341e9347049cfb76b7ca48549931fdd287 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Dec 2020 22:19:02 -0500 Subject: [PATCH 3/4] feat (stats cog): added missing name mention to top command --- santabot/cogs/stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/santabot/cogs/stats.py b/santabot/cogs/stats.py index 263e4de..2567bac 100644 --- a/santabot/cogs/stats.py +++ b/santabot/cogs/stats.py @@ -169,7 +169,7 @@ async def top( break user = self.bot.get_user(user_obj.id) embed.add_field( - name=f'{i}.', + name=f'{i}: {user.mention}', value=f'{user.owned_present_count} presents' ) embed.set_footer( From f9299f900e8da919b8b7d71c8aee45399a3d4a93 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Dec 2020 22:20:10 -0500 Subject: [PATCH 4/4] feat (stats cog): set fields to not inline --- santabot/cogs/stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/santabot/cogs/stats.py b/santabot/cogs/stats.py index 2567bac..3a4a84f 100644 --- a/santabot/cogs/stats.py +++ b/santabot/cogs/stats.py @@ -170,7 +170,8 @@ async def top( user = self.bot.get_user(user_obj.id) embed.add_field( name=f'{i}: {user.mention}', - value=f'{user.owned_present_count} presents' + value=f'{user.owned_present_count} presents', + inline=False ) embed.set_footer( text='Try "@santa about" to learn more about me',