<commit_before>import sys

from twisted.internet import defer, protocol, reactor
from twisted.python import log
from twisted.words.protocols import irc


class BasePyConBot(irc.IRCClient):
    accepted_users = ["Alex_Gaynor", "jnoller", "VanL", "tlesher", "jacobkm"]

    def __init__(self):
        self.state_handler = None
        self._namescallback = {}

    def talk_url(self, talk):
        return "http://us.pycon.org/2012/review/%s/" % talk

    @property
    def nickname(self):
        return self.factory.nickname

    def signedOn(self):
        for channel in self.factory.channels:
            self.join(channel)

    def joined(self, channel):
        log.msg("Joined %s" % channel)
        self.msg(channel, "Hello denizens of %s, I am your god." % channel)
        self.msg(channel, "To contribute to me: https://github.com/alex/THUNDERDOME-BOT")

    def privmsg(self, user, channel, message):
        user = user.split("!")[0]
        if not message.startswith(","):
            if self.state_handler is not None:
                self.state_handler(channel, user, message)
            return
        if user not in self.accepted_users:
            return
        message = message[1:]
        command_parts = message.split()
        command, command_args = command_parts[0], command_parts[1:]
        if command not in self.commands:
            self.msg(channel, "%s: I don't recognize that command" % user)
            return
        action = getattr(self, "handle_%s" % command)
        action(channel, *command_args)

    def names(self, channel):
        channel = channel.lower()
        d = defer.Deferred()
        self._namescallback.setdefault(channel, [[], []])[0].append(d)
        self.sendLine("NAMES %s" % channel)
        return d

    def irc_RPL_NAMREPLY(self, prefix, params):
        channel = params[2].lower()
        if channel not in self._namescallback:
            return
        nicklist = [name.strip('@+') for name in params[3].split(' ')]
        self._namescallback[channel][1] += nicklist

    def irc_RPL_ENDOFNAMES(self, prefix, params):
        channel = params[1].lower()
        if channel not in self._namescallback:
            return
        callbacks, namelist = self._namescallback[channel]
        for cb in callbacks:
            cb.callback(namelist)
        del self._namescallback[channel]
        
class BasePyConBotFactory(protocol.ClientFactory):
    def __init__(self, channels, nickname):
        self.channels = channels
        self.nickname = nickname


    def clientConnectionLost(self, connector, reason):
        log.msg("Lost connection: %s" % reason)
        connector.connect()

    def clientConnectionFailed(self, connector, reason):
        log.msg("Connection failed: %s" % reason)<commit_msg>Someone's been a bad boy!<commit_after>import sys

from twisted.internet import defer, protocol, reactor
from twisted.python import log
from twisted.words.protocols import irc


class BasePyConBot(irc.IRCClient):
    accepted_users = ["Alex_Gaynor", "VanL", "tlesher", "jacobkm"]

    def __init__(self):
        self.state_handler = None
        self._namescallback = {}

    def talk_url(self, talk):
        return "http://us.pycon.org/2012/review/%s/" % talk

    @property
    def nickname(self):
        return self.factory.nickname

    def signedOn(self):
        for channel in self.factory.channels:
            self.join(channel)

    def joined(self, channel):
        log.msg("Joined %s" % channel)
        self.msg(channel, "Hello denizens of %s, I am your god." % channel)
        self.msg(channel, "To contribute to me: https://github.com/alex/THUNDERDOME-BOT")

    def privmsg(self, user, channel, message):
        user = user.split("!")[0]
        if not message.startswith(","):
            if self.state_handler is not None:
                self.state_handler(channel, user, message)
            return
        if user not in self.accepted_users:
            return
        message = message[1:]
        command_parts = message.split()
        command, command_args = command_parts[0], command_parts[1:]
        if command not in self.commands:
            self.msg(channel, "%s: I don't recognize that command" % user)
            return
        action = getattr(self, "handle_%s" % command)
        action(channel, *command_args)

    def names(self, channel):
        channel = channel.lower()
        d = defer.Deferred()
        self._namescallback.setdefault(channel, [[], []])[0].append(d)
        self.sendLine("NAMES %s" % channel)
        return d

    def irc_RPL_NAMREPLY(self, prefix, params):
        channel = params[2].lower()
        if channel not in self._namescallback:
            return
        nicklist = [name.strip('@+') for name in params[3].split(' ')]
        self._namescallback[channel][1] += nicklist

    def irc_RPL_ENDOFNAMES(self, prefix, params):
        channel = params[1].lower()
        if channel not in self._namescallback:
            return
        callbacks, namelist = self._namescallback[channel]
        for cb in callbacks:
            cb.callback(namelist)
        del self._namescallback[channel]

class BasePyConBotFactory(protocol.ClientFactory):
    def __init__(self, channels, nickname):
        self.channels = channels
        self.nickname = nickname


    def clientConnectionLost(self, connector, reason):
        log.msg("Lost connection: %s" % reason)
        connector.connect()

    def clientConnectionFailed(self, connector, reason):
        log.msg("Connection failed: %s" % reason)
{'fraction_non_alphanumeric': 0.11403350747613043, 'fraction_numerical': 0.00468384074941452, 'mean_word_length': 2.549872122762148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6228067', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1587, 'n_words': 412}