Пример #1
0
Файл: bot.py Проект: 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)
Пример #2
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)
Пример #3
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()
Пример #4
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()