Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. import discord, sqlite3
  2. from discord.ext import commands
  3. from .local import Database
  4. from random import randint as gain
  5.  
  6. class Leveling:
  7.     def __init__(self, bot):
  8.         self.bot = bot
  9.  
  10.     def level_embed(self, user: discord.Member, results):
  11.         embed=discord.Embed()
  12.         embed.add_field(name=f'Search Results for **{user.name}#{user.discriminator}**', value=f'We found the following information on {user.mention}: \n\nLeaderboard Ranking: {results[0]} \nLevel: {results[1]} \nTotal XP: {results[2]}')
  13.         return embed.set_footer(text='Provided by: SimplySavant via SavantBot')
  14.  
  15.     def leaderboard_embed(self):
  16.         embed=discord.Embed()
  17.         embed.add_field(name='Server Leaderboard', value='Make sure to give a MASSIVE Congratulations to these people for making into the Top 10!')
  18.         return embed.set_footer(text='Provided by: SimplySavant via SavantBot')
  19.  
  20.     async def on_message(self, message):
  21.         if message.guild is not None:
  22.             exp = gain(5, 25)
  23.             Database.addXP(str(message.guild.id), str(message.author.id), exp)
  24.  
  25.     @commands.command(description='Command to Check Individual Progression')
  26.     async def check(self, ctx, user: discord.Member=None):
  27.         if not user:
  28.             user = ctx.message.author
  29.         results = Database.userXP(str(ctx.guild.id), str(user.id))
  30.         await ctx.send(embed=self.level_embed(user, results))
  31.  
  32.     @commands.command(description='Command to Check Top 10 Members of A Guild')
  33.     async def top(self, ctx):
  34.         results = Database.leaderboard(str(ctx.guild.id))
  35.         leaderboard = ''
  36.         counter = 1
  37.         for id in results.keys():
  38.             if counter == 1:
  39.                 leaderboard += f'{counter}. {self.bot.get_user(id).mention} - Level: {results[id][0]} ({results[id][1] XP}) 👑 \n'
  40.                 counter += 1
  41.             else:
  42.                 leaderboard += f'{counter}. {self.bot.get_user(id).mention} - Level: {results[id][0]} ({results[id][1] XP}) \n'
  43.                 counter += 1
  44.         e = self.leaderboard_embed()
  45.         e.add_field(name='', value=leaderboard)
  46.         await ctx.send(embed=e)
  47.  
  48.  
  49. def setup(bot):
  50.     bot.add_cog(Leveling(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement