Created
September 6, 2019 22:24
-
-
Save 4Kaylum/6e7f0ae03c2d97d2bd32577f7aa0bb56 to your computer and use it in GitHub Desktop.
A cog that gets a person at rank N on the Mee6 leaderboards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Gets a member at the Nth place on Mee6's leaderboard""" | |
| from discord.ext import commands | |
| from cogs import utils | |
| class Mee6Ranking(utils.Cog): | |
| def __init__(self, bot:utils.CustomBot): | |
| super().__init__(bot) | |
| @commands.command() | |
| async def mee6rank(self, ctx:commands.Context, rank:int): | |
| """Gives you the user at rank N on Mee6""" | |
| url = f"https://mee6.xyz/api/plugins/levels/leaderboard/{ctx.guild.id}" | |
| params = { | |
| "page": rank // 100 | |
| } | |
| async with self.bot.session.get(url, params=params) as r: | |
| data = await r.json() | |
| index = (rank % 100) - 1 | |
| user_id = int(data['players'][index]['id']) | |
| user = ctx.guild.get_member(user_id) | |
| if user is None: | |
| await ctx.send(f"The user in {rank}th place has left the server.") | |
| else: | |
| await ctx.send(f"The user in {rank}th place is {user.mention}!") | |
| def setup(bot): | |
| x = Mee6Ranking(bot) | |
| bot.add_cog(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment