Пример #1
0
 def _read_with_module(self, a_group_name, a_format, a_path, a_origin):
     """ read external include file that is defined in another format """
     
      # check if file exits
     if not os.path.exists(a_path):
         raise IncludeError("the config %s file to include %s does not exits" % (a_format, a_path), a_origin)
     
     mod_prefix = "org.ctbto.conf.module."
     
     # get the module dir from the current module path
     # then split the path from org to get only the dir where the src are defined
     current_mod_path = os.path.dirname(__file__)
     src_dir    = current_mod_path.split('org')[0]
     
     # need to get the module dir from the conf
     
     the_module = module_loader.load("%s%s_loader" %(mod_prefix,a_format), src_dir)
     
     cursect    = the_module.read(a_path)
     
     self._sections[a_group_name] = cursect
Пример #2
0
    def __init__(self):
        logger.print_info("Welcome to TextSiri NEO.")
        logger.print_info("Starting engine, version {}".format(
            botstrings.VERSION))
        self.check_for_updates()
        logger.print_info("Starting config parser")
        logger.print_info("Config file is {}".format(botstrings.CONFIG_FILE))
        self.config = json_parser.JSONParser(botstrings.CONFIG_FILE)
        if self.config.is_empty:
            logger.print_warn("Config file is empty. Generating new config.")
            self.config["general"] = {  # General bot settings.
                "nickname": "TextSiri",
                "realname": "Your digital assistant on IRC.",
                "authmethod": "nickserv",  # TODO add sasl method
                "password": "",
                "triggertype":
                "1",  # Modes are: 1- Regexp, 2-Single char, 3-Text at the beginning of message. Any other will give a FATAL error.
                "showmotd": True,
                "trigger":
                "^{botnick}[^a-zA-Z0-9]\s(.+)"  # Available replacements: {botnick} = Bot's nick.
            }
            self.config["server"] = {  # Server settings.
                "address": "irc.freenode.net",
                "port": "6697",
                "ssl": True
            }
            self.config["channels"] = [{
                "name": "#botters",
                "key": "",  # Leave empty for no key.
                "joincommands": []  # MUST BE RFC2812 COMPLIANT!
            }]
            self.config["modules"] = {
                # Space for module settings. Each module that needs a config should have its own dictionary with its own name here.
            }

            self.config.write()
            logger.print_warn("Config file is written.")
            logger.print_info(
                "It looks like this is your first time running TextSiri NEO. Please edit {} in the current directory."
                .format(botstrings.CONFIG_FILE))
            sys.exit(1)
        else:
            logger.print_info("Config file successfully read.")
            server_info = self.config["server"]
            general_info = self.config["general"]
            logger.print_info(
                "Attempting to connect to {} at port {} (SSL: {})".format(
                    server_info["address"], server_info["port"],
                    "YES" if server_info["ssl"] else "NO"))
            if server_info["ssl"]:
                irc.bot.SingleServerIRCBot.__init__(
                    self, [(server_info["address"], int(server_info["port"]))],
                    general_info["nickname"],
                    general_info["realname"],
                    connect_factory=irc.connection.Factory(
                        wrapper=ssl.wrap_socket))
            else:
                irc.bot.SingleServerIRCBot.__init__(
                    self, [(server_info["address"], int(server_info["port"]))],
                    general_info["nickname"], general_info["realname"])
            self.connection.buffer_class = irc.buffer.LenientDecodingLineBuffer
            logger.print_info("Attempting to load modules.")
            self.modules = module_loader.load(self, logger,
                                              botstrings.MODULES_DIR)
            logger.print_info("Finished loading modules.")
            self.message_buffer = []
            self.message_counter = 0
            self.message_slowmode_lock = 0
            logger.print_info("Starting message sender.")
            self.msgThread = threading.Thread(target=self.message_loop,
                                              args=(self.connection, ))
            self.msgThread.setDaemon(True)
            self.msgThread.start()
            logger.print_info("Started message sender.")
            logger.print_info("Reached Target Initialization.")
Пример #3
0
    def __init__(self):
        logger.print_info("Welcome to TextSiri NEO.")
        logger.print_info("Starting engine, version {}".format(botstrings.VERSION))
        self.check_for_updates()
        logger.print_info("Starting config parser")
        logger.print_info("Config file is {}".format(botstrings.CONFIG_FILE))
        self.config = json_parser.JSONParser(botstrings.CONFIG_FILE)
        if self.config.is_empty:
            logger.print_warn("Config file is empty. Generating new config.")
            self.config["general"] = { # General bot settings.
                    "nickname": "TextSiri",
                    "realname": "Your digital assistant on IRC.",
                    "authmethod": "nickserv", # TODO add sasl method
                    "password": "",
                    "triggertype": "1", # Modes are: 1- Regexp, 2-Single char, 3-Text at the beginning of message. Any other will give a FATAL error.
                    "showmotd": True,
                    "trigger": "^{botnick}[^a-zA-Z0-9]\s(.+)" # Available replacements: {botnick} = Bot's nick.
            }
            self.config["server"] = { # Server settings.
                    "address": "irc.freenode.net",
                    "port": "6697",
                    "ssl": True
            }
            self.config["channels"] = [
                    {
                        "name": "#botters",
                        "key": "", # Leave empty for no key.
                        "joincommands": [] # MUST BE RFC2812 COMPLIANT!
                    }
            ]
            self.config["modules"] = {
                    # Space for module settings. Each module that needs a config should have its own dictionary with its own name here.
            }

            self.config.write()
            logger.print_warn("Config file is written.")
            logger.print_info("It looks like this is your first time running TextSiri NEO. Please edit {} in the current directory.".format(botstrings.CONFIG_FILE))
            sys.exit(1)
        else:
            logger.print_info("Config file successfully read.")
            server_info = self.config["server"]
            general_info = self.config["general"]
            logger.print_info("Attempting to connect to {} at port {} (SSL: {})".format(
                              server_info["address"], server_info["port"], "YES" if server_info["ssl"] else "NO"))
            if server_info["ssl"]:
                irc.bot.SingleServerIRCBot.__init__(self, [(server_info["address"], int(server_info["port"]))],
                                                    general_info["nickname"], general_info["realname"],
                                                    connect_factory=irc.connection.Factory(wrapper=ssl.wrap_socket))
            else:
                irc.bot.SingleServerIRCBot.__init__(self, [(server_info["address"], int(server_info["port"]))],
                                                    general_info["nickname"], general_info["realname"])
            self.connection.buffer_class = irc.buffer.LenientDecodingLineBuffer
            logger.print_info("Attempting to load modules.")
            self.modules = module_loader.load(self, logger, botstrings.MODULES_DIR)
            logger.print_info("Finished loading modules.")
            self.message_buffer = []
            self.message_counter = 0
            self.message_slowmode_lock = 0
            logger.print_info("Starting message sender.")
            self.msgThread = threading.Thread(target=self.message_loop, args=(self.connection,))
            self.msgThread.setDaemon(True)
            self.msgThread.start()
            logger.print_info("Started message sender.")
            logger.print_info("Reached Target Initialization.")