// Weedle II
// Responds with cleverbot to everything.
// Checks for reconnections

var myname = "";
var await = 0;
var await_interval = 30;
var pushed = false;

function begin(name) {
	myname = name;
	nmdc_connect("ma.songil.es", 411, name, "", 0);

	if (! pushed) {
		_onPublic.push(weedleTechnology);
		_onTick.push(tickHandler);
		pushed = true;
	}
}

// Ensure we're connected to the hub
function checkConnection() {
	if (nmdc_connected() != 1) {
		mudc_console("Reconnecting to the hub...");
		nmdc_connect("ma.songil.es", 411, myname, "", 0);
	}	
}
function tickHandler() {
	await++;
	if (await >= await_interval) {		
		checkConnection();
		await = 0;
	}
}

function weedleTechnology(user, text) {
	if (user != myname && user != "PtokaX") {
		var response = cb_query(text);
		if (response.length) nmdc_say(response);
	}
}