Advertisement
Guest User

Eggybot PHP

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