// ############################
// Cleverbot functions for mudc
// ############################

cb_session = "";
cb_prevref = "";

function cb_query(message) {
	var url = "http://cleverbot.com/webservicemin";
	
	var reqstr = "stimulus="+http_escape(message)+"&start=y&sessionid="+cb_session;

	reqstr += "&icognoid=wsf&icognocheck=";
	reqstr += md5( reqstr.substring(9, 29) );
	reqstr +=
		"&fno=0&prevref=" + cb_prevref + 
		"lineref=&sub=Say&islearning=0&cleanslate=false"
	;
	
	mudc_console("Waiting for cleverbot...");
	var response = http_post(url, reqstr);
	mudc_console("Got a response from cleverbot.");
	
	if (! response.length) return "";
	
	var response_data = response.split(String.fromCharCode(13));
	cb_session = response_data[1];
	cb_prevref = response_data[10];
	
	return response_data[0];
}