def initbot(self, bot): """ initialise a bot. """ if bot not in self.bots: if not os.path.exists(self.datadir + os.sep + bot.name): os.mkdir(self.datadir + os.sep + bot.name) if type(bot.cfg['owner']) == types.StringType or type(bot.cfg['owner']) == types.UnicodeType: bot.cfg['owner'] = [bot.cfg['owner'], ] bot.cfg.save() users.make_owner(config['owner'] + bot.cfg['owner']) rlog(10, 'fleet', 'added bot: ' + bot.name)
def initbot(self, bot): """ initialise a bot. """ if bot not in self.bots: if not os.path.exists(self.datadir + os.sep + bot.name): os.mkdir(self.datadir + os.sep + bot.name) if type(bot.cfg['owner']) == types.StringType or type( bot.cfg['owner']) == types.UnicodeType: bot.cfg['owner'] = [ bot.cfg['owner'], ] bot.cfg.save() users.make_owner(config['owner'] + bot.cfg['owner']) rlog(10, 'fleet', 'added bot: ' + bot.name)
def start(self, botlist=[], enable=False): """ startup the bots. """ # scan the fleet datadir for bots dirs = [] got = [] for bot in botlist: dirs.append(self.datadir + os.sep + bot) if not dirs: dirs = glob.glob(self.datadir + os.sep + "*") for fleetdir in dirs: if fleetdir.endswith('fleet'): continue rlog(10, 'fleet', 'found bot: ' + fleetdir) cfg = Config(fleetdir, 'config') if not cfg: rlog(10, 'fleet', "can't read %s config file" % fleetdir) continue name = fleetdir.split(os.sep)[-1] if not name: rlog(10, 'fleet', "can't read botname from %s config file" % \ fleetdir) continue if not enable and not cfg['enable']: rlog(10, 'fleet', '%s bot is disabled' % name) continue else: rlog(10, 'fleet', '%s bot is enabled' % name) if not name in fleetdir: rlog(10, 'fleet', 'bot name in config file doesnt match dir name') continue bot = self.makebot(name, cfg) if bot: start_new_thread(bot.connectwithjoin, ()) self.addbot(bot) got.append(bot) return got # set startok event self.startok.set()