Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Paste Description for Norbot 1

88.249.36.188

Norbot 1
Thursday, April 17th, 2008 at 8:30:39am MDT 

  1. //===================================================================
  2. //========================CLASS.PHP==================================
  3. //===================================================================
  4.  
  5. <?php
  6. define("VERSION", "1.0");
  7. set_time_limit(0); // Set time limit at 0, so it wont be cut off after 30sec
  8. error_reporting(E_ALL); // Make it report all errors.
  9.  
  10. class ZeroBot {
  11.     // Class variables
  12.     var $CONFIG = Array();
  13.     var $con = array();
  14.     var $buffer = array();
  15.     var $perform = true;
  16.     var $onText = Array();
  17.     var $onJoin = Array();
  18.     var $onPart = Array();
  19.     var $onCtcp = Array();
  20.     var $onUserMode = Array();
  21.     var $onNumeric = Array();
  22.     var $channels = Array();
  23.     var $usersOnChannel = Array();
  24.  
  25.     function ZeroBot ()  {
  26.         // Define some default values.
  27.         $this->CONFIG['nick'] = "Norbot36";
  28.         $this->CONFIG['ident'] = "Norek Bot ". VERSION;
  29.         $this->buffer['old_buffer'] = "";
  30.         $this->buffer['new'] = false;
  31.         $this->CONFIG['admin'] = "";
  32.     }
  33.  
  34.     function connect () {
  35.         // if configured, connect.
  36.         if (count($this->CONFIG) >= 4) {
  37.             $this->con['socket'] = fsockopen($this->CONFIG['server'], $this->CONFIG['port']);
  38.             if (!$this->con['socket']) {
  39.                 $this->error("Could not connect to: ". $this->CONFIG['server'] ." on port ". $this->CONFIG['port']);
  40.             } else {
  41.                    $this->send("USER ". $this->CONFIG['nick'] ." ". $this->CONFIG['server'] ." ". $this->CONFIG['server'] ." :". $this->CONFIG['ident']);
  42.                 $this->send("NICK ". $this->CONFIG['nick'] ." ". $this->CONFIG['server']);
  43.             }
  44.         } else {
  45.             $this->error("Not configured correctly!");
  46.         }
  47.     }
  48.  
  49.     function newData () {
  50.         // check if there's new data to be read, and handle if ping.
  51.         $this->buffer['new'] = false;
  52.         $data = trim(fgets($this->con['socket']));
  53.         if (!empty($data)) {
  54.             $this->buffer['all'] = $data;
  55.             if(substr($data, 0, 6) == 'PING :') {
  56.                 $this->send('PONG :'.substr($data, 6), false);
  57.                 if ($this->perform) {
  58.                     $this->perform();               
  59.                 }
  60.                 return false;
  61.             }
  62.             $this->parse_buffer();
  63.             $this->buffer['new'] = true;
  64.             return true;
  65.         }
  66.         return false;
  67.     }
  68.  
  69.     function perform () {
  70.         // actions to be done on connect.
  71.         $this->join($this->CONFIG['chan'], $this->CONFIG['key']);
  72.         $this->perform = false;   
  73.     }
  74.    
  75.     function printData () {
  76.         //  output the data
  77.         if ($this->buffer['new'] && count($this->buffer['parsed']) > 4) {
  78.             echo date("[H:i:s]") ."{".$this->buffer['parsed']['username']." / ". $this->buffer['parsed']['command'] ." / ". $this->buffer['parsed']['channel'] ."} ". $this->buffer['parsed']['text']. "\n\r";
  79.         }
  80.     }
  81.  
  82.     function writeToLog () {
  83.         // Functie waarmee je logs kan maken.
  84.         $file = "C:\web\www\bot2\Logs\\" . $this->buffer['parsed']['channel'] . ".txt";
  85.         $fh = fopen($file, 'a');
  86.         fwrite($fh, date("[H:i:s]") ."{".$this->buffer['parsed']['username']." / ". $this->buffer['parsed']['command'] ." / ". $this->buffer['parsed']['channel'] ."} ". $this->buffer['parsed']['text']. "\n");
  87.         fclose($fh);
  88.     }
  89.    
  90.     function events () {
  91.         // check which event needs to be triggered, and trigger it.
  92.         if (!empty($this->buffer['parsed']['command'])) {
  93.             if (strtoupper($this->buffer['parsed']['command']) == "PRIVMSG") {
  94.                 if (substr(trim($this->buffer['parsed']['text']),0,1) == chr(001)) {
  95.                     $this->onCtcp(trim($this->buffer['parsed']['text']));
  96.                 } elseif (!empty($this->CONFIG['admin']) && strtolower($this->buffer['parsed']['username']) == strtolower($this->CONFIG['admin'])) {
  97.                     $this->onText(trim($this->buffer['parsed']['text']));
  98.                 }
  99.             }
  100.             if (strtoupper($this->buffer['parsed']['command']) == "NUMERIC") {
  101.                 $this->onNumeric($this->buffer['parsed']['text'], $this->buffer['parsed']['channel'], $this->buffer['parsed']['target']);
  102.             }   
  103.             if (strtoupper($this->buffer['parsed']['command']) == "NICK") {
  104.                 $this->onNick($this->buffer['parsed']['old'], $this->buffer['parsed']['new']);
  105.             }
  106.             if (strtoupper($this->buffer['parsed']['command']) == "JOIN") {
  107.                 $this->onJoin($this->buffer['parsed']['username'], $this->buffer['parsed']['channel']);
  108.             }
  109.             if (strtoupper($this->buffer['parsed']['command']) == "PART") {
  110.                 $this->onPart($this->buffer['parsed']['username'], $this->buffer['parsed']['channel']);
  111.             }
  112.             if (strtoupper($this->buffer['parsed']['command']) == "MODE" && strtoupper($this->buffer['parsed']['channel']) != strtoupper($this->CONFIG['nick'])) {
  113.                 $this->onMode($this->buffer['parsed']['username'], $this->buffer['parsed']['channel'], $this->buffer['parsed']['text']);
  114.             }
  115.             elseif (strtoupper($this->buffer['parsed']['command']) == "MODE" && strtoupper($this->buffer['parsed']['channel']) == strtoupper($this->CONFIG['nick'])) {
  116.                 $this->onUserMode($this->buffer['parsed']['username'], $this->buffer['parsed']['text']);
  117.             }
  118.         }
  119.     }
  120.    
  121.  
  122.     function setServer ($server, $port = 6667) {
  123.         if (!empty($server)) {
  124.             $this->CONFIG['server'] = $server;
  125.             $this->CONFIG['port'] = $port;
  126.         } else {
  127.             $this->error("Need valid server adres");
  128.         }
  129.     }
  130.  
  131.     function setName ($name = "ZeroBot", $ident = false) {
  132.         $this->CONFIG['nick'] = $name;
  133.         if ($ident) {
  134.             $this->CONFIG['ident'] = $ident . " [Zero bot v". VERSION . " by DaeDaluz]";
  135.         }
  136.     }
  137.  
  138.     function setChannel ($chan, $key = "") {
  139.         if (substr($chan,0,1) == "#") {
  140.             $this->CONFIG['chan'] = $chan;
  141.         } else {
  142.             $this->CONFIG['chan'] = "#" . $chan;
  143.         }
  144.         $this->CONFIG['key'] = $key;
  145.     }
  146.  
  147.     function setAdmin ($nick) {
  148.         $this->CONFIG['admin'] = $nick;
  149.     }
  150.  
  151.     function error ($error) {
  152.         trigger_error($error, E_USER_ERROR);
  153.     }
  154.  
  155.     function send ($data, $output = true) {
  156.         if ($output) {
  157.             echo date("[H:i:s]") ." -> " . $data . "\n";
  158.         }
  159.         fputs($this->con['socket'], $data."\n\r");
  160.     }
  161.  
  162.     function connected () {
  163.         if (!feof($this->con['socket'])) {
  164.             return true;
  165.         } else {
  166.             return false;
  167.         }
  168.     }
  169.  
  170.     // Make sense of the input data.
  171.     function parse_buffer() {
  172.         $buffer = NUll;
  173.         $this->buffer['parsed'] = Array();
  174.         $buffer = $this->buffer['all'];
  175.         $buffer = explode(" ", $buffer, 4);
  176.         if (count($buffer) >= 3) {
  177.             if (strpos($buffer['0'], "!")) {
  178.                 $buffer['username'] = substr($buffer[0], 1, strpos($buffer['0'], "!") - 1);
  179.             } else {
  180.                 $buffer['username'] = substr($buffer[0], 1);
  181.             }
  182.             $posExcl = strpos($buffer[0], "!");
  183.             $posAt = strpos($buffer[0], "@");
  184.             $buffer['identd'] = substr($buffer[0], $posExcl+1, $posAt-$posExcl-1);
  185.             $buffer['hostname'] = substr($buffer[0], strpos($buffer[0], "@")+1);
  186.             $buffer['user_host'] = substr($buffer[0],1);
  187.  
  188.             switch (strtoupper($buffer[1])) {
  189.                 case "JOIN":
  190.                     $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
  191.                     $buffer['command'] = "JOIN";
  192.                     $buffer['channel'] = $buffer[2];
  193.                     if (substr($buffer['channel'],0,1) == ":") {
  194.                         $buffer['channel'] = substr($buffer['channel'],1);
  195.                     }
  196.                 break;
  197.                 case "QUIT":
  198.                     $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
  199.                     $buffer['command'] = "QUIT";
  200.                     $buffer['channel'] = "";
  201.                 break;
  202.                 case "NOTICE":
  203.                     $buffer['text'] = substr($buffer[3], 1);
  204.                     $buffer['command'] = "NOTICE";
  205.                     $buffer['channel'] = $buffer[2];
  206.                 break;
  207.                 case "PART":
  208.                     $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
  209.                     $buffer['command'] = "PART";
  210.                     $buffer['channel'] = $buffer[2];
  211.                 break;
  212.                 case "MODE":
  213.                     if (substr($buffer[3], 0, 1) == ":") {
  214.                         $buffer['text'] = substr($buffer[3], 1);
  215.                     } else {
  216.                         $buffer['text'] = $buffer[3];
  217.                     }
  218.                     $buffer['command'] = "MODE";
  219.                     $buffer['channel'] = $buffer[2];
  220.                 break;
  221.                 case "NICK":
  222.                     $buffer['text'] = $buffer['username']." => ". $buffer[2]." ( ".$buffer['user_host']." )";
  223.                     $buffer['old'] = $buffer['username'];
  224.                     $buffer['new'] = $buffer[2];
  225.                     $buffer['command'] = "NICK";
  226.                     $buffer['channel'] = "";
  227.                 break;
  228.                 case is_numeric($buffer[1]) == true:
  229.                     $buffer['text'] = $buffer[3];
  230.                     $buffer['command'] = "NUMERIC";
  231.                     $buffer['channel'] = $buffer[1];
  232.                     $buffer['target'] = $buffer[2];
  233.                 break;
  234.                 default:
  235.                     $buffer['command'] = $buffer[1];
  236.                     if (strtoupper($buffer[2]) == strtoupper($this->CONFIG['nick'])) {
  237.                         $buffer['channel'] = $buffer['username'];
  238.                     } else {
  239.                         $buffer['channel'] = $buffer[2];
  240.                     }
  241.                     $buffer['text'] = substr($buffer[3], 1);
  242.                 break;
  243.             }
  244.             $this->buffer['parsed'] = $buffer;
  245.         }
  246. }
  247.  
  248.     function meIson ($chan) {
  249.         if (in_array(strtolower($chan), $this->channels)) {
  250.             return true;
  251.         } else {
  252.             return false;
  253.         }
  254.     }
  255.  
  256.     function join ($chan, $key = "") {
  257.         $this->send("JOIN " . $chan . " " . $key);
  258.     }
  259.  
  260.     function msg ($chan, $msg) {
  261.             $this->send('PRIVMSG '. $chan .' :'.$msg);
  262.     }
  263.  
  264.     function ctcp ($to, $msg) {
  265.         $split = explode(" ", $msg, 2);
  266.         $this->send("NOTICE ". $to ." :" . chr(001) . strtoupper($split[0]) . " " . $split[1] . chr(001));
  267.     }
  268.  
  269.     function part ($chan) {
  270.         $this->send("PART " . $chan);
  271.     }
  272.  
  273.     function quit ($msg = "Zerobot singing off..") {
  274.         $this->send("QUIT :" . $msg);
  275.     }
  276.  
  277.     function mode ($chan, $modes) {
  278.         $this->send("MODE ". $chan . " " . $modes);
  279.     }
  280.  
  281.     function Op ($chan, $nick) {
  282.         $this->mode ($chan, "+o " . $nick);
  283.     }
  284.  
  285.     function deOp ($chan, $nick) {
  286.         $this->mode ($chan, "-o " . $nick);
  287.     }
  288.    
  289.     function changeName ($name) {
  290.         $this->send("NICK :" . $name);
  291.     }
  292.    
  293.     function randomName () {
  294.         $newName = substr($this->CONFIG['nick'],0,3) . rand(1000,9999);
  295.         $this->changeName($newName);
  296.     }
  297.    
  298.     function storeUsers () {
  299.         $text = $this->buffer['parsed']['text'];
  300.         $exp = explode(" ", $text, 8);
  301.         $exp[0] = strtolower($exp[0]);
  302.        
  303.         if (in_array($exp[0], array_keys($this->usersOnChannel))) {
  304.             $getal = count($this->usersOnChannel[$exp[0]]);
  305.         } else {
  306.             $getal = 0;
  307.         }
  308.         $this->usersOnChannel[$exp[0]][$getal]['nick'] = $exp[4];
  309.         $this->usersOnChannel[$exp[0]][$getal]['ident'] = $exp[1];
  310.         $this->usersOnChannel[$exp[0]][$getal]['host'] = $exp[2];
  311.         $this->usersOnChannel[$exp[0]][$getal]['info'] = $exp[7];
  312.     }
  313.    
  314.    
  315.     function ison ($chan, $nick) {
  316.         $chan = strtolower($chan);
  317.         foreach ($this->usersOnChannel[$chan] as $value) {
  318.             if (strtolower($value['nick']) == strtolower($nick)) {
  319.                     return true;
  320.             }
  321.         }
  322.         return false;
  323.     }
  324.    
  325.     function onMode ($nick, $chan, $modes) {
  326.         $split = explode(" ", $modes);
  327.         $extra = count($split) - 1;
  328.         $extrac = 1;
  329.         $specials = Array("o", "v", "h", "q", "a", "k");
  330.         for ($i = 0; $i < strlen($split[0]); $i++) {
  331.                 $value = substr($split[0], $i, 1);
  332.                 if ($value == "+") {
  333.                     $temp = true;
  334.                 } elseif ($value == "-") {
  335.                     $temp = false;
  336.                 } else {
  337.                     if ($temp) {
  338.                         $tmp['mode'] = $value;
  339.                         if (in_array($value, $specials) && $extra > 0) {
  340.                             $tmp['ex'] = $split[$extrac];
  341.                             if ($value == "o") {
  342.                                 $this->onOp($nick, $chan, $split[$extrac]);
  343.                             }
  344.                             $extrac++;
  345.                         }
  346.                         $plus[] = $tmp;
  347.                     } else {
  348.                         $tmp['mode'] = $value;
  349.                         if (in_array($value, $specials) && $extra > 0) {
  350.                             $tmp['ex'] = $split[$extrac];
  351.                             if ($value == "o") {
  352.                                 $this->onDeop($nick, $chan, $split[$extrac]);
  353.                             }
  354.                             $extrac++;
  355.                         }
  356.                         $min[] = $tmp;
  357.                     }
  358.                 }           
  359.         }
  360.     }
  361.  
  362.     function onUserMode ($nick, $modes) {
  363.         $split = explode(" ", $modes);
  364.         $extra = count($split) - 1;
  365.         $extrac = 1;
  366.         for ($i = 0; $i < strlen($split[0]); $i++) {
  367.             $value = substr($split[0], $i, 1);
  368.             if ($value == "+") {
  369.                 $temp = true;
  370.             } elseif ($value == "-") {
  371.                 $temp = false;
  372.             } else {
  373.                 if ($temp) {
  374.                     foreach ($this->onUserMode as $key => $val) {
  375.                         if ("+" . $value . "" == $val['mode']) {
  376.                             call_user_func(Array(&$this, $val['cmd']));
  377.                             break;
  378.                         }
  379.                     }
  380.                 } else {
  381.                     foreach ($this->onUserMode as $key => $val) {
  382.                         if ("-" . $value . "" == $val['mode']) {
  383.                             call_user_func(Array(&$this, $val['cmd']));
  384.                             break;
  385.                         }
  386.                     }
  387.                 }
  388.             }           
  389.         }
  390.     }
  391.    
  392.     function onNumeric ($text, $numeric) {
  393.         if ($this->buffer['parsed']['target'] != $this->CONFIG['nick'] && $this->buffer['parsed']['target'] != "*") {
  394.             $this->CONFIG['nick'] = $this->buffer['parsed']['target'];
  395.         }
  396.         if ($numeric == '433') {
  397.             $exp = explode(" ", $text);
  398.             if ($exp[0] == $this->CONFIG['nick']) {
  399.                 $this->randomName();
  400.             }
  401.         }
  402.         foreach ($this->onNumeric as $key => $val) {
  403.             if ($numeric == $val['numeric']) {
  404.                 call_user_func(Array(&$this, $val['cmd']));
  405.                 break;
  406.             }
  407.         }
  408.     }
  409.    
  410.     function onNick ($old, $new) {
  411.         if ($this->buffer['parsed']['old'] == $this->CONFIG['nick']) {
  412.             $this->CONFIG['nick'] = $this->buffer['parsed']['new'];
  413.         }
  414.     }
  415.  
  416.     function onOp ($by, $chan, $on) {
  417.         if (strtolower($on) == strtolower($this->CONFIG['nick']) && strtolower($chan) == strtolower($this->CONFIG['chan'])) {
  418.             $this->CONFIG['secured'] = true;
  419.             $this->mode($chan, '+ims');
  420.         }
  421.     }
  422.  
  423.  
  424.     function onDeop ($by, $chan, $on) {
  425.         if (strtolower($on) == strtolower($this->CONFIG['admin']) && strtolower($on) != strtolower($by)) {
  426.             $this->deop($chan, $by);
  427.             $this->op($chan, $on);
  428.         }
  429.     }
  430.  
  431.     function onPart($nick, $chan) {
  432.         if (strtoupper($nick) == strtoupper($this->CONFIG['nick'])) {
  433.             if (in_array(strtolower($chan), $this->channels)) {
  434.                 $this->channels[] = strtolower($chan);
  435.             }
  436.         } else {
  437.             if (!empty($chan) && !empty($nick)) {
  438.                 if (count($this->onPart) > 0) {
  439.                     foreach ($this->onPart as $key => $val) {
  440.                         $this->JPProcess($val, $key);
  441.                     }
  442.                 }
  443.             }
  444.         }
  445.     }
  446.  
  447.     function onJoin($nick, $chan) {
  448.         if (strtoupper($nick) == strtoupper($this->CONFIG['nick'])) {
  449.             if (!in_array(strtolower($chan), $this->channels)) {
  450.                 $key = Array_search(strtolower($chan), $this->channels);
  451.                 unset($this->channels[$key]);
  452.             }
  453.         }
  454.         if (!empty($chan) && !empty($nick)) {
  455.             if (count($this->onJoin) > 0) {
  456.                 foreach ($this->onJoin as $key => $val) {
  457.                     $this->JPProcess($val, $key);
  458.                 }
  459.             }
  460.         }
  461.     }
  462.  
  463.     function JPProcess ($val, $key) {
  464.         if (!empty($val['chan'])) {
  465.             if (is_array($val['chan'])) {
  466.                 if (in_array_i($key, $val['chan'])) {
  467.                     $chan_s = true;
  468.                 } else {
  469.                     $chan_s = false;
  470.                 }
  471.             } elseif (strtoupper($val['chan']) == strtoupper($chan)) {
  472.                 $chan_s = true;
  473.             } else {
  474.                 $chan_s = false;
  475.             }
  476.         } else {
  477.             $chan_s = true;
  478.         }
  479.         if (!empty($val['nick'])) {
  480.             $val['nick'] = str_replace("*me", $this->CONFIG['nick'] , $val['nick']);
  481.             if (is_array($val['nick'])) {
  482.                 if (in_array_i($this->buffer['parsed']['username'], $val['nick'])) {
  483.                     $nick_s = true;
  484.                 } else {
  485.                     $nick_s = false;
  486.                 }
  487.             } elseif (strtoupper($val['nick']) == strtoupper($this->buffer['parsed']['username'])) {
  488.                 $nick_s = true;
  489.             } else {
  490.                 $nick_s = false;
  491.             }
  492.         } else {
  493.             $nick_s = true;
  494.         }
  495.         if ($nick_s && $chan_s) {
  496.             if (is_array($val['para'])) {
  497.                 foreach ($val['para'] as $waarde) {
  498.                     $par = str_replace("*nick", $this->buffer['parsed']['username'] , $waarde);
  499.                     $para[] = str_replace("*chan", $this->buffer['parsed']['channel'] , $par);
  500.                 }
  501.                 call_user_func_array(Array(&$this, $val['cmd']), $para);
  502.             } else {
  503.                 call_user_func(Array(&$this, $val['cmd']));
  504.             }
  505.         }
  506.     }
  507.  
  508.     function onCtcp ($text) {
  509.         if (count($this->onCtcp) > 0) {
  510.             $text = str_replace(chr(001), "", $text);
  511.             $trig = explode(" ", $text, 2);
  512.             $trig = $trig[0];
  513.             $text = $trig[1];
  514.             $word = explode(" ", $text);   
  515.             foreach ($this->onCtcp as $key => $val) {
  516.                 if (strtoupper($trig) == strtoupper($val['trigger']) && (count($word) - 1) >= $val['req']) {
  517.                     if (is_array($val['para'])) {
  518.                         foreach ($val['para'] as $sleutell => $par) {
  519.                             $par = str_replace("*fulltime", date("D M j G:i:s Y"), $par);
  520.                             $par = str_replace("*version", VERSION , $par);
  521.                             $par = str_replace("*nick", $this->buffer['parsed']['username'] , $par);
  522.                             $par = str_replace("*time", date('H:i:s') , $par);
  523.                             $para[] = $par;
  524.                         }
  525.                         call_user_func_array(Array(&$this, $val['cmd']), $para);
  526.                     } else {
  527.                         call_user_func(Array(&$this, $val['cmd']));
  528.                     }
  529.                     break;
  530.                 }
  531.             }
  532.         }
  533.     }
  534.  
  535.     function tokenRep ($string, $zin) {
  536.         preg_match_all("*\*[0-9]{1,2}\-*", $string, $output, PREG_SET_ORDER);
  537.         foreach ($output as $value) {
  538.             $val = str_replace("*", "", $value[0]);
  539.             $val = str_replace("-", "", $val);
  540.             settype($val, "int");
  541.             $split = explode(" ", $zin, $val);
  542.             if (!empty($split[$val -1])) {
  543.                 $string = str_replace($value[0], $split[$val -1], $string);
  544.             }
  545.         }
  546.         preg_match_all("*\*[0-9]{1,2}*", $string, $output, PREG_SET_ORDER);
  547.         foreach ($output as $value) {
  548.             $val = str_replace("*", "", $value[0]);
  549.             settype($val, "int");
  550.             $split = explode(" ", $zin);
  551.             if (!empty($split[$val - 1])) {
  552.                 $string = str_replace($value[0], $split[$val - 1], $string);
  553.             }
  554.         }
  555.         return $string;
  556.     }
  557.  
  558.     function onText ($text) {
  559.         if (count($this->onText) > 0) {
  560.             $word = explode(" ", $text);
  561.             $trig = explode(" ", $text, 2);
  562.             foreach ($this->onText as $key => $val) {
  563.                 if (strtoupper($word[0]) == strtoupper($val['trigger']) && (count($word) - 1) >= $val['req']) {
  564.                     if (is_array($val['para'])) {
  565.                         foreach ($val['para'] as $sleutel => $waarde) {
  566.                             if (count($trig) < 2) {
  567.                                 break;
  568.                             } else {
  569.                                 $val['para'][$sleutel] = $this->tokenRep($waarde, $trig[1]);
  570.                             }
  571.                         }
  572.                         foreach ($val['para'] as $sleutell => $par) {
  573.                             $par = str_replace("*fulltime", date("D M j G:i:s Y"), $par);
  574.                             $par = str_replace("*version", VERSION , $par);
  575.                             $par = str_replace("*nick", $this->buffer['parsed']['username'] , $par);
  576.                             $par = str_replace("*time", date('H:i:s') , $par);
  577.                             $para[] = str_replace("*chan", $this->buffer['parsed']['channel'] , $par);
  578.                         }
  579.                         call_user_func_array(Array(&$this, $val['cmd']), $para);
  580.                     } else {
  581.                         call_user_func(Array(&$this, $val['cmd']));
  582.                     }
  583.                     break;
  584.                 }
  585.             }
  586.         }
  587.     }
  588.  
  589.     function newOnText ($trigger, $cmd, $reqPar = 0, $para = "") {
  590.         if (is_callable(array('ZeroBot', $cmd))) {
  591.             if (!empty($trigger)) {
  592.                 if (is_int($reqPar)) {
  593.                     $getal = count($this->onText);
  594.                     $this->onText[$getal]['trigger'] = $trigger;
  595.                     $this->onText[$getal]['cmd'] = $cmd;
  596.                     $this->onText[$getal]['req'] = $reqPar;
  597.                     $this->onText[$getal]['para'] = $para;
  598.                 } else {
  599.                     $this->error("The number of required parameters must be an INT");
  600.                 }
  601.             } else {
  602.                 $this->error("Trigger required");
  603.             }
  604.         } else {
  605.             $this->error("Not callable function! :" . $cmd);
  606.         }
  607.     }
  608.  
  609.     function newOnCtcp ($trigger, $cmd, $reqPar = 0, $para = "") {
  610.         if (is_callable(array('ZeroBot', $cmd))) {
  611.             if (!empty($trigger)) {
  612.                 if (is_int($reqPar)) {
  613.                     $getal = count($this->onCtcp);
  614.                     $this->onCtcp[$getal]['trigger'] = $trigger;
  615.                     $this->onCtcp[$getal]['cmd'] = $cmd;
  616.                     $this->onCtcp[$getal]['req'] = $reqPar;
  617.                     $this->onCtcp[$getal]['para'] = $para;
  618.                 } else {
  619.                     $this->error("The number of required parameters must be an INT");
  620.                 }
  621.             } else {
  622.                 $this->error("Trigger required");
  623.             }
  624.         } else {
  625.         $this->error("Not callable function! :" . $cmd);
  626.         }
  627.     }
  628.  
  629.     function newOnJoin ($cmd, $para = "", $nick = "", $chan = "") {
  630.         if (is_callable(array('ZeroBot', $cmd))) {
  631.             if (is_array($para)) {
  632.                 $getal = count($this->onJoin);
  633.                 $this->onJoin[$getal]['cmd'] = $cmd;
  634.                 $this->onJoin[$getal]['para'] = $para;
  635.                 $this->onJoin[$getal]['nick'] = $nick;
  636.                 $this->onJoin[$getal]['chan'] = $chan;
  637.             } else {
  638.                 $this->error("Parameters must be in array format!");
  639.             }
  640.         } else {
  641.             $this->error("Not callable function! :" . $cmd);
  642.         }
  643.     }
  644.  
  645.     function newOnPart ($cmd, $para = "", $nick = "", $chan = "") {
  646.         if (is_callable(array('ZeroBot', $cmd))) {
  647.             if (is_array($para)) {
  648.                 $getal = count($this->onPart);
  649.                 $this->onPart[$getal]['cmd'] = $cmd;
  650.                 $this->onPart[$getal]['para'] = $para;
  651.                 $this->onPart[$getal]['nick'] = $nick;
  652.                 $this->onPart[$getal]['chan'] = $chan;
  653.             } else {
  654.                 $this->error("Parameters must be in array format!");
  655.             }
  656.         } else {
  657.             $this->error("Not callable function! :" . $cmd);
  658.         }
  659.     }
  660.  
  661.     function newOnUserMode ($mode, $cmd) {
  662.         if (is_callable(array('ZeroBot', $cmd))) {
  663.             $getal = count($this->onUserMode);
  664.             $this->onUserMode[$getal]['mode'] = $mode;
  665.             $this->onUserMode[$getal]['cmd'] = $cmd;
  666.         } else {
  667.             $this->error("Not callable function! :" . $cmd);
  668.         }
  669.     }
  670.  
  671.     function newOnNumeric ($numeric, $cmd) {
  672.         if (is_callable(array('ZeroBot', $cmd))) {
  673.             $getal = count($this->onNumeric);
  674.             $this->onNumeric[$getal]['numeric'] = $numeric;
  675.             $this->onNumeric[$getal]['cmd'] = $cmd;
  676.         } else {
  677.             $this->error("Not callable function! :" . $cmd);
  678.         }
  679.     }
  680. }
  681.  
  682. function in_array_i($search, &$array) {
  683.   $search = strtolower($search);
  684.   foreach ($array as $item)
  685.     if (strtolower($item) == $search)
  686.         return TRUE;
  687.   return FALSE;
  688. }
  689. ?>
  690.  
  691. //===================================================================
  692. //========================INDEX.PHP==================================
  693. //===================================================================
  694.  
  695. <?php
  696. include("class.php");
  697.  
  698. $bot = new ZeroBot;
  699.  
  700. $bot->setServer("irc.gtanet.com");
  701. $bot->setName("Norbot36", "AKAZAR");
  702. $bot->setChannel("#norek.test");
  703. $bot->setAdmin("[TNC]Norek");
  704.  
  705. // newOnText( String trigger, String Functie, Int required parameters [, Array parameter]);
  706. $bot->newOnText('!say', 'msg', 1, Array("*chan", "*1-"));
  707. $bot->newOnText('!msg', 'msg', 1, Array("*1", "*2-"));
  708.  
  709. $bot->newOnText('!ops', 'op', 1, Array("*chan", "*1"));
  710. $bot->newOnText('!ops', 'op', 0, Array("*chan", "*nick"));
  711.  
  712. $bot->newOnText('!join', 'join', 2, Array("*1", "*2"));
  713. $bot->newOnText('!join', 'join', 1, Array("*1"));
  714.  
  715. $bot->newOnText('!part', 'part', 1, Array("*1-"));
  716. $bot->newOnText('!part', 'part', 0, Array("*chan"));
  717.  
  718. $bot->newOnText('!quit', 'quit', 1, Array("*1-"));
  719. $bot->newOnText('!quit', 'quit', 0, Array("Quitting..."));
  720.  
  721. $bot->newOnText('!name', 'changeName', 1, Array("*1"));
  722.  
  723. // newOnText( String trigger, String functie, int required parameters [, Array parameters]);
  724. $bot->newOnCtcp('version', 'ctcp', 0, Array("*nick", "( :: ZeroBot :: ) [v*version] ( :: by DaeDaluz :: )"));
  725. $bot->newOnCtcp('time', 'ctcp', 0, Array("*nick", "*fulltime"));
  726. $bot->newOnCtcp('finger', 'ctcp', 0, Array("*nick", "Nice ^^"));
  727.  
  728. // newOnUserMode(string usermode, string functie);
  729. $bot->newOnUserMode('+xviw', 'perform');
  730.  
  731. // newOnNumerc(string numeric, string functie);
  732. $bot->newOnNumeric('352', 'storeUsers');
  733.  
  734. // newOnJoin('String functie, Array parameters [, String on who ] [, String channel]);
  735. $bot->newOnJoin('send', Array('who *chan'), '*me');
  736.  
  737. // newOnPart('String functie, Array parameters [, String on who ] [, String channel]);
  738.  
  739. $bot->connect();
  740.  
  741. while ($bot->connected()) {
  742.     if ($bot->newData()) {
  743.         $bot->printData();
  744.         $bot->events();
  745.     }
  746.     usleep(100);
  747. }
  748. ?>

Paste Details

Tags: php irc bot

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
fantasy-obligation