Location: PHPKode > scripts > t0xirc > t0xirc/example.php
#!/usr/local/bin/php
<?

/*

This is a very simple example of an interactive bot using t0xirc.

The script says "hello" when it connects to the bot, and monitors the channel
text and private queries.

It echoes the public channel text to the console, can answer a basic question,
and quits when someone tells him to do in private.

*/

include "t0xirc.php";

class example_bot extends t0xirc_bot {

	function example_bot($login, $pass) {

		parent::t0xirc_bot($login, $pass);

	}

	function on_pubmsg($nick, $msg) {

		if (strpos($msg, "where?")!==false) $this->say("$nick: DTC");
		echo "$nick said '$msg'\n";

	}

	function on_privmsg($nick, $msg) {

		if ($msg=="quit") exit;

	}

	function on_join($nick, $host) {

		$this->say("hi $nick");

	}

}

$mybot =& new example_bot("login", "pass");

$mybot->connect() or die("Unable to connect\n");
$mybot->say("hello world");

echo "connected to ".$mybot->bot_nick.", monitoring ".$mybot->channel["name"].".\n";

foreach($mybot->channel["members"] as $user_arr) {

	echo "- ".$user_arr["nickname"]."\n";

}

$mybot->run();

?>
Return current item: t0xirc