Beispiel #1
0
 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)))
Beispiel #2
0
 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,
         )
     )
Beispiel #3
0
    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)
Beispiel #4
0
    async def askSpecificServer(
        self,
        ctx,
        server_config,
    ):
        def check(m):
            return m.author == ctx.author and m.channel == ctx.channel

        member = ctx.author
        records = server_config.getAllServers(str(
            member.id))  # Get a list of servers where user is admin
        servers = []
        for record in records:
            guild = self.bot.get_guild(int(record[0]))
            if guild is not None:
                guild_name = guild.name  # Get the guild name from server id
                servers.append(guild_name)
        await ctx.send(embed=embedded.info(ADMIN_REQUEST_SERVER_ID))
        embed = self.generate_embed("Servers", servers)
        await ctx.send(
            embed=embed
        )  # Send a multi-choice option to the user to select a specific server
        message = None
        try:
            # Wait for 5 seconds for response
            message = await self.bot.wait_for("message",
                                              timeout=5.0,
                                              check=check)
        except asyncio.TimeoutError:
            await ctx.send(embed=embedded.error(REQUEST_TIMEOUT)
                           )  # Send a timeout message
            return -1
        index = None
        try:
            index = int(message.content)  # Convert the string to number
        except Exception:
            # If non-numeric characters are passed
            await ctx.send(embed=embedded.error(
                REQUIRE_NUMERICAL_VALUE.format(entity="Server Number")))
            return -1
        if index > len(records):  # Check if index is out of bounds
            await ctx.send(embed=embedded.error(BAD_ARGUMENT))
            return
        return index, records