def parsesocket(self, handler, message): """ parse request/response into a WebEvent. """ self.handler = handler try: data = LazyDict(json.loads(message)) except Exception, ex: logging.error("failed to parse data: %s - %s" % (message, str(ex))) ; return self logging.info("incoming: %s" % message) self.div = data.target self.userhost = tornado.escape.xhtml_escape(handler.current_user) if not self.userhost: raise Exception("no current user.") self.isweb = True input = data.cmnd self.how = data.how or self.how logging.info("cmnd is %s - how is %s" % (input, self.how)) self.origtxt = fromenc(input.strip(), self.bot.encoding) self.txt = self.origtxt self.usercmnd = self.txt and self.txt.split()[0] self.groupchat = False self.nick = self.userhost.split("@")[0] self.auth = fromenc(self.userhost) self.stripped = stripped(self.auth) self.domain = None self.channel = stripped(self.userhost) logging.debug(u'tornado - parsed - %s - %s' % (self.txt, self.userhost)) self.makeargs() return self
def parse(self, response, request): """ parse request/response into a WebEvent. """ logging.warn("parsing %s" % request.body) body = getpostdata_gae(request) logging.warn("body is %s" % body) data = LazyDict(getjson().loads(body)) self.target = data.target self.how = data.how if not self.how: self.how = "channel" input = data.cmnd self.isweb = True self.origtxt = fromenc(input.strip(), self.bot.encoding) self.txt = self.origtxt self.usercmnd = self.txt and self.txt.split()[0] self.groupchat = False self.response = response self.request = request (userhost, user, u, nick) = checkuser(response, request, self) self.userhost = fromenc(userhost) self.nick = fromenc(nick) self.auth = fromenc(userhost) self.stripped = stripped(self.auth) self.domain = None self.channel = stripped(userhost) logging.debug(u"web - parsed - %s - %s" % (self.txt, self.userhost)) self.makeargs() return self
def parse(self, handler, request): """ parse request/response into a WebEvent. """ #logging.warn(dir(handler)) #logging.warn(dir(request)) #logging.warn(request.arguments) #logging.warn(request.body) self.handler = handler self.request = request self.userhost = tornado.escape.xhtml_escape(handler.current_user) if not self.userhost: raise Exception("no current user.") try: how = request.arguments['how'][0] except KeyError: how = "background" if not how: how = "background" self.how = how if self.how == "undefined": self.how = "overwrite" logging.warn("web - how is %s" % self.how) #self.webchan = request.headers.get('webchan') #input = request.headers.get('content') or request.headers.get('cmnd') if not input: try: input = request.arguments['content'] or request.arguments['cmnd'] except KeyError: pass self.isweb = True logging.warn("input is %s" % input) self.origtxt = fromenc(input[0].strip(), self.bot.encoding) self.txt = self.origtxt self.usercmnd = self.txt and self.txt.split()[0] self.groupchat = False self.nick = self.userhost.split("@")[0] self.auth = fromenc(self.userhost) self.stripped = stripped(self.auth) self.domain = None self.channel = stripped(self.userhost) logging.debug(u'tornado - parsed - %s - %s' % (self.txt, self.userhost)) self.makeargs() return self
def handle_message(self, data, *args, **kwargs): """ message handler. """ if '<delay xmlns="urn:xmpp:delay"' in str(data): logging.debug("ignoring delayed message") ; return m = Message() m.parse(data, self) if m.type == 'groupchat' and m.subject: logging.debug("%s - checking topic" % self.cfg.name) self.topiccheck(m) nm = Message(m) callbacks.check(self, nm) return if m.isresponse: logging.debug("%s - message is a response" % self.cfg.name) return jid = None m.origjid = m.jid #if self.cfg.user in m.jid or (m.groupchat and self.cfg.nick == m.nick): # logging.error("%s - message to self .. ignoring" % self.cfg.name) # return 0 if self.cfg.fulljids and not m.msg: utarget = self.userhosts.get(m.nick) if utarget: m.userhost = m.jid = m.auth = stripped(utarget) else: m.userhost = m.jid if m.msg: m.userhost = stripped(m.userhost) logging.debug("using %s as userhost" % m.userhost) m.dontbind = False self.put(m)
def parse(self, handler, request, path=None): """ parse request/response into a WebEvent. """ self.handler = handler self.request = request self.userhost = tornado.escape.xhtml_escape(handler.current_user) if not self.userhost: raise Exception("no current user.") try: how = request.arguments['how'][0] except KeyError: how = "background" if not how: how = "background" self.how = how if self.how == "undefined": self.how = "overwrite" logging.warn("web - how is %s" % self.how) input = request.headers.get('content') or request.headers.get('cmnd') if not input: try: input = request.arguments['content'] or request.arguments['cmnd'] except KeyError: pass self.isweb = True if not input: logging.warn("input is %s" % input) ; raise NoInput(input) self.txt = fromenc(input[0].strip(), self.bot.encoding) self.nick = self.userhost.split("@")[0] self.auth = fromenc(self.userhost) self.stripped = stripped(self.auth) self.channel = stripped(self.userhost) logging.debug(u'tornado - parsed - %s - %s' % (self.txt, self.userhost)) self.prepare() return self
def handle_message(self, data, *args, **kwargs): """ message handler. """ if '<delay xmlns="urn:xmpp:delay"' in str(data): logging.debug("ignoring delayed message") return m = Message() m.parse(data, self) if m.type == 'groupchat' and m.subject: logging.debug("%s - checking topic" % self.cfg.name) self.topiccheck(m) nm = Message(m) callbacks.check(self, nm) return if m.isresponse: logging.debug("%s - message is a response" % self.cfg.name) return jid = None m.origjid = m.jid #if self.cfg.user in m.jid or (m.groupchat and self.cfg.nick == m.nick): # logging.error("%s - message to self .. ignoring" % self.cfg.name) # return 0 if self.cfg.fulljids and not m.msg: utarget = self.userhosts.get(m.nick) if utarget: m.userhost = m.jid = m.auth = stripped(utarget) else: m.userhost = m.jid if m.msg: m.userhost = stripped(m.userhost) logging.debug("using %s as userhost" % m.userhost) m.dontbind = False self.put(m)
def parseAPI(self, handler, apitype, path): """ parse request/response into a WebEvent. """ #logging.warn(dir(handler)) #logging.warn(dir(handler.request)) #logging.warn(request.arguments) #logging.warn(request.body) self.handler = handler self.request = handler.request self.query = self.request.query self.upath = path self.apitype = apitype self.userhost = tornado.escape.xhtml_escape(handler.current_user) if not self.userhost: raise Exception("no current user.") input = path self.isweb = True logging.warn("input is %s" % input) if not input: raise NoInput(input) self.txt = fromenc(input.strip(), self.bot.encoding) self.nick = self.userhost.split("@")[0] self.auth = fromenc(self.userhost) self.stripped = stripped(self.auth) self.channel = stripped(self.userhost) logging.debug(u'tornado - parsed - %s - %s' % (self.txt, self.userhost)) self.prepare() return self
def handle_presence(self, data, *args, **kwargs): """ message handler. """ try: p = Presence() p.parse(data, self) frm = p.fromm nickk = "" nick = p.nick if self.cfg.user in frm: self.pongcheck = True if nick: self.userhosts[nick] = stripped(frm) nickk = nick jid = p.fromm if nickk and jid and self.cfg.fulljids: channel = p.channel if not self.jids.has_key(channel): self.jids[channel] = {} self.jids[channel][nickk] = jid self.userhosts[nickk] = stripped(jid) logging.debug( '%s - setting jid of %s (%s) to %s' % (self.cfg.name, nickk, channel, self.userhosts[nickk])) if p.type == 'subscribe': pres = Presence({'to': p.fromm, 'type': 'subscribed'}) self.send(pres) pres = Presence({'to': p.fromm, 'type': 'subscribe'}) self.send(pres) nick = p.resource if p.type != 'unavailable': p.joined = True p.type = 'available' elif self.cfg.user in p.userhost: try: del self.jids[p.channel] logging.debug('%s - removed %s channel jids' % (self.cfg.name, p.channel)) except KeyError: pass else: try: del self.jids[p.channel][p.nick] logging.debug('%s - removed %s jid' % (self.cfg.name, p.nick)) except KeyError: pass self.put(p) except Exception, ex: logging.error(str(ex))
def handle_presence(self, data, *args, **kwargs): """ message handler. """ try: p = Presence() p.parse(data, self) frm = p.fromm nickk = "" nick = p.nick if self.cfg.user in frm: self.pongcheck = True if nick: self.userhosts[nick] = stripped(frm) nickk = nick jid = p.fromm if nickk and jid and self.cfg.fulljids: channel = p.channel if not self.jids.has_key(channel): self.jids[channel] = {} self.jids[channel][nickk] = jid self.userhosts[nickk] = stripped(jid) logging.debug('%s - setting jid of %s (%s) to %s' % (self.cfg.name, nickk, channel, self.userhosts[nickk])) if p.type == 'subscribe': pres = Presence({'to': p.fromm, 'type': 'subscribed'}) self.send(pres) pres = Presence({'to': p.fromm, 'type': 'subscribe'}) self.send(pres) nick = p.resource if p.type != 'unavailable': p.joined = True p.type = 'available' elif self.cfg.user in p.userhost: try: del self.jids[p.channel] logging.debug('%s - removed %s channel jids' % (self.cfg.name, p.channel)) except KeyError: pass else: try: del self.jids[p.channel][p.nick] logging.debug('%s - removed %s jid' % (self.cfg.name, p.nick)) except KeyError: pass self.put(p) except Exception, ex: logging.error(str(ex))
def parsesocket(self, handler, message): """ parse request/response into a WebEvent. """ self.handler = handler try: data = LazyDict(json.loads(message)) except Exception, ex: logging.error("failed to parse data: %s - %s" % (message, str(ex))) ; return self logging.info("incoming: %s" % message) self.div = data.target self.userhost = tornado.escape.xhtml_escape(handler.current_user) if not self.userhost: raise Exception("no current user.") self.isweb = True input = data.cmnd self.how = data.how or self.how logging.warn("cmnd is %s - how is %s" % (input, self.how)) self.txt = fromenc(input.strip(), self.bot.encoding) self.nick = self.userhost.split("@")[0] self.auth = fromenc(self.userhost) self.stripped = stripped(self.auth) self.channel = stripped(self.userhost) logging.debug(u'tornado - parsed - %s - %s' % (self.txt, self.userhost)) self.prepare() return self
def parse(self, request, response): """ parse incoming request/response into a XMPPEvent. """ self.copyin(LazyDict(request.POST)) (userhost, user, u, nick) = checkuser(response, request) self.userhost = self['from'] self.origin = self.channel if user: self.auth = user.email() else: self.auth = stripped(self.userhost) logging.info('xmpp - auth is %s' % self.auth) self.resource = resource(self['from']) self.jid = self['from'] self.to = stripped(self['to']) self.channel = stripped(self.userhost) self.stripped = stripped(self.userhost) self.nick = self.stripped.split("@")[0] self.origin = self.channel input = self.body or self.stanza input = input.strip() self.origtxt = input self.txt = input self.usercmnd = self.txt.split()[0].lower() logging.debug(u'xmpp - in - %s - %s' % (self.userhost, self.txt)) return self
handle_exception() if not input: try: input = request.GET['content'] or request.GET['cmnd'] except KeyError: pass self.isweb = True self.origtxt = fromenc(input.strip(), self.bot.encoding) self.txt = self.origtxt self.usercmnd = self.txt and self.txt.split()[0] self.groupchat = False self.response = response self.request = request (userhost, user, u, nick) = checkuser(response, request, self) self.userhost = fromenc(userhost) self.nick = fromenc(nick) self.auth = fromenc(userhost) self.stripped = stripped(self.auth) self.domain = None self.channel = stripped(userhost) logging.debug(u'web - parsed - %s - %s' % (self.txt, self.userhost)) self.makeargs() return self def reply(self, txt, result=[], event=None, origin="", dot=u", ", nr=600, extend=0, *args, **kwargs): """ reply to this event """# if self.checkqueues(result): return if not txt: return if self.how == "background": txt = self.bot.makeoutput(self.channel, txt, result, origin=origin, nr=nr, extend=extend, *args, **kwargs) self.bot.outnocb(self.channel, txt, self.how, response=self.response) else:
try: input = request.GET['content'] or request.GET['cmnd'] except KeyError: pass self.isweb = True self.origtxt = fromenc(input.strip(), self.bot.encoding) self.txt = self.origtxt self.usercmnd = self.txt and self.txt.split()[0] self.groupchat = False self.response = response self.request = request (userhost, user, u, nick) = checkuser(response, request, self) self.userhost = fromenc(userhost) self.nick = fromenc(nick) self.auth = fromenc(userhost) self.stripped = stripped(self.auth) self.domain = None self.channel = stripped(userhost) logging.debug(u'web - parsed - %s - %s' % (self.txt, self.userhost)) self.makeargs() return self def reply(self, txt, result=[], event=None, origin="", dot=u", ", nr=600, extend=0, *args,