Exemplo n.º 1
0
    def __init__(self, config_path):
        builtins.yui = self

        # load config
        self.configPath = config_path
        self.config = None
        if not self.load_config():
            quit()

        self.db = sqlite3.connect(self.config_val('sqlitePath', default='yui.db'))

        self.loadingPlugin = None  # name of the currently loading plugin
        self.hooks = {}  # dict containing hook callable -> Hook object
        if not self.autoload_plugins():
            quit()

        self.server_ready = False

        self.ignored_users = {}

        self.authed_users = []

        # init SingleServerIRCBot
        IRCClient.__init__(self,
                           server=self.config_val('server', 'host', default='127.0.0.1'),
                           port=self.config_val('server', 'port', default=6667),
                           ssl=self.config_val('server', 'ssl', default=False),
                           encoding=self.config_val('server', 'encoding', default='utf-8'),
                           nick=self.config_val('server', 'nick', default='yuibot'),
                           user=self.config_val('server', 'user', default='yuibot'),
                           password=self.config_val('server', 'password', default=''),
                           realname=self.config_val('server', 'realname', default='yui'),
                           timeout=self.config_val('server', 'timeout', default=300))
Exemplo n.º 2
0
 def __init__(self, host, port=6667):
     """
     Makes a connection to an IRC server.
     
     host - the IRC server's host
     port - the IRC server's listening port
     """
     IRCClient.__init__(self, host, port)
     plugin_manager.get_plugins(self)
Exemplo n.º 3
0
 def recv_loop(self):
     """
     Runs the event system. This method is a blocking one.
     """
     plugin_manager.handle_plugins(self, "init")
     plugin_manager.handle_plugins(self, "connect")
     return IRCClient.recv_loop(self)
Exemplo n.º 4
0
    logger = logging.getLogger()
    logger.setLevel(level)
    
    # Console handler
    ch = logging.StreamHandler()
    ch.setLevel(level)
    
    # Log to file
    fh = logging.FileHandler('irc.log')
    fh.setLevel(level)
    
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', '%H:%M:%S')
    ch.setFormatter(formatter)
    fh.setFormatter(formatter)
    
    # Output log to console
    logger.addHandler(ch)
    logger.addHandler(fh)

if __name__ == '__main__':    
    start_logging()
    c = Config()
    c = Config()
    c.read_all()
                
    irch = IRCClient(c.nick, c.realname, c.channels, c.admins, c.trigger,
                     c.plugins, c.password, c.ssl, c.reconnect,
                     c.oper_user, c.oper_pass)
    irch.load_plugins()
    irch.connect(c.host, c.port)
    irch.run()
Exemplo n.º 5
0
 def event_generic(self, event_generic, args):
     IRCClient.event_generic(self, event_generic, args)
     plugin_manager.handle_plugins(self, event_generic, args)
Exemplo n.º 6
0
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', '%H:%M:%S')
    ch.setFormatter(formatter)
    fh.setFormatter(formatter)

    # Output log to console
    logger.addHandler(ch)
    logger.addHandler(fh)

    logger.info('Started logger with {} level.'.format(logging.getLevelName(level)))

    return logger

if __name__ == '__main__':
    c = Config()
    c.read_all()

    logger = start_logging(c.logging)
                
    irch = IRCClient(c.nick, c.realname, c.channels, c.admins, c.trigger,
                     c.plugins, c.password, c.ssl, c.reconnect,
                     c.oper_user, c.oper_pass)
    irch.load_plugins()
    irch.connect(c.host, c.port)

    try:
        irch.run()
    except Exception as e:
        logger.exception(e)
        logger.critical("Teslabot has encountered an error that it cannot "\
                        "recover from.")