async def setcount(self, ctx, arg=None): if arg is None: await ctx.send(embed=embedded.error(BAD_ARGUMENT)) return count = None try: count = int(arg) # Value to set the count config to except Exception: # If numerical value is not passed await ctx.send(embed=embedded.error( REQUIRE_NUMERICAL_VALUE.format( entity="Toxic Count Threshold Per User"))) return member = ctx.author server_config = ServerConfig() SERVER_OWNER_ID = str(member.id) SERVER_ID = 0 try: # Get the server config for servers that the user is an admin SERVER_ID = server_config.modifyServerConfig(SERVER_OWNER_ID, count=count) except AttributeError: # If admin of multiple servers index, records = await self.askSpecificServer(ctx, server_config) if index == -1: return SERVER_ID = str(records[index - 1][0]) # Modify the server config for a particular server SERVER_ID = server_config.modifyServerConfig(SERVER_OWNER_ID, server_id=SERVER_ID, count=count) guild = self.bot.get_guild(int(SERVER_ID)) guild_name = guild.name if guild is not None else "" await ctx.send(embed=embedded.success( SUCCESSFUL_UPDATE.format(entity="Toxic Count Threshold Per User", server=guild_name)))
async def setdays(self, ctx, arg=None): if arg is None: await ctx.send(BAD_ARGUMENT) return days = None try: days = int(arg) except Exception: await ctx.send(REQUIRE_NUMERICAL_VALUE.format(entity="Days before resetting toxic count for an user")) return member = ctx.author server_config = ServerConfig() SERVER_OWNER_ID = str(member.id) SERVER_ID = 0 try: # Get the server config for servers that the user is an admin SERVER_ID = server_config.modifyServerConfig(SERVER_OWNER_ID, threshold=days) except AttributeError: # Admin of multiple servers index, records = await self.askSpecificServer(ctx, server_config) if index == -1: return SERVER_ID = str(records[index - 1][0]) # Modify the server config for a particular server SERVER_ID = server_config.modifyServerConfig(SERVER_OWNER_ID, server_id=SERVER_ID, threshold=days) guild = self.bot.get_guild(int(SERVER_ID)) guild_name = guild.name if guild is not None else "" # Send a success message to the user await ctx.send( SUCCESSFUL_UPDATE.format( entity="Days before resetting toxic count for an user", server=guild_name, ) )
async def help(self, ctx): member = ctx.author server_config = ServerConfig() try: server_config.getConfigFromUser(str(member.id)) except commands.NotOwner: # User does not own a server await ctx.send(HELP_MESSAGE.format(username=member.name)) return except AttributeError: pass await ctx.send(ADMIN_HELP_MESSAGE.format(username=member.name))
async def toptoxic(self, ctx, arg=None): if arg is None: await ctx.send(embed=embedded.error(BAD_ARGUMENT)) return top = None try: top = int(arg) except Exception: await ctx.send(embed=embedded.error( REQUIRE_NUMERICAL_VALUE.format( entity="Number of entries required"))) return member = ctx.author server_config = ServerConfig() SERVER_OWNER_ID = str(member.id) SERVER_ID = "-1" try: # Get the server config for servers that the user is an admin record = server_config.getConfigFromUser(SERVER_OWNER_ID) SERVER_ID = str(record[0]) except AttributeError: # Admin of multiple servers index, records = await self.askSpecificServer(ctx, server_config) if index == -1: return # Get the particular server id SERVER_ID = str(records[index - 1][0]) toxic_count_obj = ToxicCount() top_records = toxic_count_obj.getTopRecords(SERVER_ID, top) users = [] for top_record in top_records: user_id = top_record[1] # Get the user id user = self.bot.get_user( int(user_id)) # Get the User object from user_id if user is not None: users.append({ "toxic_count": top_record[2], "username": user.name, }) # Embed the response embed = discord.Embed() embed = discord.Embed(title=f"Top {top} toxic users") for index, user in enumerate(users): index_humanize = index + 1 embed.add_field( name= f"{index_humanize}. {user['username']} || {user['toxic_count']} ", value="______", inline=False, ) await ctx.send(embed=embed)
async def on_guild_join(self, guild): server_config = ServerConfig() SERVER_ID = str(guild.id) SERVER_OWNER_ID = str(guild.owner_id) # Create the configurations for the server server_config.createServerConfig(SERVER_ID, SERVER_OWNER_ID) # Doesn't work as it returns None always ( BUG ) owner = self.bot.get_user(int(SERVER_OWNER_ID)) if owner is None: # Send a message to the general channel general = find(lambda x: x.name == "general", guild.text_channels) if general and general.permissions_for(guild.me).send_messages: await general.send(ADMIN_MESSAGE_AFTER_BOT_JOIN) else: await owner.create_dm() await owner.dm_channel.send(ADMIN_MESSAGE_AFTER_BOT_JOIN)
async def config(self, ctx): member = ctx.author server_config = ServerConfig() record = None try: # Get the server config for servers that the user is an admin record = server_config.getConfigFromUser(str(member.id)) except AttributeError: # Attribute error means the user is the admin of multiple servers index, records = await self.askSpecificServer(ctx, server_config) if index == -1: return record = records[index - 1] # Get the specific server SERVER_ID = record[0] guild = self.bot.get_guild(int(SERVER_ID)) guild_name = guild.name if guild is not None else "" await ctx.send(ADMIN_CONFIG.format(guild=guild_name, count=record[1], time=record[2]))