<commit_before>import logging
import re

from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
from socbot.pluginbase import InsuffPerms, BadParams

from socbot.usermanager import UserManager

# Credits to ibid for some helpful code:
# - Ping ponger

class Bot(irc.IRCClient):
    nickname = "SocBot"
    sourceURL = "http://github.com/entityreborn/SocBot/"

    _ping_deferred = None
    _reconnect_deferred = None

    def __init__(self):
        self.factory = None
        self.log = None
        self.shutdown = False
        self.channels = []

    def _idle_ping(self):
        self.log.debug("sending idle ping")

        self._ping_deferred = None
        self._reconnect_deferred = reactor.callLater(
            self.factory.pong_timeout, self._timeout_reconnect)

        self.sendLine('PING idle-socbot')

    def _timeout_reconnect(self):
        self.log.info("idle timeout; reconnecting")
        self.transport.loseConnection()

    def dataReceived(self, data):
        irc.IRCClient.dataReceived(self, data)

        if self._ping_deferred is not None:
            self._ping_deferred.reset(self.factory.ping_interval)

    def irc_PONG(self, prefix_unused, params):
        if params[-1] == 'idle-socbot' and self._reconnect_deferred:
            self.log.debug("received idle pong")

            self._reconnect_deferred.cancel()

            self._reconnect_deferred = None
            self._ping_deferred = reactor.callLater(
                self.factory.ping_interval, self._idle_ping)

    def doJoins(self):
        if self.factory.config["channels"]:
            for channel, chanconfig in self.factory.config["channels"].iteritems():
                if not chanconfig["autojoin"]:
                    continue

                if chanconfig["password"]:
                    self.join(channel, chanconfig["password"])
                else:
                    self.join(channel)

    def irc_ERR_NOMOTD(self, prefix, params):
        self.log.info("no MOTD")
        self.doJoins()

    def receivedMOTD(self, motd):
        self.log.info("received MOTD")
        self.doJoins()

    def sendLine(self, line):
        self.log.debug("sending line `{0}`".format(line))

        irc.IRCClient.sendLine(self, line)

        if self._ping_deferred is not None:
            self._ping_deferred.reset(self.factory.ping_interval)

    def connectionMade(self):
        self.log.info("connected to server")

        self.factory.resetDelay()
        self.factory.addBot(self)

        irc.IRCClient.connectionMade(self)
        self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)

    def connectionLost(self, reason):
        self.log.info("lost connection: {0}".format(reason))

        irc.IRCClient.connectionLost(self, reason)

        if self.shutdown:
            self.factory.removeBot(self)

    def handleCommand(self, command, prefix, params):
        self.log.debug("command `{0}`, from prefix `{1}`".format(
            command, prefix))

        self.factory.sstate["pluginmanager"].triggerEvent(command,
            self, command, prefix, params)

        irc.IRCClient.handleCommand(self, command, prefix, params)

    def privmsg(self, user, channel, msg):
        msg = msg.strip()
        nick, hostmask = user.split("!")
        wasprivate = False

        if not msg:
            return

        match = re.search('^[ ]*{0}[:,][ ]*(.*)$'.format(self.nickname), msg)

        if channel.lower() != self.nickname.lower():
            if match:
                msg = match.group(1)
            elif msg[0] in self.factory.sstate['baseconfig']['general']['commandchars']:
                msg = msg[1:]
        else:
            wasprivate = True
            channel = user.split("!")[0]

        trigger = msg.split()[0].upper()
        usr = self.factory.users[nick]
        pm = self.factory.sstate["pluginmanager"]
        splitmsg = msg.split()
        details = {
            "fullmsg": msg,
            "splitmsg": splitmsg,
            "trigger": splitmsg.pop(0),
            "channel": channel,
            "wasprivate": wasprivate
        }

        if trigger in pm.triggers:
            self.log.debug("trigger: {0}".format(trigger))

            func = pm.getTrigger(trigger)

            try:<commit_msg>Case sensitive typo<commit_after>import logging
import re

from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
from socbot.pluginbase import InsuffPerms, BadParams

from socbot.usermanager import UserManager

# Credits to ibid for some helpful code:
# - Ping ponger

class Bot(irc.IRCClient):
    nickname = "SocBot"
    sourceURL = "http://github.com/entityreborn/SocBot/"

    _ping_deferred = None
    _reconnect_deferred = None

    def __init__(self):
        self.factory = None
        self.log = None
        self.shutdown = False
        self.channels = []

    def _idle_ping(self):
        self.log.debug("sending idle ping")

        self._ping_deferred = None
        self._reconnect_deferred = reactor.callLater(
            self.factory.pong_timeout, self._timeout_reconnect)

        self.sendLine('PING idle-socbot')

    def _timeout_reconnect(self):
        self.log.info("idle timeout; reconnecting")
        self.transport.loseConnection()

    def dataReceived(self, data):
        irc.IRCClient.dataReceived(self, data)

        if self._ping_deferred is not None:
            self._ping_deferred.reset(self.factory.ping_interval)

    def irc_PONG(self, prefix_unused, params):
        if params[-1] == 'idle-socbot' and self._reconnect_deferred:
            self.log.debug("received idle pong")

            self._reconnect_deferred.cancel()

            self._reconnect_deferred = None
            self._ping_deferred = reactor.callLater(
                self.factory.ping_interval, self._idle_ping)

    def doJoins(self):
        if self.factory.config["channels"]:
            for channel, chanconfig in self.factory.config["channels"].iteritems():
                if not chanconfig["autojoin"]:
                    continue

                if chanconfig["password"]:
                    self.join(channel, chanconfig["password"])
                else:
                    self.join(channel)

    def irc_ERR_NOMOTD(self, prefix, params):
        self.log.info("no MOTD")
        self.doJoins()

    def receivedMOTD(self, motd):
        self.log.info("received MOTD")
        self.doJoins()

    def sendLine(self, line):
        self.log.debug("sending line `{0}`".format(line))

        irc.IRCClient.sendLine(self, line)

        if self._ping_deferred is not None:
            self._ping_deferred.reset(self.factory.ping_interval)

    def connectionMade(self):
        self.log.info("connected to server")

        self.factory.resetDelay()
        self.factory.addBot(self)

        irc.IRCClient.connectionMade(self)
        self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)

    def connectionLost(self, reason):
        self.log.info("lost connection: {0}".format(reason))

        irc.IRCClient.connectionLost(self, reason)

        if self.shutdown:
            self.factory.removeBot(self)

    def handleCommand(self, command, prefix, params):
        self.log.debug("command `{0}`, from prefix `{1}`".format(
            command, prefix))

        self.factory.sstate["pluginmanager"].triggerEvent(command,
            self, command, prefix, params)

        irc.IRCClient.handleCommand(self, command, prefix, params)

    def privmsg(self, user, channel, msg):
        msg = msg.strip()
        nick, hostmask = user.split("!")
        wasprivate = False

        if not msg:
            return

        match = re.search('^[ ]*{0}[:,][ ]*(.*)$'.format(self.nickname), msg)

        if channel.lower() != self.nickname.lower():
            if match:
                msg = match.group(1)
            elif msg[0] in self.factory.sstate['baseconfig']['general']['commandchars']:
                msg = msg[1:]
        else:
            wasprivate = True
            channel = user.split("!")[0]

        trigger = msg.split()[0].upper()
        usr = self.factory.users[nick]
        pm = self.factory.sstate["pluginmanager"]
        splitmsg = msg.split()
        details = {
            "fullmsg": msg,
            "splitmsg": splitmsg,
            "trigger": splitmsg.pop(0).lower(),
            "channel": channel,
            "wasprivate": wasprivate
        }

        if trigger in pm.triggers:
            self.log.debug("trigger: {0}".format(trigger))

            func = pm.getTrigger(trigger)

            try:
{'fraction_non_alphanumeric': 0.11731391585760517, 'fraction_numerical': 0.003005085529357374, 'mean_word_length': 2.231142643764003, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, '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': '2588040', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2483, 'n_words': 511}