phrase response(s)
// Build our response string
// get a random choice of response based on the key
// Then structure the response
var pass = 0;
var thisstr = "";
function phrase( sString, keyidx ){
idxmin = keyword[keyidx].idx;
idrange = keyword[keyidx].end - idxmin + 1;
choice = keyword[keyidx].idx + Math.floor( Math.random() * idrange );
if( choice == keyword[keyidx].last && pass < 5 ){
pass++; phrase(sString, keyidx );
}
keyword[keyidx].last = choice;
var rTemp = response[choice];
var tempt = rTemp.charAt( rTemp.length - 1 );
if(( tempt == "*" ) || ( tempt == "@" )){
var sTemp = padString(sString);
var wTemp = sTemp.toUpperCase();
var strpstr = wTemp.indexOf( " " + keyword[keyidx].key + " " );
strpstr += keyword[ keyidx ].key.length + 1;
thisstr = conjugate( sTemp.substring( strpstr, sTemp.length ) );
thisstr = strTrim( unpadString(thisstr) )
if( tempt == "*" ){
sTemp = replaceStr( rTemp, "<*", " " + thisstr + "?", 0 );
} else { sTemp = replaceStr( rTemp, "<@", " " + thisstr + ".", 0 );
}
} else sTemp = rTemp;
return sTemp;
}