Guest User

Untitled

a guest
Jun 25th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.63 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. set_time_limit(0); //This is here so the bot doesnt randomly exit the chat.
  5. class IRCBot { //Starting of the class
  6.     var $owner = "Sesh"; //Owner of the bot
  7.         var $server = "i.r.cx"; //Server the bot will connect to.
  8.         var $port = "6667"; //Port for the server
  9.         var $channel = "#bot"; //Channel on the server the bot will connect to.
  10.         var $nick = "iBot"; //The nickname the bot will use.
  11.         var $user = "Bot7777"; //USER
  12.         var $password = ""; //Password if needed
  13.         var $commandsEnabled = true; //If false, no one will be able to use the commands.
  14.         var $startUpMessage = true; //If false, the bot wont send a message when it enters a channel.
  15.         var $badWords = array("Fuck","Shit","Bitch");
  16.         var $socket; //The socket the bot will use
  17.         var $data; //Data read from the socket
  18.        
  19.         function run(){
  20.         $this->setuser($this->server,$this->port);
  21.         $this->join($this->channel);
  22.         }
  23.         function GetBetween($content,$start,$end){
  24.     $r = explode($start, $content);
  25.     if (isset($r[1])){
  26.     $r = explode($end, $r[1]);
  27.     return $r[0]; } return '';
  28.     }
  29.         function sendMessage($msg){
  30.     $this->write = fwrite($this->socket, "PRIVMSG ".$this->channel." :".$msg."\n");
  31.         if (!$this->write){
  32.         die("Socket error");
  33.         } elseif($this->write==true){
  34.         echo "Sent Message\n";
  35.         }
  36.     }
  37.         function setuser($server,$port){
  38.         $this->socket = fsockopen($server,$port);
  39.         if (!$this->socket){
  40.         die("Socket error");
  41.         } elseif($this->socket==true){
  42.         echo "Socket succesfull\n";
  43.         $this->send("USER ".$this->user." google.ca ".$this->user." :Iamanbot");
  44.         $this->send("NICK ".$this->nick);
  45.         }
  46.         }
  47.         function handleCommand(){
  48.         while(1){
  49.         while ($this->data = fgets($this->socket, 130)){
  50.         echo nl2br($this->data);
  51.     flush();
  52.         $this->ping = explode(" ",$this->data);
  53.         if ($this->ping[0]=="PING"){
  54.         $this->send("PONG ".$this->ping[1]);
  55.         }
  56.         if (in_array($this->badWords, $this->data)){
  57.         $this->sendMessage("No swearing!");
  58.         }
  59.         if ($this->commandsEnabled==true){
  60.     if (strpos($this->data, "!say")){
  61.     $this->msg = $this->GetBetween($this->data, "PRIVMSG ".$this->channel." :!say","<br />");
  62.     $this->sendMessage($this->msg);
  63.     }
  64.     if (strpos($this->data, "!8ball")){
  65.     $this->msg = $this->GetBetween($this->data, "PRIVMSG ".$this->channel." :!8ball","<br />");
  66.     if ($this->msg===null){
  67.     $this->sendMessage("Please ask a question");
  68.     } else {
  69.     $this->answers = array("Yes","No","Certainly","It's not certain.");
  70.     $this->answer = array_rand($this->answers);
  71.     $this->sendMessage($this->answers[$this->answer]);
  72.     }
  73.     }
  74.     } else {
  75.     if (strpos($this->data, "!say"||"!8ball")){
  76.     $this->sendMessage("Commands are disabled by ".$this->owner);
  77.     }
  78.     }
  79.         }
  80.         }
  81.         }
  82.         function join($channel){
  83.         $this->send("JOIN ".$this->channel);
  84.         if ($this->startUpMessage=true){
  85.     $this->send("PRIVMSG ".$this->channel." :Bot Online - I am an IRC Bot connected by ".$this->owner." and programmed by bi0sph3re");
  86.     }
  87.         $this->handleCommand();
  88.         }
  89.         function send($msg){
  90.         $this->write = fwrite($this->socket, $msg."\0");
  91.         if (!$this->write){
  92.         die("Unable to write to socket");
  93.         } elseif($this->write==true){
  94.         echo "[FIB] Sent: ".$msg."\n";
  95.         }
  96.         }
  97.         }
  98.         $bot = new IRCBot();
  99.         $bot->run();
  100.         ?>
Add Comment
Please, Sign In to add comment