<commit_before>#!/usr/bin/env python
#Let's keep this file in particular as clean and neatly organized as possible.
#If this is nice and organized, then writing new modules will be a snap and this
#file should rarely have to be edited.

import ConfigParser
DEFAULT_CONFIG = "default.conf"
CONFIG_NAME = ".scrappyrc"

import logging
import os, os.path
import ssl
import sys
import traceback
import thread, threading

#import irclib_scrappy
#import irclib
from irclib import client as ircclient


# Logging guidelines and levels
# DEBUG - Python debugging (e.g., printing list of connected servers on startup)
# INFO - Anything we would want to see during normal operation (e.g., startup/reboot messages)
# WARNING - Things we would rather not happen (e.g., using a non-SSL connection)
# ERROR - Deviations from normal operation (e.g., failed to connect to a server)
# CRITICAL - Scrappy gonna die! But not before spitting out a final goodbye! (e.g., SIGINT)
logging.basicConfig(level=logging.DEBUG)


irc_logger = logging.getLogger("irclib.client")
# Change me if you want to see IRC DEBUG lines
irc_logger.setLevel(logging.INFO)

#this is our main bot class.  Once scrappy.py is called, an instance of this
#class (our bot) gets created and some initialization is done.  The real work is
#done via modules that get loaded here.
class scrappy:
        def __init__(self):

            self.logger = logging.getLogger("scrappy")

            # TODO: Use logging module
            self.logger.info("Scrappy bot started.")

            if not os.path.exists(CONFIG_NAME):
                self.logger.critical("Error: Configuration file '%s' not found." % CONFIG_NAME)
                self.logger.critical("Copy %s to %s and modify as necessary." % (DEFAULT_CONFIG, CONFIG_NAME))
                sys.exit(1)
            self.config = ConfigParser.SafeConfigParser()
            self.config.read(CONFIG_NAME)

            self.servers = {}
            required_items = ["cmdchar","nickname","username","realname",
                                "server","port","channels", "ssl"]
            for server in self.config.sections():
                self.servers[server] = {}
                for (k,v) in self.config.items(server):
                    self.servers[server][k] = v

                # Ok ok, so ssl is already a key, but I want to coerce it to bool
                self.servers[server]["ssl"] = self.config.getboolean(server, "ssl")

                # Sanity check
                errors = False
                for item in required_items:
                    if item not in self.servers[server]:
                        errors = True
                        self.logger.critical("Error: %s not found in configuration." % item)
                    if errors:
                        sys.exit(1)

                self.servers[server]["channels"] = self.servers[server]["channels"].split()
                self.servers[server]["port"] = int(self.servers[server]["port"])

            self.ircsock = '' #this will be the socket
            self.lock = threading.Lock()

            #our event lists.
            #each module adds functions to be called to these events.
            #each event handler calls all of the functions within its list.
            self.events = {"connect": {},
                            "disconnect": {},
                            "error": {},
                            "invite": {},
                            "join": {},
                            "kick": {},
                            "load": {},
                            "mode": {},
                            "msg": {},
                            "part": {},<commit_msg>Server name is now stored in the server object so modules can get at it<commit_after>#!/usr/bin/env python
#Let's keep this file in particular as clean and neatly organized as possible.
#If this is nice and organized, then writing new modules will be a snap and this
#file should rarely have to be edited.

import ConfigParser
DEFAULT_CONFIG = "default.conf"
CONFIG_NAME = ".scrappyrc"

import logging
import os, os.path
import ssl
import sys
import traceback
import thread, threading

#import irclib_scrappy
#import irclib
from irclib import client as ircclient


# Logging guidelines and levels
# DEBUG - Python debugging (e.g., printing list of connected servers on startup)
# INFO - Anything we would want to see during normal operation (e.g., startup/reboot messages)
# WARNING - Things we would rather not happen (e.g., using a non-SSL connection)
# ERROR - Deviations from normal operation (e.g., failed to connect to a server)
# CRITICAL - Scrappy gonna die! But not before spitting out a final goodbye! (e.g., SIGINT)
logging.basicConfig(level=logging.DEBUG)


irc_logger = logging.getLogger("irclib.client")
# Change me if you want to see IRC DEBUG lines
irc_logger.setLevel(logging.INFO)

#this is our main bot class.  Once scrappy.py is called, an instance of this
#class (our bot) gets created and some initialization is done.  The real work is
#done via modules that get loaded here.
class scrappy:
        def __init__(self):

            self.logger = logging.getLogger("scrappy")

            # TODO: Use logging module
            self.logger.info("Scrappy bot started.")

            if not os.path.exists(CONFIG_NAME):
                self.logger.critical("Error: Configuration file '%s' not found." % CONFIG_NAME)
                self.logger.critical("Copy %s to %s and modify as necessary." % (DEFAULT_CONFIG, CONFIG_NAME))
                sys.exit(1)
            self.config = ConfigParser.SafeConfigParser()
            self.config.read(CONFIG_NAME)

            self.servers = {}
            required_items = ["cmdchar","nickname","username","realname",
                                "server","port","channels", "ssl"]
            for server in self.config.sections():
                self.servers[server] = {}
                for (k,v) in self.config.items(server):
                    self.servers[server][k] = v

                # Ok ok, so ssl is already a key, but I want to coerce it to bool
                self.servers[server]["ssl"] = self.config.getboolean(server, "ssl")

                # Sanity check
                errors = False
                for item in required_items:
                    if item not in self.servers[server]:
                        errors = True
                        self.logger.critical("Error: %s not found in configuration." % item)
                    if errors:
                        sys.exit(1)

                self.servers[server]["channels"] = self.servers[server]["channels"].split()
                self.servers[server]["port"] = int(self.servers[server]["port"])
                self.servers[server]["servername"] = server

            self.ircsock = '' #this will be the socket
            self.lock = threading.Lock()

            #our event lists.
            #each module adds functions to be called to these events.
            #each event handler calls all of the functions within its list.
            self.events = {"connect": {},
                            "disconnect": {},
                            "error": {},
                            "invite": {},
                            "join": {},
                            "kick": {},
                            "load": {},
                            "mode": {},
                            "msg": {},
                            "part": {},
{'fraction_non_alphanumeric': 0.09922231161169215, 'fraction_numerical': 0.0005363368195226602, 'mean_word_length': 1.8989506412747765, 'pattern_counts': {'":': 20, '<': 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': '7673835', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1869, 'n_words': 672}