var cleverbot = new ( require( "cleverbot-node" ) );
var busy = false;
var excited = false;

var phrases = [
	"hello",
	"hey",
	"hi",
	"what's",
	"how",
	"where"
];

bot.on( "Message", OnMessage );

function ShouldReply( msg ) {

	// Don't reply if we are already replying
	if ( busy )
		return false;
		
	// 10% chance to reply if excited
	if ( excited )
		return Math.random() > 0.90;

	// 25% chance to reply if first word is a defined phrase
	var firstWordLower = msg.toLowerCase().split( " " )[ 0 ];

	if ( phrases.indexOf( firstWordLower ) != -1 )
		return Math.random() > 0.75;

	// 3% chance by default
	return Math.random() > 0.96;

}

function OnMessage( name, steamID, msg ) {

	if ( !ShouldReply( msg ) )
		return;

	busy = true;

	cleverbot.write( msg, function( res ) {

		if ( res && res.message )
			bot.sendMessage( res.message );

		busy = false;

	} );

}

bot.registerCommand( "excite", function() {

	excited = !excited;
	
});

@@ -159,16 +159,101 @@
 re%22%0A%5D;%0A%0A
+var botNames = %5B%22hash%22,%22#%22,%22bot%22,%22emneknagg%22%5D;%0Avar botNameLength = botNames.length;%0A%0A
 bot.on( 
@@ -380,18 +380,337 @@
  false;%0A
-%09%09
+%0A%09// 90%25 chance to reply if the bot's name is spoken.%0A%09///Loop through the names of the bot%0A%0A%09for(i=0; i != botNameLength; i++) %7B%0A%09%09//if one of the words is equal to an entry in botNames%0A%0A%09%09if(msg.toLowerCase().indexOf(botNames%5Bi%5D) != -1) %7B%0A%0A%09%09%09//Make the bot speak 90%25 of the time%0A%09%09%09return Math.random() %3E 0.10;%0A%09%09%7D%0A%09%7D%0A
 %0A%09// 10%25
@@ -1339,14 +1339,13 @@
 xcited;%0A
-%09
 %0A%7D);%0A

Make the bot reply when its name is called