async def degenerates(self, ctx: commands.Context): """ Returns a list of the top anime posters """ userPosts = {} for instance in self.postsDB.query(posts).order_by(posts.name): userPosts[instance.name] = instance.animePosts userPosts = sorted(userPosts.items(), key=lambda x: x[1], reverse=True) totalAnime = 0 output = "" embed = discordEmbed(title="Degeneracy per User this Month", color=0xbf5700) try: for person in userPosts[:10]: output += f"{str(person[0])} - {str(person[1])} posts\n" except: print("10 users haven't posted yet") #Get the total anime posts for person in userPosts: totalAnime += person[1] embed.add_field(name="Posts in #anime", value=output, inline=False) totalAnimeMessage = f"{str(totalAnime)} total posts made in #anime" embed.add_field(name="Collective degeneracy", value=totalAnimeMessage, inline=False) await ctx.send(embed=embed) #This is getting out of hand if totalAnime > 100: ctx.send("https://tenor.com/WmUi.gif")
async def cc_error(self, ctx: commands.Context, error): if isinstance(error, commands.MissingRequiredArgument): if error.param.name == 'command': #Output command list output = [""] i = 0 for instance in self.sessionquery(CCCommand).order_by(CCCommand.name): if (int(len(output[i])/900)) == 1: i = i + 1 output.append("") output[i] += f"{instance.name} " i = 1 for message in output: embed = discordEmbed( title=f'CC commands, pg {i}', color=0xbf5700) embed.add_field( name='All CC commands, times out after 2 minutes', value = message, inline=False) i += 1 await ctx.send(embed=embed, delete_after=120) elif error.param.name == '_responce': #delete a command victim = self.sessionquery(CCCommand).filter_by(name=ctx.args[2]).one() await self.delete_command(ctx, victim)
async def _show_cogs(self, ctx): """Shows loaded/unloaded cogs""" # This function assumes that all cogs are in the cogs folder, # which is currently true. # Extracting filename from __module__ Example: cogs.owner loaded = [c.__module__.split(".")[1] for c in self.bot.cogs.values()] # What's in the folder but not loaded is unloaded #unloaded = [c.split(".")[1] for c in self._list_cogs() # if c.split(".")[1] not in loaded] #if not unloaded: # unloaded = ["None"] '''msg = ("+ Loaded\n" "{}\n\n" "- Unloaded\n" "{}" "".format(", ".join(sorted(loaded)), ", ".join(sorted(unloaded))) )''' embed = discordEmbed(title="Cog Info", color=ctx.message.author.top_role.colour) embed.add_field(name="Loaded", value="{}".format(", ".join(sorted(loaded))), inline=False) await ctx.send(embed=embed)
def createPlayerEmbed(self): ptrStr = [] for i in range(len(self.player_list)): ptrStr.append(f"{i+1}. {self.player_list[i]}\n") self.plEmbed = None self.plEmbed = discordEmbed(title="Cards against humainty game") self.plEmbed.description = f"Host: {self.creator.mention}" self.plEmbed = self.fit1024(ptrStr, self.plEmbed) return self.plEmbed
async def userstats(self, ctx: commands.Context, *user): """ Returns stats about the user, such as amount of monthly posts Usage: $userstats @user Not inputting a user will return the top posters """ if len(user) == 0: #Put users into dictionary userPosts = {} #Iterate through database for instance in self.postsDB.query(posts).order_by(posts.name): userPosts[instance.name] = instance.posts #Sort by amount of posts userPosts = sorted(userPosts.items(), key=lambda x: x[1], reverse=True) output = "" embed = discordEmbed(title="Posts per User this Month", color=0xbf5700) try: for person in userPosts[:10]: output += f"{str(person[0])} - {str(person[1])} posts\n" except: print("10 users haven't posted yet") embed.add_field(name="Total Posts", value=output, inline=False) await ctx.send(embed=embed) else: authorEntry = None for instance in self.postsDB.query(posts).order_by(posts.name): if instance.name == user: authorEntry = instance found = True break if authorEntry != None: await ctx.send( f"{user} has {str(authorEntry.posts)} total posts and {str(authorEntry.animePosts)} posts in #anime this month" ) else: await ctx.send( "User not found or has not posted yet this month")
async def hc_error(self, ctx: commands.Context, error): if isinstance(error, commands.MissingRequiredArgument): if error.param.name == 'command': #print(self.UTBotChecker.in_botspam(ctx)) if await self.UTBotChecker.in_botspam(ctx) == True: #Output the command list output = [""] i = 0 for instance in self.sessionquery(CCCommand).order_by(CCCommand.name): if instance.category == 'help': if (int(len(output[i])/900)) == 1: i = i + 1 output.append("") output[i] += f"{instance.name} " i = 1 for message in output: #print(f"Messages: {message}") embed = discordEmbed( title=f'Help commands, pg {i}', color=0xbf5700) embed.add_field( name='All help commands, times out after 2 minutes', value=message, inline=False) i += 1 await ctx.send(embed=embed, delete_after=120) return else: return #Responce be missing so yeet it elif error.param.name == '_responce': #Make sure they be allowed if await self.UTBotChecker.is_regular(ctx) == True and await self.UTBotChecker.in_secret_channel(ctx) == True: victim = self.sessionquery(CCCommand).filter_by(name=ctx.args[2]).one() if victim.category == 'help': await self.delete_command(ctx, victim) else: await ctx.send("hc can only delete help commands") else: await ctx.send("There was an error, details in log (in function hc_error)") print(f"Error be different:{error}")
async def owner_mod(self, ctx, ownerMod, id=None): """This allows you to modify (and list) the owners of the bot without restarting.""" try: if ownerMod.lower() == "add" and not id == None: for x in range(len(owners)): if owners[x] == str(id): await ctx.send("This user is already an owner.") raise self.NoResponseException owners.append(str(id)) if ownerMod.lower() == "del" and not id == None: if id in ['188493063973371904']: await ctx.send("This user cannot be removed, sorry.") raise self.NoResponseException for x in range(len(owners)): if owners[x] == str(id): del owners[x] if ownerMod.lower() == "list": embed = discordEmbed(title="Owner List", color=ctx.message.author.top_role.colour) embed.add_field(name="-", value="{}".format(", ".join(sorted(owners))), inline=False) await ctx.send(embed=embed) raise self.NoResponseException if not ownerMod.lower() == "list" and id == None: raise self.NoResponseException if not ownerMod.lower() == "list": temp = {"owners": [x for x in owners]} with open("config/owners.json", 'w') as ownerFile: json.dump(temp, ownerFile) await self.mod_extension(ctx, "cogs.owner", "reload") except self.NoResponseException: pass except Exception as unhandled: await ctx.send( f"**`ERROR: {type(unhandled).__name__} - {unhandled}`**") else: await ctx.send(f"**`{ownerMod.upper()} SUCCESS`**")