async def leaderboard(self, ctx, *args): """Check this server's users with the most karma.""" db.clear_cache() User = Query() server = str(ctx.message.guild.id) result = db.search(User.servers.all([server])) # doesnt work leaderboard = {} # Prepares an empty dictionary. for x in result: # For each entry in the database: leaderboard[x.get("username")] = int(x.get("points")) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted(leaderboard.items(), key = lambda x : x[1], reverse=True) # Sort this database by amount of points. s = "Top artists sorted by most thanks received.\n\n" i = 0 for key, value in leaderboard: # For each value in the new, sorted DB: if not args: if i != 10: user = self.client.get_user(key) if not user: user = await self.client.fetch_user(key) print("User not found. Trying to fetch it...") if i==0: s += ("🥇 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") elif i==1: s += ("🥈 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") elif i==2: s += ("🥉 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") else: s += ("🎨 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") i = i+1 embed = discord.Embed(title="AOTSKINS Leaderboard", colour=discord.Colour(0xa353a9), description=s) glb = await ctx.send(embed=embed)
async def globalleaderboard(self, ctx, *args): """Check the top karma holders on all Discord!""" db.clear_cache() result = db.all() # "Result" is just the entire database. leaderboard = {} # Prepares an empty dictionary. for x in result: # For each entry in the database: leaderboard[x.get("username")] = int( x.get("points") ) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted( leaderboard.items(), key=lambda x: x[1], reverse=True) # Sort this database by amount of points. s = "" i = 0 for key, value in leaderboard: # For each value in the new, sorted DB: if not args: if i != 10: user = self.client.get_user(key) if not user: user = await self.client.fetch_user(key) print("User not found. Trying to fetch it...") if i == 0: s += ("🥇 " + str(user) + " - " + str(value) + " Karma\n") elif i == 1: s += ("🥈 " + str(user) + " - " + str(value) + " Karma\n") elif i == 2: s += ("🥉 " + str(user) + " - " + str(value) + " Karma\n") else: s += ("✨ " + str(user) + " - " + str(value) + " Karma\n") i = i + 1 elif args[0] == "all": user = self.client.get_user(key) if not user: user = await self.client.fetch_user(key) print("User not found. Trying to fetch it...") if i == 0: s += ("🥇 #" + str(i + 1) + " - " + str(user) + " - " + str(value) + " Karma\n") elif i == 1: s += ("🥈 #" + str(i + 1) + " - " + str(user) + " - " + str(value) + " Karma\n") elif i == 2: s += ("🥉 #" + str(i + 1) + " - " + str(user) + " - " + str(value) + " Karma\n") else: s += ("✨ #" + str(i + 1) + " - " + str(user) + " - " + str(value) + " Karma\n") i = i + 1 embed = discord.Embed(title="Global Leaderboard", colour=discord.Colour(0xa353a9), description=s) glb = await ctx.send(embed=embed)
async def updatelb(self): await self.client.wait_until_ready() """Check this server's users with the most karma.""" db.clear_cache() User = Query() server = str(811586984879063050) result = db.search(User.servers.all([server])) # doesnt work leaderboard = {} # Prepares an empty dictionary. for x in result: # For each entry in the database: leaderboard[x.get("username")] = int(x.get("points")) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted(leaderboard.items(), key = lambda x : x[1], reverse=True) # Sort this database by amount of points. dateToday = "....." s = f"Top 50 artists sorted by most thanks received.\n\n" i = 0 for key, value in leaderboard: # For each value in the new, sorted DB: if i != 50: user = self.client.get_user(key) if not user: user = await self.client.fetch_user(key) if i==0: s += ("🥇 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") elif i==1: s += ("🥈 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") elif i==2: s += ("🥉 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") else: s += ("🎨 #" + str(i+1) + " - " + f"<@!{key}>" + " - " + str(value) +" thanks\n") i = i+1 embed = discord.Embed(title="AOTSKINS' Top 50 Artists", colour=discord.Colour(0xa353a9), description=s) embed.set_footer(text='The list is updated every hour.') thisguild = self.client.get_guild(811586984879063050) channel = discord.utils.get(thisguild.text_channels, name="top-50") lbMessage = await channel.fetch_message(815960589125287966) staffchannel = discord.utils.get(thisguild.text_channels, name="staff-commands") glb = await lbMessage.edit(embed=embed) await staffchannel.send(content=f"<#815956314798424114> leaderboard updated")
async def on_reaction_add(self, reaction, user): value = user.id User = Query() if ((user.id != reaction.message.author.id) or (debug == True)) and not user.bot: if isinstance(reaction.emoji, str): # ------------------------- # REACTION = :WASTEBASKET: # (leaderboards) # ------------------------- if reaction.emoji == '🗑️': await deleteMessages(reaction) # ------------------------- # REACTION = :ARROW_RIGHT: # (leaderboards) # ------------------------- if reaction.emoji == '➡️': result = dm.get(Query()['id'] == reaction.message.id) page = result.get('page') + 1 currentguild = str(reaction.message.guild.id) isGlobal = result.get('global') print(isGlobal) if (isGlobal == True): result = post.all() else: result = post.search(Query()['servers'] == currentguild) leaderboard = {} # Prepares an empty dictionary. j = 0 for x in result: # For each entry in the database: leaderboard[j] = [int(x.get("points")), str(x.get("content")), str(x.get("username")), str(x.get("embed")), str(x.get("servers")), str(x.get("stars")), str(x.get("nsfw")), str(x.get("richembed"))] # ...save the user's ID and its amount of points in a new Python database. j = j+1 leaderboard = sorted(leaderboard.items(), key = lambda x : x[1][0], reverse=True) await printLeaderboard(page, leaderboard, self, reaction.message.guild, reaction.message, reaction.message.channel, False, isGlobal) await deleteMessages(reaction) # ------------------------- # REACTION = :ARROW_LEFT: # (leaderboards) # ------------------------- if reaction.emoji == '⬅️': result = dm.get(Query()['id'] == reaction.message.id) page = result.get('page') - 1 currentguild = str(reaction.message.guild.id) isGlobal = result.get('global') if (isGlobal == True): result = post.all() else: result = post.search(Query()['servers'] == currentguild) leaderboard = {} # Prepares an empty dictionary. j = 0 for x in result: # For each entry in the database: leaderboard[j] = [int(x.get("points")), str(x.get("content")), str(x.get("username")), str(x.get("embed")), str(x.get("servers")), str(x.get("stars")), str(x.get("nsfw")), str(x.get("richembed"))] # ...save the user's ID and its amount of points in a new Python database. j = j+1 leaderboard = sorted(leaderboard.items(), key = lambda x : x[1][0], reverse=True) await printLeaderboard(page, leaderboard, self, reaction.message.guild, reaction.message, reaction.message.channel, False, isGlobal) await deleteMessages(reaction) # ------------------------- # REACTION = :BOMB: # (Delete User Data) # ------------------------- if reaction.emoji == "💣": if isinstance(reaction.message.channel, discord.channel.DMChannel): if (reaction.message.embeds[0].title == "Are you SURE?!"): checkM = loadingEmoji = self.client.get_emoji(660250625107296256) react = await reaction.message.add_reaction(checkM) priv.remove(where('username') == user.id) priv.clear_cache() post.remove(where('username') == str(user.id)) post.clear_cache() db.remove(where('username') == str(user.id)) db.clear_cache() botid = self.client.user await reaction.message.remove_reaction(checkM, botid) await reaction.message.channel.send("**Done.** Your Privacy Settings, all of your Comments and your personal data (such as servers and Karma) has been deleted.\nDo note that, by interacting with Reto functions, you may be re-introduced into the database.\n*Thank you for using Reto!*")
async def autorole(self): """Autoroles.""" await self.client.wait_until_ready() db.clear_cache() User = Query() server = str(811586984879063050) result = db.search(User.servers.all([server])) # doesnt work leaderboard = {} # Prepares an empty dictionary. for x in result: # For each entry in the database: leaderboard[x.get("username")] = int(x.get("points")) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted(leaderboard.items(), key = lambda x : x[1], reverse=True) # Sort this database by amount of points. i = 0 #Roles thisguild = self.client.get_guild(811586984879063050) newbie_artist = discord.utils.get(thisguild.roles, name="Newbie Artist") veteran_artist = discord.utils.get(thisguild.roles, name="Veteran Artist") senior_artist = discord.utils.get(thisguild.roles, name="Senior Artist") designer = discord.utils.get(thisguild.roles, name="Designer") veteran_designer = discord.utils.get(thisguild.roles, name="Veteran Designer") senior_designer = discord.utils.get(thisguild.roles, name="Senior Designer") artist = discord.utils.get(thisguild.roles, name="Artist") for key, value in leaderboard: # For each value in the new, sorted DB: user = self.client.get_user(key) if not user: user = await self.client.fetch_user(key) for x in thisguild.members: if int(key) == int(x.id): if value >= 25 and value < 100: await x.add_roles(newbie_artist) await x.remove_roles(veteran_artist) await x.remove_roles(senior_artist) await x.remove_roles(designer) await x.remove_roles(veteran_designer) await x.remove_roles(senior_designer) await x.add_roles(artist) elif value >= 100 and value < 200: await x.add_roles(veteran_artist) await x.remove_roles(newbie_artist) await x.remove_roles(senior_artist) await x.remove_roles(designer) await x.remove_roles(veteran_designer) await x.remove_roles(senior_designer) await x.add_roles(artist) elif value >= 200 and value < 400: await x.add_roles(senior_artist) await x.remove_roles(newbie_artist) await x.remove_roles(veteran_artist) await x.remove_roles(designer) await x.remove_roles(veteran_designer) await x.remove_roles(senior_designer) await x.add_roles(artist) elif value >= 400 and value < 700: await x.add_roles(designer) await x.remove_roles(newbie_artist) await x.remove_roles(veteran_artist) await x.remove_roles(senior_artist) await x.remove_roles(veteran_designer) await x.remove_roles(senior_designer) await x.add_roles(artist) elif value >= 700 and value < 1000: await x.add_roles(veteran_designer) await x.remove_roles(newbie_artist) await x.remove_roles(veteran_artist) await x.remove_roles(senior_artist) await x.remove_roles(designer) await x.remove_roles(senior_designer) await x.add_roles(artist) elif value >= 1000: await x.add_roles(senior_designer) await x.remove_roles(newbie_artist) await x.remove_roles(veteran_artist) await x.remove_roles(senior_artist) await x.remove_roles(designer) await x.remove_roles(veteran_designer) await x.add_roles(artist) i = i+1
async def getProfile(author, ctx, self): valor = str(author) searchvalor = str(author.id) result = db.get(Query()['username'] == searchvalor) # # CONSEGUIR VALOR EN LA GLB # if not isinstance(ctx.message.channel, discord.channel.DMChannel): server = str(ctx.message.guild.id) db.clear_cache() lbsult = db.all() # doesnt work leaderboard = {} # Prepares an empty dictionary. for x in lbsult: # For each entry in the database: leaderboard[x.get("username")] = int( x.get("points") ) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted( leaderboard.items(), key=lambda x: x[1], reverse=True) # Sort this database by amount of points. s = "" leadervalue = 1 for key, value in leaderboard: # For each value in the new, sorted DB: if key == searchvalor: break else: leadervalue += 1 # # CONSEGUIR VALOR EN LA LLB # if not isinstance(ctx.message.channel, discord.channel.DMChannel): llbsult = db.search(Query().servers.all([server])) # doesnt work lleaderboard = {} # Prepares an empty dictionary. for x in llbsult: # For each entry in the database: lleaderboard[x.get("username")] = int( x.get("points") ) # ...save the user's ID and its amount of points in a new Python database. lleaderboard = sorted( lleaderboard.items(), key=lambda x: x[1], reverse=True) # Sort this database by amount of points. s = "" localvalue = 1 for key, value in lleaderboard: # For each value in the new, sorted DB: if key == searchvalor: break else: localvalue += 1 # # GLB BADGE # if result: if leadervalue == 1: leaderemblem = "🥇" elif leadervalue == 2: leaderemblem = "🥈" elif leadervalue == 3: leaderemblem = "🥉" elif leadervalue <= 10: leaderemblem = "🏅" else: leaderemblem = " " else: leaderemblem = " " # # REVISAR ESTATUS DE CURATOR # thisguild = ctx.message.guild newbie_artist = discord.utils.get(thisguild.roles, name="Newbie Artist") veteran_artist = discord.utils.get(thisguild.roles, name="Veteran Artist") senior_artist = discord.utils.get(thisguild.roles, name="Senior Artist") designer = discord.utils.get(thisguild.roles, name="Designer") veteran_designer = discord.utils.get(thisguild.roles, name="Veteran Designer") senior_designer = discord.utils.get(thisguild.roles, name="Senior Designer") artist = discord.utils.get(thisguild.roles, name="Artist") roleemblem = "None" if newbie_artist in author.roles: roleemblem = f"{newbie_artist.mention}" elif veteran_artist in author.roles: roleemblem = f"{veteran_artist.mention}" elif senior_artist in author.roles: roleemblem = f"{senior_artist.mention}" elif designer in author.roles: roleemblem = f"{designer.mention}" elif veteran_designer in author.roles: roleemblem = f"{veteran_designer.mention}" elif senior_designer in author.roles: roleemblem = f"{senior_designer.mention}" elif artist in author.roles: roleemblem = f"{artist.mention}" # # POINTS SENT # sentpoints = post.search(Query().voters.any([author.id])) # # STARS RECEIVED # starlist = post.search(Query().username == str(author.id)) starsrec = 0 for star in starlist: if 'stars' in star: starsrec += star['stars'] # # SUPPORT BADGES (WIP) # #checkM = self.client.get_emoji(741669341409312889) #print(str(checkM)) # # SEND THE EMBED # embed = discord.Embed(title=author.name + ' ' + leaderemblem) embed.set_thumbnail(url=author.avatar_url) if result: embed.add_field(name="Thanks Received", value=result.get('points'), inline=False) else: embed.add_field(name="Thanks Received", value='0', inline=False) if result: embed.add_field(name="Artist Rank", value=roleemblem, inline=False) embed.add_field(name="Leaderboard Rank", value=leadervalue, inline=False) embed.add_field(name="Thanks Given", value=len(sentpoints), inline=False) embed.add_field(name="Stars received", value=starsrec, inline=False) embed.colour = author.top_role.colour await ctx.send(embed=embed)
async def getProfile(author, ctx, self): valor = str(author) searchvalor = str(author.id) result = db.get(Query()['username'] == searchvalor) # # CONSEGUIR VALOR EN LA GLB # if not isinstance(ctx.message.channel, discord.channel.DMChannel): server = str(ctx.message.guild.id) db.clear_cache() lbsult = db.all() # doesnt work leaderboard = {} # Prepares an empty dictionary. for x in lbsult: # For each entry in the database: leaderboard[x.get("username")] = int( x.get("points") ) # ...save the user's ID and its amount of points in a new Python database. leaderboard = sorted( leaderboard.items(), key=lambda x: x[1], reverse=True) # Sort this database by amount of points. s = "" leadervalue = 1 for key, value in leaderboard: # For each value in the new, sorted DB: if key == searchvalor: break else: leadervalue += 1 # # CONSEGUIR VALOR EN LA LLB # if not isinstance(ctx.message.channel, discord.channel.DMChannel): llbsult = db.search(Query().servers.all([server])) # doesnt work lleaderboard = {} # Prepares an empty dictionary. for x in llbsult: # For each entry in the database: lleaderboard[x.get("username")] = int( x.get("points") ) # ...save the user's ID and its amount of points in a new Python database. lleaderboard = sorted( lleaderboard.items(), key=lambda x: x[1], reverse=True) # Sort this database by amount of points. s = "" localvalue = 1 for key, value in lleaderboard: # For each value in the new, sorted DB: if key == searchvalor: break else: localvalue += 1 # # GLB BADGE # if result: if leadervalue == 1: leaderemblem = "🥇" elif leadervalue == 2: leaderemblem = "🥈" elif leadervalue == 3: leaderemblem = "🥉" elif leadervalue <= 10: leaderemblem = "🏅" else: leaderemblem = " " else: leaderemblem = " " # # REVISAR ESTATUS DE CURATOR # curatoremblem = "" if not isinstance(ctx.message.channel, discord.channel.DMChannel): curatoremote = self.client.get_emoji(742136325628756000) role = discord.utils.get(ctx.guild.roles, name="Curator") if role in author.roles: curatoremblem = str(curatoremote) # # REVISAR ESTATUS DE BOTOWNER # botemblem = "" for x in botowner: if (int(author.id) == int(x)): botemblem = "👨💻" # # POINTS SENT # sentpoints = post.search(Query().voters.any([author.id])) # # STARS RECEIVED # starlist = post.search(Query().username == str(author.id)) starsrec = 0 for star in starlist: if 'stars' in star: starsrec += star['stars'] # # SUPPORT BADGES (WIP) # #checkM = self.client.get_emoji(741669341409312889) #print(str(checkM)) # # SEND THE EMBED # embed = discord.Embed(title=author.name + ' ' + leaderemblem + str(curatoremblem) + botemblem) embed.set_thumbnail(url=author.avatar_url) if result: embed.add_field(name="Karma", value=result.get('points'), inline=True) else: embed.add_field(name="Karma", value='0', inline=True) if result: embed.add_field(name="Global Rank", value=leadervalue, inline=True) if not isinstance(ctx.message.channel, discord.channel.DMChannel): embed.add_field(name="Local Rank", value=localvalue, inline=True) embed.add_field(name="Reacted posts", value=len(sentpoints), inline=True) embed.add_field(name="Stars received", value=starsrec, inline=True) await ctx.send(embed=embed)