Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set("UTC");
- $server = "irc.rizon.net";
- $port = 6667;
- $nickname = "imabot";
- $ident = "imanooBOT";
- $gecos = "LiquidFenrir.irc.bot";
- $chan = "#imanoob";
- $quotes = json_decode(file_get_contents("./quotes.json"), true);
- print_r($quotes);
- $trigger_char = "!";
- $uno_mode = false;
- require("modules.php");
- print_r($commands);
- function write($msg) {
- echo $msg."\n";
- }
- function isOwner($user) {
- write("owner check");
- $tmpvar = false;
- print_r($user);
- if ($user["host"] == "LiquidFenrir.irc.name") {
- $tmpvar = true;
- }
- write($tmpvar);
- return $tmpvar;
- }
- $socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP);
- $error = socket_connect($socket,$server,$port);
- if ($socket === false) {
- $errorCode = socket_last_error();
- $errorString = socket_strerror($errorCode);
- die("Error $errorCode: $errorString\n");
- }
- socket_write($socket, "NICK $nickname\r\n");
- socket_write($socket, "USER $ident * 8 :$gecos\r\n");
- while(is_resource($socket)) {
- $data = trim(socket_read($socket, 1024, PHP_NORMAL_READ));
- echo $data."\r\n";
- $d = explode(" ", $data);
- $d = array_pad($d, 10, "");
- $d[0] = substr($d[0],1);
- if ($d[0] === "ING") { //ping, first character missing due to substr above
- socket_write($socket, "PONG ".$d[1]."\r\n");
- $sender = array("nick" => "ping", "host" => "ping");
- } elseif (substr($d[0],0,4) == "irc.") {
- $sender = array("nick" => "server", "host" => "server");
- } else {
- $nick_stop = strpos($d[0],"!");
- $user_stop = strpos($d[0],"@");
- $sender = array(
- "nick" => substr($d[0],0,$nick_stop),
- "user" => substr($d[0],$nick_stop+2,$user_stop-$nick_stop-2),
- "host" => substr($d[0],$user_stop+1)
- );
- }
- unset($d[0]);
- $action = $d[1];
- unset($d[1]);
- $channel = $d[2];
- unset($d[2]);
- $message = substr(trim(implode(" ", $d)),1);
- $word = strtolower(substr($d[3],1));
- unset($d[3]);
- $msg = trim(implode(" ", $d));
- $info = array(
- "socket" => $socket,
- "message" => $message,
- "msg" => $msg,
- "d" => $d,
- "sender" => $sender,
- "channel" => $channel,
- "action" => $action
- );
- if ($action === "INVITE") {
- socket_write($socket, "JOIN $message\r\n");
- }
- if ($action === "376" || $action === "422") {
- socket_write($socket, "JOIN $chan\r\n");
- }
- if (substr($word,0,1) === $trigger_char) {
- $word = substr($word,1);
- if ($word == "reload") {
- if (isOwner($info["sender"])) {
- unset($commands);
- require("modules.php");
- print_r($commands);
- socket_write($socket, "PRIVMSG $channel :Reload complete.\r\n");
- }
- } elseif ($word == "uno") {
- $uno_mode = !$uno_mode;
- if ($uno_mode) {
- socket_write($socket, "PRIVMSG $channel :UNO mode engaged!\r\n");
- socket_write($socket, "PRIVMSG UNOBot :.pce-on\r\n");
- socket_write($socket, "PRIVMSG $channel :.uj\r\n");
- } else {
- socket_write($socket, "PRIVMSG $channel :UNO mode disengaged!\r\n");
- socket_write($socket, "PRIVMSG $channel :.leave\r\n");
- }
- } elseif ($word == "commands") {
- socket_write($socket, "PRIVMSG $channel :Trigger character: '$trigger_char'\r\n");
- socket_write($socket, "PRIVMSG $channel :Available commands:\r\n");
- socket_write($socket, "PRIVMSG $channel :".implode(", ", array_keys($commands)).".\r\n");
- } elseif ($word == "quit") {
- if (isOwner($sender)) {
- socket_write($socket, "QUIT \r\n");
- break;
- }
- } elseif ($word == "quote") {
- print_r($info);
- $call = $commands["quote"];
- $quotes = $call($info, $quotes);
- } elseif (array_key_exists($word, $commands)) {
- print_r($info);
- $call = $commands[$word];
- $call($info);
- }
- }
- if ($uno_mode && $sender["host"] == "play.uno.with.me") {
- $call = $commands["uno"];
- $state = $call($info);
- if ($state) {
- $uno_mode = false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment