예제 #1
0
파일: irc.py 프로젝트: melmothx/jsonbot
 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 = []
예제 #2
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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
예제 #3
0
파일: irc.py 프로젝트: Petraea/jsonbot
 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
예제 #4
0
파일: bot.py 프로젝트: Lujeni/old-projects
 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"
예제 #5
0
 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"
예제 #6
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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"
예제 #7
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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"
예제 #8
0
파일: bot.py 프로젝트: NURDspace/jsonbot
 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))
예제 #9
0
파일: bot.py 프로젝트: Petraea/jsonbot
 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))
예제 #10
0
 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
예제 #11
0
 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()
예제 #12
0
파일: bot.py 프로젝트: Petraea/jsonbot
 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 = {}
예제 #13
0
 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)
예제 #14
0
파일: bot.py 프로젝트: code2u/jsb
 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
예제 #15
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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
예제 #16
0
파일: bot.py 프로젝트: Lujeni/old-projects
 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))
예제 #17
0
 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
예제 #18
0
파일: bot.py 프로젝트: Petraea/jsonbot
 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))
예제 #19
0
파일: admin.py 프로젝트: melmothx/jsonbot
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()
예제 #20
0
파일: irc.py 프로젝트: NURDspace/jsonbot
 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
예제 #21
0
파일: admin.py 프로젝트: melmothx/jsonbot
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()
예제 #22
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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"
예제 #23
0
파일: bot.py 프로젝트: melmothx/jsonbot
 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"
예제 #24
0
파일: bot.py 프로젝트: Lujeni/old-projects
 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))
예제 #25
0
파일: bot.py 프로젝트: buzzworkers/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"
예제 #26
0
파일: bot.py 프로젝트: code2u/jsb
 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 = {}
예제 #27
0
파일: bot.py 프로젝트: code2u/jsb
 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"