Exemplo n.º 1
0
Arquivo: chat.py Projeto: Javran/twig
	def post(self):
		# parse message
		message = xmpp.Message(self.request.POST)
		raw_text = message.body
		account = message.sender.split('/')[0].lower()
		# find active user of this account
		uid = twig_db.getActiveUser(account)

		r = Reply()

		isPreCmd, precmd = command.isIdCommand( raw_text )
		if isPreCmd:
			cmd_id, raw_text = precmd
			r.h( cmd_id )

		isCmd, data = command.parseText( raw_text )	
		if isCmd:
			# is command
			cmd, params = data
			command.dispatchCommand(account, cmd, params, r)
			if len( r.dump() ) > 0:
				message.reply( r.dump() )
		else:
			# is text
			if uid:
				command.dispatchCommand(account, 'send', data, r) 
				message.reply( r.dump() )
			else:
				r.l( "!no active user found")
				message.reply( r.dump() )
Exemplo n.º 2
0
	def get(self):
		raw = self.request.get("raw")
		cmd = self.request.get("cmd")
		params = self.request.get("params")
		if params is None:
			params = ''

		self.response.write(FORM)
		account = "*****@*****.**"
		r = Reply() 
		if raw is not None and len(raw)>0:
			# find active user of this account
			uid = twig_db.getActiveUser(account)

			isPreCmd, precmd = command.isIdCommand( raw )
			if isPreCmd:
				cmd_id, raw = precmd
				r.h( cmd_id )

			isCmd, data = command.parseText( raw )	
			if isCmd:
				# is command
				cmd, params = data
				command.dispatchCommand(account, cmd, params, r)
				if len( r.dump() ) ==0:
					r.l("(blank reply)")
			else:
				# is text
				if uid:
					command.dispatchCommand(account, 'send', data, r) 
				else:
					r.l("!no active account found")

		else:
			if cmd is not None and len(cmd)>0:
				command.dispatchCommand( account, cmd, params, r )
		
		reply = r.dump()
		if len(reply)>0:
			self.response.write( ("""
				<h1>Result</h1>
				value:<br /><textarea readonly="true" rows="20" cols="50">%s</textarea>
			""" % reply))