<commit_before>import socket
import requests


class TwitchSocket(object):

    def __init__(self, pw, user, channel):
        self.host = 'irc.chat.twitch.tv'
        self.port = 6667
        self.pw = pw
        self.user = user
        self.channel = channel
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.join_room()

    def send_message(self, message):
        message_temp = "PRIVMSG #" + self.channel + " :" + message
        self.sock.send("{}\r\n".format(message_temp).encode('utf-8'))

    def send_whisper(self, user, message):
        message_temp = "PRIVMSG #jtv :/w " + user + " " + message
        self.sock.send("{}\r\n".format(message_temp).encode('utf-8'))

    def join_room(self):
        self.sock.connect((self.host, self.port))
        self.sock.send("PASS {PASS}\r\n".format(PASS=self.pw).encode('utf-8'))
        self.sock.send("NICK {USER}\r\n".format(USER=self.user).encode('utf-8'))
        self.sock.send("JOIN #{CHANNEL}\r\n".format(CHANNEL=self.channel).encode('utf-8'))

        messages = ""
        loading = True
        while loading:
            try:
                read_buffer = self.sock.recv(1024)
                messages = messages + read_buffer.decode('utf-8')
                last_message = messages.split('\r\n')[-2]
                messages = ""
                if "End of /NAMES list" in last_message:
                    loading = False
                else:
                    loading = True
            except:
                continue
        self.sock.send("CAP REQ :twitch.tv/commands\r\n".encode('utf-8'))
        self.sock.send("CAP REQ :twitch.tv/tags\r\n".encode('utf-8'))

    def get_user(self, line):
        line_list = line.split(':', 2)
        user = line_list[-2].split('!')[0]
        return user

    def get_human_readable_message(self, line):
        if 'emotes=;' in line:
            num_colons = 2
        else:
            num_colons = 3
        if "PRIVMSG" in line or ("WHISPER" in line and self.get_user(line) in self.get_mods()):
            line_list = line.split(':', num_colons)<commit_msg>Fixed a bug in the get_user function where it would break if the message had emotes in it. Silly twitch is silly.<commit_after>import socket
import requests


class TwitchSocket(object):

    def __init__(self, pw, user, channel):
        self.host = 'irc.chat.twitch.tv'
        self.port = 6667
        self.pw = pw
        self.user = user
        self.channel = channel
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.join_room()

    def send_message(self, message):
        message_temp = "PRIVMSG #" + self.channel + " :" + message
        self.sock.send("{}\r\n".format(message_temp).encode('utf-8'))

    def send_whisper(self, user, message):
        message_temp = "PRIVMSG #jtv :/w " + user + " " + message
        self.sock.send("{}\r\n".format(message_temp).encode('utf-8'))

    def join_room(self):
        self.sock.connect((self.host, self.port))
        self.sock.send("PASS {PASS}\r\n".format(PASS=self.pw).encode('utf-8'))
        self.sock.send("NICK {USER}\r\n".format(USER=self.user).encode('utf-8'))
        self.sock.send("JOIN #{CHANNEL}\r\n".format(CHANNEL=self.channel).encode('utf-8'))

        messages = ""
        loading = True
        while loading:
            try:
                read_buffer = self.sock.recv(1024)
                messages = messages + read_buffer.decode('utf-8')
                last_message = messages.split('\r\n')[-2]
                messages = ""
                if "End of /NAMES list" in last_message:
                    loading = False
                else:
                    loading = True
            except:
                continue
        self.sock.send("CAP REQ :twitch.tv/commands\r\n".encode('utf-8'))
        self.sock.send("CAP REQ :twitch.tv/tags\r\n".encode('utf-8'))

    def get_user(self, line):
        if 'emotes=;' in line:
            num_colons = 2
        else:
            num_colons = 3
        line_list = line.split(':', num_colons)
        user = line_list[-2].split('!')[0]
        return user

    def get_human_readable_message(self, line):
        if 'emotes=;' in line:
            num_colons = 2
        else:
            num_colons = 3
        if "PRIVMSG" in line or ("WHISPER" in line and self.get_user(line) in self.get_mods()):
            line_list = line.split(':', num_colons)
{'fraction_non_alphanumeric': 0.14453477868112014, 'fraction_numerical': 0.01016260162601626, 'mean_word_length': 1.9945909398242054, 'pattern_counts': {'":': 0, '<': 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': '3986188', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1391, 'n_words': 279}