<commit_before>#
# client.py
#
# discord-analytics - Store Discord records for later analysis
# Copyright (c) 2017 <NAME>
#
# discord-analytics is available free of charge under the terms of the MIT
# License. You are free to redistribute and/or modify it under those
# terms. It is distributed in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY. See the LICENSE file for more details.
#

import discord

__all__ = [
    'LOG_FULL_MESSAGES',
    'make_client',
]

LOG_FULL_MESSAGES = False

from .sql import DiscordSqlHandler
from .util import get_username, get_emoji_name, null_logger

def make_client(config, logger=null_logger):
    client = discord.Client()
    client.ready = False
    sql = DiscordSqlHandler(config['url'], logger)

    def _accept(message):
        if not client.ready:
            logger.warn("Can't log message, not ready yet!")
            return False
        elif not isinstance(message.channel, discord.TextChannel):
            logger.debug("Message not from a guild.")
            logger.debug("Ignoring message.")
            return False
        elif message.guild.id not in config['guilds']:
            logger.debug("Message from a guild we don't care about.")
            logger.debug("Ignoring message.")
            return False
        else:
            return True

    def _log(message, action):
        name = get_username(message.author)
        guild = message.guild.name
        chan = message.channel.name

        logger.info(f"Message {action} by {name} in {guild} #{chan}:")
        if LOG_FULL_MESSAGES:<commit_msg>Replace isinstance() check with hasattr()<commit_after>#
# client.py
#
# discord-analytics - Store Discord records for later analysis
# Copyright (c) 2017 <NAME>
#
# discord-analytics is available free of charge under the terms of the MIT
# License. You are free to redistribute and/or modify it under those
# terms. It is distributed in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY. See the LICENSE file for more details.
#

import discord

__all__ = [
    'LOG_FULL_MESSAGES',
    'make_client',
]

LOG_FULL_MESSAGES = False

from .sql import DiscordSqlHandler
from .util import get_username, get_emoji_name, null_logger

def make_client(config, logger=null_logger):
    client = discord.Client()
    client.ready = False
    sql = DiscordSqlHandler(config['url'], logger)

    def _accept(message):
        if not client.ready:
            logger.warn("Can't log message, not ready yet!")
            return False
        elif not hasattr(message, 'guild'):
            logger.debug("Message not from a guild.")
            logger.debug("Ignoring message.")
            return False
        elif message.guild.id not in config['guilds']:
            logger.debug("Message from a guild we don't care about.")
            logger.debug("Ignoring message.")
            return False
        else:
            return True

    def _log(message, action):
        name = get_username(message.author)
        guild = message.guild.name
        chan = message.channel.name

        logger.info(f"Message {action} by {name} in {guild} #{chan}:")
        if LOG_FULL_MESSAGES:
{'fraction_non_alphanumeric': 0.09168510907366424, 'fraction_numerical': 0.002529244388239014, 'mean_word_length': 2.7621878715814505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844860', 'n_tokens_mistral': 909, 'n_tokens_neox': 869, 'n_words': 303}