Beispiel #1
0
def remotecb(bot, event):
    """ dispatch an event. """
    try:
        container = Container().load(event.txt)
    except TypeError:
        handle_exception()
        logging.warn("remotecallbacks - not a remote event - %s " %
                     event.userhost)
        return
    logging.debug('doing REMOTE callback')
    try:
        digest = hmac.new(str(container.hashkey),
                          XMLunescape(container.payload),
                          hashlib.sha512).hexdigest()
        logging.debug("remotecallbacks - digest is %s" % digest)
    except TypeError:
        handle_exception()
        logging.error("remotecallbacks - can't load payload - %s" %
                      container.payload)
        return
    if container.digest == digest:
        e = EventBase().load(XMLunescape(container.payload))
    else:
        raise NoProperDigest()
    e.txt = XMLunescape(e.txt)
    e.nodispatch = True
    e.forwarded = True
    bot.doevent(e)
    event.status = "done"
    return
Beispiel #2
0
 def __init__(self, input={}):
     if input == None: EventBase.__init__(self)
     else: EventBase.__init__(self, input)
     try:
         self['fromm'] = self['from']
     except (KeyError, TypeError):
         self['fromm'] = ''
Beispiel #3
0
def remotecb(bot, event):
    """ dispatch an event. """
    try:
        container = Container().load(event.txt)
    except TypeError:
        handle_exception()
        logging.warn("remotecallbacks - not a remote event - %s " % event.userhost)
        return
    logging.debug("doing REMOTE callback")
    try:
        digest = hmac.new(str(container.hashkey), xmlstream.XMLunescape(container.payload), hashlib.sha512).hexdigest()
        logging.debug("remotecallbacks - digest is %s" % digest)
    except TypeError:
        handle_exception()
        logging.error("remotecallbacks - can't load payload - %s" % container.payload)
        return
    if container.digest == digest:
        e = EventBase().load(xmlstream.XMLunescape(container.payload))
    else:
        raise NoProperDigest()
    e.txt = xmlstream.XMLunescape(e.txt)
    e.nodispatch = True
    e.forwarded = True
    e.dontbind = True
    bot.doevent(e)
    event.status = "done"
    return
Beispiel #4
0
 def __init__(self):
     EventBase.__init__(self)
     self.bottype = "wave"
     self.msg = False
     self.target = None
     self.roottarget = None
     self.rootreply = None
     self.gadget = None
     self.result = []
     self.cbtype = "BLIP_SUBMITTED"
Beispiel #5
0
 def __init__(self):
     EventBase.__init__(self)
     self.bottype = "wave"
     self.msg = False
     self.target = None
     self.roottarget = None
     self.rootreply = None
     self.gadget = None
     self.result = []
     self.cbtype = "BLIP_SUBMITTED"
     self.overload = True
Beispiel #6
0
 def handle(self):
     """ send TICK events to callback. """
     self.counter += 1
     event = EventBase()
     event.nolog = True
     event.nobind = True
     event.channel = "usedefault"
     event.stop = True
     if self.counter % 60 == 0:
         event.type = event.cbtype = 'TICK60'
         callbacks.check(self.bot, event)
     maincfg = getmainconfig()
     t = maincfg.ticksleep or 1
     if self.counter % t == 0:
         event.type = event.cbtype = 'TICK'
         callbacks.check(self.bot, event)
Beispiel #7
0
 def get(self, name):
     """ get a attribute by name. """
     if self.has_key('subelements'):
         for i in self['subelements']:
             if name in i: return i[name]
     if self.has_key(name): return self[name]
     return EventBase()
Beispiel #8
0
class TickLoop(TimedLoop):

    event = EventBase()
    event.type = event.cbtype = 'TICK'

    def start(self, bot=None):
        """ start the loop. """
        self.bot = bot
        TimedLoop.start(self)

    def handle(self):
        """ send TICK events to callback. """
        callbacks.check(self.bot, self.event)
Beispiel #9
0
def boteventcb(inputdict, request, response):
    #logging.warn(inputdict)
    #logging.warn(dir(request))
    #logging.warn(dir(response))
    body = request.body
    #logging.warn(body)
    payload = json.loads(body)
    try:
        botjson = payload['bot']
        logging.warn(botjson)
        cfg = LazyDict(json.loads(botjson))
        #logging.warn(str(cfg))
        bot = BotFactory().create(cfg.type, cfg)
        logging.warn("created bot: %s" % bot.tojson(full=True))
        eventjson = payload['event']
        #logging.warn(eventjson)
        event = EventBase()
        event.update(LazyDict(json.loads(eventjson)))
        logging.warn("created event: %s" % event.tojson(full=True))
        event.notask = True
        bot.doevent(event)
    except Exception, ex: handle_exception()
Beispiel #10
0
 def handle(self):
     """ send TICK events to callback. """
     self.counter += 1
     event = EventBase()
     event.nolog = True
     event.nobind = True
     event.channel = "usedefault"
     event.stop = True
     if self.counter % 60 == 0:
         event.type = event.cbtype = 'TICK60'
         callbacks.check(self.bot, event)
     maincfg = getmainconfig()
     t = maincfg.ticksleep or 1
     if self.counter % t == 0:
         event.type = event.cbtype = 'TICK'
         callbacks.check(self.bot, event)
Beispiel #11
0
def boteventcb(inputdict, request, response):
    logging.warn(inputdict)
    logging.warn(dir(request))
    logging.warn(dir(response))
    body = request.body
    logging.warn(body)
    payload = json.loads(body)
    try:
        botjson = payload['bot']
        logging.warn(botjson)
        cfg = LazyDict(json.loads(botjson))
        logging.warn(str(cfg))
        bot = BotFactory().create(cfg.type, cfg)
        logging.warn("botevent - created bot: %s" % bot.dump())
        eventjson = payload['event']
        logging.warn(eventjson)
        event = EventBase()
        event.update(LazyDict(json.loads(eventjson)))
        logging.warn("botevent - created event: %s" % event.dump())
        event.isremote = True
        event.notask = True
        bot.doevent(event)
    except Exception, ex:
        handle_exception()
Beispiel #12
0
 def __init__(self, bot=None): 
     EventBase.__init__(self, bot=bot)
     self.bottype = "tornado"
     self.cbtype = "TORNADO"
     self.bot = bot
     self.how = "overwrite"
Beispiel #13
0
 def reply(self, txt, result=[], event=None, origin="", dot=u", ", nr=600, extend=0, showall=True, *args, **kwargs):
     EventBase.reply(self, txt, result, event, origin, dot, nr, extend, showall=True, *args, **kwargs)
Beispiel #14
0
 def __getattr__(self, name):
     """ override getattribute so nodes in payload can be accessed. """
     if not self.has_key(name) and self.has_key('subelements'):
         for i in self['subelements']:
             if name in i: return i[name]
     return EventBase.__getattr__(self, name, default="")
Beispiel #15
0
 def __init__(self, bot=None):
     EventBase.__init__(self, bot=bot)
     self.bottype = "web"
     self.cbtype = "WEB"
     self.bot = bot
Beispiel #16
0
 def __init__(self, bot=None):
     EventBase.__init__(self, bot=bot)
     self.bottype = "web"
     self.cbtype = "WEB"
     self.bot = bot
Beispiel #17
0
 def __init__(self, bot=None): 
     EventBase.__init__(self)
     self.bottype = "xmpp"
     self.cbtype = 'MESSAGE'
     self.bot = bot
Beispiel #18
0
 def __init__(self, bot=None): 
     EventBase.__init__(self, bot=bot)
     self.bottype = "tornado"
     self.cbtype = "TORNADO"
     self.bot = bot
     self.how = "overwrite"
Beispiel #19
0
Datei: bot.py Projekt: code2u/jsb
 def outnocb(self, channel, txt, how=None, event=None, origin=None, response=None, dotime=False, *args, **kwargs):
     txt = self.normalize(txt)
     if event and event.how != "background":
         logging.info("%s - out - %s" % (self.cfg.name, txt))
     if "http://" in txt or "https://" in txt:
          for item in re_url_match.findall(txt):
              logging.debug("web - raw - found url - %s" % item)
              url = u'<a href="%s" onclick="window.open(\'%s\'); return false;">%s</a>' % (item, item, item)
              try: txt = txt.replace(item, url)
              except ValueError:  logging.error("web - invalid url - %s" % url)
     if response: self._raw(txt, event.target, event.how, event.handler)
     else:
         if event:
             e = cpy(event)
             e.txt = txt
             e.channel = channel
             e.how = event.how or how
         else:
             e = EventBase()
             e.nick = self.cfg.nick
             e.userhost = self.cfg.nick + "@" + "bot"
             e.channel = channel
             e.txt = txt
             e.div = "content_div"
             e.origin = origin
             e.how = how or "overwrite"
             e.headlines = True
         e.update(kwargs)
         update_web(self, e)
     self.benice(event)
Beispiel #20
0
 def __getattr__(self, name):
     """ override getattribute so nodes in payload can be accessed. """
     if not self.has_key(name) and self.has_key('subelements'):
         for i in self['subelements']:
             if name in i: return i[name]
     return EventBase.__getattr__(self, name, default="")
Beispiel #21
0
 def __init__(self, input={}):
     if input == None: EventBase.__init__(self)
     else: EventBase.__init__(self, input)
     try: self['fromm'] = self['from']
     except (KeyError, TypeError): self['fromm'] = ''
Beispiel #22
0
 def outnocb(self,
             channel,
             txt,
             how=None,
             event=None,
             origin=None,
             response=None,
             dotime=False,
             *args,
             **kwargs):
     txt = self.normalize(txt)
     if event and event.how != "background":
         logging.info("%s - out - %s" % (self.cfg.name, txt))
     if "http://" in txt or "https://" in txt:
         for item in re_url_match.findall(txt):
             logging.debug("web - raw - found url - %s" % item)
             url = u'<a href="%s" onclick="window.open(\'%s\'); return false;">%s</a>' % (
                 item, item, item)
             try:
                 txt = txt.replace(item, url)
             except ValueError:
                 logging.error("web - invalid url - %s" % url)
     if response or (event and event.doweb):
         self._raw(txt, event.target, event.how, event.handler)
     else:
         if event:
             e = cpy(event)
             e.txt = txt
             e.channel = channel
             e.how = event.how or how
         else:
             e = EventBase()
             e.nick = self.cfg.nick
             e.userhost = self.cfg.nick + "@" + "bot"
             e.channel = channel
             e.txt = txt
             e.div = "content_div"
             e.origin = origin
             e.how = how or "overwrite"
             e.headlines = True
         e.update(kwargs)
         update_web(self, e)
     self.benice(event)
Beispiel #23
0
 def __init__(self, bot=None):
     EventBase.__init__(self)
     self.bottype = "xmpp"
     self.cbtype = 'MESSAGE'
     self.bot = bot