<commit_before>#!/usr/bin/python2
# -*- coding: utf-8 -*-
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers
import ConfigParser
import logging
import socket
import time
import re
import os
import commands
import sys, traceback

config = ConfigParser.ConfigParser()
config.read(os.path.join(os.path.dirname(os.path.realpath(__file__)),'settings.ini'))

logging.basicConfig(level=logging.DEBUG)

is_command_pattern = re.compile('\![a-zA-Z0-9]+')

class IRCHandler(DefaultCommandHandler):
    def endofmotd(self, server, target, text):
        for channel in config.get('irc', 'channels').split(','):
            helpers.join(self.client, channel)

    def nicknameinuse(self, server, wtf, nick, reason):
        helpers.nick(self.client, nick+'_')

    def privmsg(self, sender, chan, msg):
        if msg[0] == '!':
            s = msg.split(' ')
            if is_command_pattern.match(s[0]):
                command = s[0][1:]
                arguments = s[1:]
                nick = sender.split('!')[0]

                if hasattr(commands, command) and callable(getattr(commands, command)):
                    try:
                        response = getattr(commands, command)(nick, chan, arguments, sender, config, self)
                    except:
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout)
                        response = 'Coś poszło nie tak…'

                    if response is not None:
                        helpers.msg(self.client, chan, nick+": "+response)

cli = IRCClient(IRCHandler, host=config.get('irc', 'server'), port=config.getint('irc', 'port'), nick=config.get('irc', 'nick'))

try:
    conn = cli.connect()
except:
    time.sleep(10)
    conn = cli.connect()

while True:
    try:
        conn.next()
    except KeyboardInterrupt:
        conn.close()
        quit()
    except socket.error as e:
        print "Socket error (%d) reconnecting after delay" % e
        time.sleep(10)
        print "Now"
        conn = cli.connect()<commit_msg>Blocking, non-blocking, who cares ;)<commit_after>#!/usr/bin/python2
# -*- coding: utf-8 -*-
from oyoyo.client import IRCClient, IRCApp
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers
import ConfigParser
import logging
import socket
import time
import re
import os
import commands
import sys, traceback

config = ConfigParser.ConfigParser()
config.read(os.path.join(os.path.dirname(os.path.realpath(__file__)),'settings.ini'))

logging.basicConfig(level=logging.DEBUG)

is_command_pattern = re.compile('\![a-zA-Z0-9]+')

class IRCHandler(DefaultCommandHandler):
    def endofmotd(self, server, target, text):
        for channel in config.get('irc', 'channels').split(','):
            helpers.join(self.client, channel)

    def nicknameinuse(self, server, wtf, nick, reason):
        helpers.nick(self.client, nick+'_')

    def privmsg(self, sender, chan, msg):
        if msg[0] == '!':
            s = msg.split(' ')
            if is_command_pattern.match(s[0]):
                command = s[0][1:]
                arguments = s[1:]
                nick = sender.split('!')[0]

                if hasattr(commands, command) and callable(getattr(commands, command)):
                    try:
                        response = getattr(commands, command)(nick, chan, arguments, sender, config, self)
                    except:
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout)
                        response = 'Coś poszło nie tak…'

                    if response is not None:
                        helpers.msg(self.client, chan, nick+": "+response)

cli = IRCClient(IRCHandler, host=config.get('irc', 'server'), port=config.getint('irc', 'port'), nick=config.get('irc', 'nick'))

app = IRCApp()
app.addClient( cli )

try:
    app.run()
except KeyboardInterrupt:
    quit()
{'fraction_non_alphanumeric': 0.12981351416807943, 'fraction_numerical': 0.006296924194720271, 'mean_word_length': 2.52991452991453, 'pattern_counts': {'":': 2, '<': 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': '297183', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1216, 'n_words': 293}