<commit_before>import asyncio
import discord
import logging
import traceback
from libs import banpool
from discord import Embed, Color

print("[Public Plugin] <banpool_manager.py>: This plugin manages the banpool.")

# Setup the BanPoolManager
banpool_manager = banpool.BanPoolManager()

# Setup Logging
logger = logging.getLogger('banpool_manager')
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('banpool.log')
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(fh)

help_string = """
**BanPool Commands**
BanPool is a Discord bot that automatically coordinates bans between Discord servers which have the bot.
All commands start with `!bp`. Do not include the `<` or `>` brackets in your commands.

```
!bp help - this command

!bp list - list all available banpools. Currently only 'global' is used

!bp listusers <BANPOOL_NAME> - list all user IDs in the banpool

!bp adduser <BANPOOL_NAME> <USER_ID> - add user ID to the banpool

!bp adduserlist <BANPOOL_NAME> <USER_ID_LIST> - ban a list of user IDs, separated by commas

!bp listexception - list all of the ban exceptions: a user ID and Server ID pair

!bp addexception <USER_ID> <SERVER_ID> - add a ban exception pair for user ID and Server ID

!bp removeuser <BANPOOL_NAME> <USER_ID> - remove user ID from the banpool

!bp removeexception <USER_ID> <SERVER_ID> - remove a ban exception pair for user ID and Server ID

!bp isuserbanned <USER_ID> - check if the user ID is in any banpools

!bp getuserinfo <USER_ID> - check to see if the user ID is present in any servers
```
"""


def chunks(l, n):
    # Stolen from: https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks
    for i in range(0, len(l), n):
        yield l[i:i + n]


@asyncio.coroutine
async def action(message, client, config):
    """
    Config Values:
    [banpool]
    # The Discord ID of the Admin user
    admin_server_id =
    admin_group =
    admin_chan =
    # the time to wait between executing scheduled tasks in seconds
    task_length =

    :param message: discord message obj
    :param client: discord client obj
    :param config: config obj
    :return:
    """

    # get config values
    admin_server_id = config.get('banpool', 'admin_server_id')
    admin_group = config.get('banpool', 'admin_group')
    admin_chan = config.get('banpool', 'admin_chan')

    server_id = message.server.id
    source_chan = message.channel.name

    try:

        if server_id == admin_server_id and source_chan == admin_chan:
            in_admin_group = discord.utils.get(message.author.roles, name=admin_group)

            if in_admin_group:
                split_content = message.content.split()

                if split_content[0] == '!bp':

                    if split_content[1] == 'help':
                        await client.send_message(message.channel, help_string)

                    if split_content[1] == 'list':
                        banpool_list = banpool_manager.banpool_list()
                        bp_embed = Embed(title="Active BanPools", color=Color.green())

                        for bp in banpool_list:
                            bp_embed.add_field(name=bp.pool_name, value=bp.pool_description, inline=True)
                        await client.send_message(message.channel, embed=bp_embed)

                    if split_content[1] == 'listusers' and len(split_content) == 3:
                        banpool_name = split_content[2]
                        userlist = banpool_manager.banpool_user_list(banpool_name)

                        ul_embed = Embed(title=banpool_name + " banned IDs", color=Color.green())

                        if userlist:
                            # Split the list into chunks
                            user_chunks = chunks(userlist, 25)
                            for chunk in user_chunks:
                                field_string = ''
                                for user in chunk:
                                    field_string += str(user.user_id) + "\n"<commit_msg>adding count to banned user list<commit_after>import asyncio
import discord
import logging
import traceback
from libs import banpool
from discord import Embed, Color

print("[Public Plugin] <banpool_manager.py>: This plugin manages the banpool.")

# Setup the BanPoolManager
banpool_manager = banpool.BanPoolManager()

# Setup Logging
logger = logging.getLogger('banpool_manager')
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('banpool.log')
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(fh)

help_string = """
**BanPool Commands**
BanPool is a Discord bot that automatically coordinates bans between Discord servers which have the bot.
All commands start with `!bp`. Do not include the `<` or `>` brackets in your commands.

```
!bp help - this command

!bp list - list all available banpools. Currently only 'global' is used

!bp listusers <BANPOOL_NAME> - list all user IDs in the banpool

!bp adduser <BANPOOL_NAME> <USER_ID> - add user ID to the banpool

!bp adduserlist <BANPOOL_NAME> <USER_ID_LIST> - ban a list of user IDs, separated by commas

!bp listexception - list all of the ban exceptions: a user ID and Server ID pair

!bp addexception <USER_ID> <SERVER_ID> - add a ban exception pair for user ID and Server ID

!bp removeuser <BANPOOL_NAME> <USER_ID> - remove user ID from the banpool

!bp removeexception <USER_ID> <SERVER_ID> - remove a ban exception pair for user ID and Server ID

!bp isuserbanned <USER_ID> - check if the user ID is in any banpools

!bp getuserinfo <USER_ID> - check to see if the user ID is present in any servers
```
"""


def chunks(l, n):
    # Stolen from: https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks
    for i in range(0, len(l), n):
        yield l[i:i + n]


@asyncio.coroutine
async def action(message, client, config):
    """
    Config Values:
    [banpool]
    # The Discord ID of the Admin user
    admin_server_id =
    admin_group =
    admin_chan =
    # the time to wait between executing scheduled tasks in seconds
    task_length =

    :param message: discord message obj
    :param client: discord client obj
    :param config: config obj
    :return:
    """

    # get config values
    admin_server_id = config.get('banpool', 'admin_server_id')
    admin_group = config.get('banpool', 'admin_group')
    admin_chan = config.get('banpool', 'admin_chan')

    server_id = message.server.id
    source_chan = message.channel.name

    try:

        if server_id == admin_server_id and source_chan == admin_chan:
            in_admin_group = discord.utils.get(message.author.roles, name=admin_group)

            if in_admin_group:
                split_content = message.content.split()

                if split_content[0] == '!bp':

                    if split_content[1] == 'help':
                        await client.send_message(message.channel, help_string)

                    if split_content[1] == 'list':
                        banpool_list = banpool_manager.banpool_list()
                        bp_embed = Embed(title="Active BanPools", color=Color.green())

                        for bp in banpool_list:
                            bp_embed.add_field(name=bp.pool_name, value=bp.pool_description, inline=True)
                        await client.send_message(message.channel, embed=bp_embed)

                    if split_content[1] == 'listusers' and len(split_content) == 3:
                        banpool_name = split_content[2]
                        userlist = banpool_manager.banpool_user_list(banpool_name)
                        ul_embed = Embed(title=banpool_name + " banned IDs", color=Color.green())

                        if userlist:
                            userlist_len = str(len(userlist))
                            ul_embed.title = banpool_name + ": {} banned IDs".format(userlist_len)
                            # Split the list into chunks
                            user_chunks = chunks(userlist, 25)
                            for chunk in user_chunks:
                                field_string = ''
                                for user in chunk:
                                    field_string += str(user.user_id) + "\n"
{'fraction_non_alphanumeric': 0.09234676209165416, 'fraction_numerical': 0.003463003578437031, 'mean_word_length': 2.5162337662337664, 'pattern_counts': {'":': 1, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '344158', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2482, 'n_words': 746}