def __init__(self, cfg=None, users=None, plugs=None, *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, *args, **kwargs) BotBase.setstate(self) self.type = 'irc' self.wait = Wait() self.fsock = None self.oldsock = None self.sock = None if self.cfg: if not self.cfg.nolimiter: self.nolimiter = False else: self.nolimiter = self.cfg.nolimiter self.reconnectcount = 0 self.pongcheck = False self.nickchanged = False self.noauto433 = False if self.state: if not self.state.has_key('alternick'): self.state['alternick'] = self.cfg['alternick'] if not self.state.has_key('no-op'): self.state['no-op'] = [] self.nicks401 = [] if self.port == 0: self.port = 6667 self.connecttime = 0 self.encoding = 'utf-8' self.blocking = 1 self.lastoutput = 0 if self.cfg and self.cfg.ipv6: self.ipv6 = True else: self.ipv6 = False self.splitted = []
def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) self.port = 5222 if not self.host: self.host = self.cfg.host if not self.host: raise Exception("%s - host not set - %s" % (self.name, str(self.cfg))) self.username = self.user.split('@')[0] XMLStream.__init__(self, self.host, self.port, self.name) self.type = 'sxmpp' self.sock = None self.me = self.cfg.user self.jid = self.me self.lastin = None self.test = 0 self.password = "" self.connecttime = 0 self.connection = None self.privwait = XMPPWait() self.errorwait = XMPPErrorWait() self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.05 if self.port == 0: self.port = 5222
def __init__(self, cfg=None, users=None, plugs=None, *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, *args, **kwargs) #BotBase.setstate(self) self.type = 'irc' self.fsock = None self.oldsock = None self.sock = None self.reconnectcount = 0 self.pongcheck = 0 self.nickchanged = False self.noauto433 = False if self.state: if not self.state.has_key('alternick'): self.state['alternick'] = self.cfg['alternick'] if not self.state.has_key('no-op'): self.state['no-op'] = [] self.nicks401 = [] self.cfg.port = self.cfg.port or 6667 self.connecttime = 0 self.encoding = 'utf-8' self.blocking = 1 self.lastoutput = 0 self.splitted = [] if not self.cfg.server: self.cfg.server = self.cfg.host or "localhost" assert self.cfg.port assert self.cfg.server
def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, botname, nick, *args, **kwargs) self.type = "convore" self.cursor = None if not self.state.has_key("namecache"): self.state["namecache"] = {} if not self.state.has_key("idcache"): self.state["idcache"] = {} self.cfg.nick = cfg.username or "jsonbot"
def __init__(self, cfg=None, users=None, plugs=None, botname=None, *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, *args, **kwargs) self.type = "console"
def __init__(self, cfg=None, users=None, plugs=None, botname="gae-web", *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, *args, **kwargs) if self.cfg: self.cfg['type'] = u'web' self.isgae = True self.type = u"web"
def __init__(self, cfg=None, users=None, plugs=None, botname="gae-xmpp", *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, *args, **kwargs) self.jid = "*****@*****.**" if self.cfg: self.cfg['type'] = 'xmpp' self.isgae = True self.type = "xmpp"
def start(self, connect=True, *args, **kwargs): BotBase.start(self, False) try: if connect: target = self.cfg.server or self.cfg.host port = self.cfg.port or 5222 logging.warn("connecting to %s:%s" % (target, port)) if port == 5223: use_tls = True else: use_tls = True self.xmpp.connect(address=(target, port), use_tls=use_tls) print 1 self.xmpp.process(block=True) print 2 except Exception, ex: logging.error(str(ex))
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 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 __init__(self, cfg=None, users=None, plugs=None, botname="tornado-bot", *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, bottype="tornado", *args, **kwargs) assert self.cfg self.cfg.type = "tornado" self.websockets = {}
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 __init__(self, cfg=None, users=None, plugs=None, name=None, domain=None, image_url='http://jsonbot.appspot.com/assets/favicon.png', profile_url='http://jsonbot.appspot.com/', *args, **kwargs): sname = 'jsb' BotBase.__init__(self, cfg, users, plugs, name, *args, **kwargs) assert self.cfg self.type = 'wave' if domain: self.cfg.domain = domain else: self.cfg.domain = getmainconfig().domain or "wave,google.com" self.cfg.nick = self.cfg.nick or name or "gae-wave" self.overload = True robot.Robot.__init__(self, name=getmainconfig().app_id or self.cfg.nick, image_url=image_url, profile_url=profile_url) credentials = _import_byfile("credentials", getdatadir() + os.sep + "config" + os.sep + "credentials.py") self.set_verification_token_info(credentials.verification_token[self.cfg.domain], credentials.verification_secret[self.cfg.domain]) self.setup_oauth(credentials.Consumer_Key[self.cfg.domain], credentials.Consumer_Secret[self.cfg.domain], server_rpc_base=credentials.RPC_BASE[self.cfg.domain]) self.register_handler(events.BlipSubmitted, self.OnBlipSubmitted) self.register_handler(events.WaveletSelfAdded, self.OnSelfAdded) self.register_handler(events.WaveletParticipantsChanged, self.OnParticipantsChanged) self.iswave = True self.isgae = True
def __init__(self, cfg=None, users=None, plugs=None, name="gae-wave", domain=None, image_url='http://jsonbot.appspot.com/assets/favicon.png', profile_url='http://jsonbot.appspot.com/', *args, **kwargs): sname = 'jsb' BotBase.__init__(self, cfg, users, plugs, name, *args, **kwargs) if cfg: self.domain = cfg['domain'] or 'googlewave.com' else: self.domain = domain or 'googlewave.com' if self.cfg and self.cfg['domain'] != self.domain: self.cfg['domain'] = self.domain self.cfg.save() self.type = 'wave' self.nick = name or sname robot.Robot.__init__(self, name=sname, image_url=image_url, profile_url=profile_url) credentials = _import_byfile("credentials", getdatadir() + os.sep + "config" + os.sep + "credentials.py") self.set_verification_token_info(credentials.verification_token[self.domain], credentials.verification_secret[self.domain]) self.setup_oauth(credentials.Consumer_Key[self.domain], credentials.Consumer_Secret[self.domain], server_rpc_base=credentials.RPC_BASE[self.domain]) self.register_handler(events.BlipSubmitted, self.OnBlipSubmitted) self.register_handler(events.WaveletSelfAdded, self.OnSelfAdded) self.register_handler(events.WaveletParticipantsChanged, self.OnParticipantsChanged) self.iswave = True self.isgae = True
def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) if not self.cfg: raise Exception("sxmpp - config is not set.") if not self.cfg.user: raise NoUserProvided("please make sure the user config variable is set in %s (or use -u)" % cfg.cfile) try: self.cfg.username, self.cfg.host = self.cfg.user.split('@') except (ValueError, TypeError): raise Exception("%s - user not set - %s" % (self.cfg.name, str(self.cfg))) XMLStream.__init__(self, self.cfg.name) self.type = 'sxmpp' self.sock = None self.lastin = None self.test = 0 self.connecttime = 0 self.connection = None self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.02 try: self.cfg.port = int(self.cfg.port) except (ValueError, TypeError): self.cfg.port = 5222 logging.debug("%s - user is %s" % (self.cfg.name, self.cfg.user))
def __init__(self, cfg=None, users=None, plugs=None, name="gae-wave", domain=None, image_url='http://jsonbot.appspot.com/assets/favicon.png', profile_url='http://jsonbot.appspot.com/', *args, **kwargs): sname = 'jsb' BotBase.__init__(self, cfg, users, plugs, name, *args, **kwargs) if cfg: self.domain = cfg['domain'] or 'googlewave.com' else: self.domain = domain or 'googlewave.com' if self.cfg and self.cfg['domain'] != self.domain: self.cfg['domain'] = self.domain self.cfg.save() self.type = 'wave' self.nick = name or sname robot.Robot.__init__(self, name=sname, image_url=image_url, profile_url=profile_url) credentials = _import_byfile( "credentials", getdatadir() + os.sep + "config" + os.sep + "credentials.py") self.set_verification_token_info( credentials.verification_token[self.domain], credentials.verification_secret[self.domain]) self.setup_oauth(credentials.Consumer_Key[self.domain], credentials.Consumer_Secret[self.domain], server_rpc_base=credentials.RPC_BASE[self.domain]) self.register_handler(events.BlipSubmitted, self.OnBlipSubmitted) self.register_handler(events.WaveletSelfAdded, self.OnSelfAdded) self.register_handler(events.WaveletParticipantsChanged, self.OnParticipantsChanged) self.iswave = True self.isgae = True
def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) if not self.cfg: raise Exception("sxmpp - config is not set.") if not self.cfg.user: raise NoUserProvided( "please make sure the user config variable is set in %s (or use -u)" % cfg.cfile) try: self.cfg.username, self.cfg.host = self.cfg.user.split('@') except (ValueError, TypeError): raise Exception("%s - user not set - %s" % (self.cfg.name, str(self.cfg))) XMLStream.__init__(self, self.cfg.name) self.type = 'sxmpp' self.sock = None self.lastin = None self.test = 0 self.connecttime = 0 self.connection = None self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.02 try: self.cfg.port = int(self.cfg.port) except (ValueError, TypeError): self.cfg.port = 5222 logging.debug("%s - user is %s" % (self.cfg.name, self.cfg.user))
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()
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()
def start(self, connect=True, *args, **kwargs): BotBase.start(self, False) try: if connect: self.xmpp.connect() self.xmpp.process(block=True) except Exception, ex: logging.error(str(ex))
def __init__(self, cfg=None, users=None, plugs=None, botname="tornado-bot", *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, *args, **kwargs) assert self.cfg self.type = u"tornado" self.isgae = False self.websockets = {}
def __init__(self, cfg=None, users=None, plugs=None, botname="gae-web", *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, botname, *args, **kwargs) assert self.cfg self.isgae = True self.type = u"web"