<commit_before>import sys, platform, os, traceback, datetime, codecs, argparse
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, threads

from IRCResponse import IRCResponse, ResponseType
from IRCMessage import IRCMessage, IRCChannel, IRCUser
from CommandHandler import AutoLoadCommands
import GlobalVars, ServerInfo

parser = argparse.ArgumentParser(description='An IRC bot written in Python.')
parser.add_argument('-s', '--server', help='the IRC server to connect to (required)', type=str, required=True)
parser.add_argument('-p', '--port', help='the port on the server to connect to (default 6667)', type=int, default=6667)
parser.add_argument('-c', '--channels', help='channels to join after connecting (default none)', type=str, nargs='+', default=[])
parser.add_argument('-n', '--nick', help='the nick the bot should use (default PyMoronBot)', type=str, default='PyMoronBot')
cmdArgs = parser.parse_args()

restarting = False
startTime = datetime.datetime.utcnow()

class MoronBot(irc.IRCClient):

    GlobalVars.CurrentNick = cmdArgs.nick

    nickname = GlobalVars.CurrentNick
    
    realname = GlobalVars.CurrentNick
    username = GlobalVars.CurrentNick
    
    channels = {}
    userModes = {}

    fingerReply = GlobalVars.finger
    
    versionName = GlobalVars.CurrentNick
    versionNum = GlobalVars.version
    versionEnv = platform.platform()
    
    sourceURL = GlobalVars.source
    
    responses = []

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

        global startTime
        startTime = datetime.datetime.utcnow()
    
    def privmsg(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('PRIVMSG', user, chan, msg)
        self.log(u'<{0}> {1}'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)

    def action(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('ACTION', user, chan, msg)
        self.log(u'*{0} {1}*'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)
    
    def noticed(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('NOTICE', user, chan, msg)
        self.log(u'[{0}] {1}'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)
    
    def irc_NICK(self, prefix, params):
        userArray = prefix.split('!')
        oldnick = userArray[0]
        newnick = params[0]

        for key in self.channels:
            channel = self.channels[key]
            for userKey in channel.Users:
                user = channel.Users[userKey]
                if userKey == oldnick:
                    channel.Users[newnick] = IRCUser('{0}!{1}@{2}'.format(newnick, user.User, user.Hostmask))
                    del channel.Users[oldnick]
                    self.log(u'{0} is now known as {1}'.format(oldnick, newnick), channel.Name)

    def nickChanged(self, nick):
        self.nickname = nick
        GlobalVars.CurrentNick = nick
    
    def irc_JOIN(self, prefix, params):
        if params[0] in self.channels:
            channel = self.channels[params[0]]
        else:
            channel = IRCChannel(params[0])<commit_msg>Update channel ranks on nick changes<commit_after>import sys, platform, os, traceback, datetime, codecs, argparse
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, threads

from IRCResponse import IRCResponse, ResponseType
from IRCMessage import IRCMessage, IRCChannel, IRCUser
from CommandHandler import AutoLoadCommands
import GlobalVars, ServerInfo

parser = argparse.ArgumentParser(description='An IRC bot written in Python.')
parser.add_argument('-s', '--server', help='the IRC server to connect to (required)', type=str, required=True)
parser.add_argument('-p', '--port', help='the port on the server to connect to (default 6667)', type=int, default=6667)
parser.add_argument('-c', '--channels', help='channels to join after connecting (default none)', type=str, nargs='+', default=[])
parser.add_argument('-n', '--nick', help='the nick the bot should use (default PyMoronBot)', type=str, default='PyMoronBot')
cmdArgs = parser.parse_args()

restarting = False
startTime = datetime.datetime.utcnow()

class MoronBot(irc.IRCClient):

    GlobalVars.CurrentNick = cmdArgs.nick

    nickname = GlobalVars.CurrentNick
    
    realname = GlobalVars.CurrentNick
    username = GlobalVars.CurrentNick
    
    channels = {}
    userModes = {}

    fingerReply = GlobalVars.finger
    
    versionName = GlobalVars.CurrentNick
    versionNum = GlobalVars.version
    versionEnv = platform.platform()
    
    sourceURL = GlobalVars.source
    
    responses = []

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

        global startTime
        startTime = datetime.datetime.utcnow()
    
    def privmsg(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('PRIVMSG', user, chan, msg)
        self.log(u'<{0}> {1}'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)

    def action(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('ACTION', user, chan, msg)
        self.log(u'*{0} {1}*'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)
    
    def noticed(self, user, channel, msg):
        chan = self.getChannel(channel)
        message = IRCMessage('NOTICE', user, chan, msg)
        self.log(u'[{0}] {1}'.format(message.User.Name, message.MessageString), message.ReplyTo)
        self.handleMessage(message)
    
    def irc_NICK(self, prefix, params):
        userArray = prefix.split('!')
        oldnick = userArray[0]
        newnick = params[0]

        for key in self.channels:
            channel = self.channels[key]
            for userKey in channel.Users:
                user = channel.Users[userKey]
                if userKey == oldnick:
                    channel.Users[newnick] = IRCUser('{0}!{1}@{2}'.format(newnick, user.User, user.Hostmask))
                    del channel.Users[oldnick]
                    if oldnick in channel.Ranks:
                        channel.Ranks[newnick] = channel.Ranks[oldnick]
                        del channel.Ranks[newnick]
                    self.log(u'{0} is now known as {1}'.format(oldnick, newnick), channel.Name)

    def nickChanged(self, nick):
        self.nickname = nick
        GlobalVars.CurrentNick = nick
    
    def irc_JOIN(self, prefix, params):
        if params[0] in self.channels:
            channel = self.channels[params[0]]
        else:
            channel = IRCChannel(params[0])
{'fraction_non_alphanumeric': 0.1179702183027324, 'fraction_numerical': 0.0069394246060430825, 'mean_word_length': 2.973578403216542, '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': '1006446', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2028, 'n_words': 496}