def main(): config = bConfig("babble") config.parseCommandLine() config.loadConfigFile() bLogs(config) log = logging.getLogger(config.ourname) atexit.register(shutdown) if config.daemon: daemonize(config) if hasattr(config, "irc"): ircBot = irc.rbot(config.irc, cb=processMessage) ircBot.start() log.info("starting IRC") p = Process(target=loadPlugins, args=(config.plugins, qEvents, qIrc)) p.start() lastPoll = time.time() while ircBot.active: ircBot.process() try: event = qIrc.get(False) if event is not None: print "irc send event", event except Empty: time.sleep(1) # loop thru the modules that have registered # a poll handler every 60 seconds if time.time() - lastPoll > 60: qEvents.put(("babble", "ping")) lastPoll = time.time() p.join()
def main(): config = bConfig('babble') config.parseCommandLine() config.loadConfigFile() bLogs(config) log = logging.getLogger(config.ourname) atexit.register(shutdown) if config.daemon: daemonize(config) if hasattr(config, 'irc'): ircBot = irc.rbot(config.irc, cb=processMessage) ircBot.start() log.info('starting IRC') p = Process(target=loadPlugins, args=(config.plugins, qEvents, qIrc)) p.start() lastPoll = time.time() while ircBot.active: ircBot.process() try: event = qIrc.get(False) if event is not None: print 'irc send event', event except Empty: time.sleep(1) # loop thru the modules that have registered # a poll handler every 60 seconds if time.time() - lastPoll > 60: qEvents.put(('babble', 'ping')) lastPoll = time.time() p.join()
def main(config=None): if config is None: config = tools.Config(_defaults) config.appPath = os.getcwd() config.ourName = os.path.splitext(os.path.basename(sys.argv[0]))[0] if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]): configFile = sys.argv[1] else: configFile = os.path.join(config.appPath, '%s.cfg' % config.ourName) if os.path.isfile(configFile): config.load(configFile) tools.initLogs(config) log.info('Starting') loadModules(config) ircBot = irc.rbot(config, cb=processMessage) ircBot.start() log.info('starting IRC') lastPoll = time.time() while ircBot.active: ircBot.process() # loop thru the modules that have registered # a poll handler every 60 seconds if time.time() - lastPoll > 60: pollModules(ircBot) lastPoll = time.time()
_defaultOptions = { 'config': ('-c', '--config', './rbot.cfg', 'Configuration file'), 'debug': ('-d', '--debug', True, 'Enable Debug', 'b'), 'background': ('-b', '--background', False, 'daemonize ourselves', 'b'), 'logpath': ('-l', '--logpath', None, 'Path where log file is to be written'), 'modules': ('-m', '--modules', './modules', 'Path where bot modules are found'), } if __name__ == "__main__": options = initOptions(_defaultOptions) initLogs(options) log.info('Starting') loadModules(options) ircBot = rbot(options, cb=processMessage) ircBot.start() while ircBot.active: ircBot.process() try: msg = ircQueue.get(False) except Empty: msg = None if msg is not None: if msg[0] == 'irc': ircBot.tell(msg[1], msg[2]) elif msg[0] == 'command': log.info('registering %s %s' % (msg[0], msg[2]))