def create(self, type=None, cfg={}): try: type = cfg['type'] or type or None except KeyError: pass try: if 'xmpp' in type: from jsb.drivers.xmpp.bot import SXMPPBot bot = SXMPPBot(cfg) elif type == 'irc': from jsb.drivers.irc.bot import IRCBot bot = IRCBot(cfg) elif type == 'console': from jsb.drivers.console.bot import ConsoleBot bot = ConsoleBot(cfg) elif type == 'base': from jsb.lib.botbase import BotBase bot = BotBase(cfg) elif type == 'tornado' or type == "web": from jsb.drivers.tornado.bot import TornadoBot bot = TornadoBot(cfg) elif type == 'sleek': from jsb.drivers.sleek.bot import SleekBot bot = SleekBot(cfg) else: raise NoSuchBotType('%s bot .. unproper type %s' % (type, cfg.dump())) return bot except NoUserProvided, ex: logging.info("%s - %s" % (cfg.name, str(ex))) except AssertionError, ex: logging.warn("%s - assertion error: %s" % (cfg.name, str(ex))) except Exception, ex: handle_exception()
def create(self, type, cfg): if type == 'xmpp' or type == 'jabber': try: from jsb.lib.gae.xmpp.bot import XMPPBot bot = XMPPBot(cfg) except ImportError: from jsb.lib.socklib.xmpp.bot import SXMPPBot bot = SXMPPBot(cfg) elif type == 'sxmpp': from jsb.lib.socklib.xmpp.bot import SXMPPBot bot = SXMPPBot(cfg) elif type == 'web': from jsb.lib.gae.web.bot import WebBot bot = WebBot(cfg) elif type == 'wave': from jsb.lib.gae.wave.bot import WaveBot bot = WaveBot(cfg, domain=cfg.domain) elif type == 'irc': from jsb.lib.socklib.irc.bot import IRCBot bot = IRCBot(cfg) elif type == 'console': from jsb.lib.console.bot import ConsoleBot bot = ConsoleBot(cfg) elif type == 'base': from jsb.lib.botbase import BotBase bot = BotBase(cfg) else: raise NoSuchBotType('%s bot .. unproper type %s' % (type, cfg.dump())) return bot
def makebot(self, type, name, domain="", cfg={}, showerror=False): """ create a bot .. use configuration if provided. """ if not name: logging.warn("fleet - name is not correct: %s" % name) ; return if cfg: logging.warn('fleet - making %s (%s) bot - %s' % (type, name, cfg.dump())) bot = None if not cfg: cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config') if not cfg.name: cfg['name'] = cfg['botname'] = name if cfg.disable: logging.warn("fleet - %s bot is disabled. see %s" % (name, cfg.cfile)) if showerror: raise BotNotEnabled(name) return if not cfg.type and type: logging.debug("fleet - %s - setting type to %s" % (cfg.cfile, type)) cfg.type = type if not cfg['type']: try: self.data['names'].remove(name) self.save() except ValueError: pass raise Exception("no bot type specified") if not cfg.owner: cfg.owner = Config().owner if not cfg.domain and domain: cfg.domain = domain if not cfg: raise Exception("can't make config for %s" % name) cfg.save() if type == 'xmpp' or type == 'jabber': try: from jsb.lib.gae.xmpp.bot import XMPPBot bot = XMPPBot(cfg) except ImportError: from jsb.lib.socklib.xmpp.bot import SXMPPBot bot = SXMPPBot(cfg) elif type == 'sxmpp': from jsb.lib.socklib.xmpp.bot import SXMPPBot bot = SXMPPBot(cfg) elif type == 'web': from jsb.lib.gae.web.bot import WebBot bot = WebBot(cfg) elif type == 'wave': from jsb.lib.gae.wave.bot import WaveBot dom = cfg.domain or domain bot = WaveBot(cfg, domain=dom) elif type == 'irc': from jsb.lib.socklib.irc.bot import IRCBot bot = IRCBot(cfg) elif type == 'console': from jsb.lib.console.bot import ConsoleBot bot = ConsoleBot(cfg) elif type == 'base': from jsb.lib.botbase import BotBase bot = BotBase(cfg) else: raise NoSuchBotType('%s bot .. unproper type %s' % (name, type)) if bot: self.addbot(bot) return bot raise Exception("can't make %s bot" % name)
def handle_adminmakebot(bot, ievent): """ create a bot of given type. """ try: botname, bottype = ievent.args except ValueError: ievent.missing("<name> <type>") return newbot = BotBase() newbot.botname = botname newbot.type = bottype newbot.owner = bot.owner newbot.save() ievent.done()