Пример #1
0
 def __init__(self, nodedict={}):
     EventBase.__init__(self, nodedict)
     self.element = "presence"
     self.jabber = True
     self.cmnd = "PRESENCE"
     self.cbtype = "PRESENCE"
     self.bottype = "xmpp"
Пример #2
0
 def __init__(self, nodedict={}):
     self.element = "message"
     self.jabber = True
     self.cmnd = "MESSAGE"
     self.cbtype = "MESSAGE"
     self.bottype = "xmpp"
     self.type = "normal"
     self.speed = 8
     EventBase.__init__(self, nodedict)
Пример #3
0
 def __init__(self, origin=None, payload=None, type="event", key=None, how="direct"):
     EventBase.__init__(self)
     self.createtime = time.time()
     self.origin = origin
     self.type = type
     self.hashkey = key
     if payload:
         self.payload = payload
         self.makeid()
         if key: self.makehmac(key)
         else:
             self.hashkey = self.id
             self.makehmac(self.id)
Пример #4
0
 def handle(self):
     """ send TICK events to callback. """
     self.counter += 1
     event = EventBase()
     event.nolog = True
     event.nobind = True
     if self.counter % 60 == 0:
         event.type = event.cbtype = 'TICK60'
         callbacks.check(self.bot, event)
     if self.counter % 10 == 0:
         event.type = event.cbtype = 'TICK10'
         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)
Пример #5
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(bytes(container.hashkey, "utf-8"), bytes(XMLunescape(container.payload), "utf-8"), 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
    e.dontbind = True
    bot.doevent(e)
    event.status = "done"  
    return
Пример #6
0
def boteventcb(inputdict, request, response):
    body = request.body
    payload = json.loads(body)
    botjson = payload['bot']
    logging.warn(botjson)
    cfg = LazyDict(json.loads(botjson))
    bot = BotFactory().create(cfg.type, cfg)
    logging.warn("created bot: %s" % bot.tojson(full=True))
    eventjson = payload['event']
    event = EventBase()
    event.update(LazyDict(json.loads(eventjson)))
    logging.warn("created event: %s" % event.tojson(full=True))
    event.isremote = True
    event.notask = True
    bot.doevent(event)
Пример #7
0
 def __init__(self, bot=None): 
     EventBase.__init__(self, bot=bot)
     self.bottype = "tornado"
     self.cbtype = "TORNADO"
     self.bot = bot
     self.how = "overwrite"
Пример #8
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 = '<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)