Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*Fun IRC Bot - Fun for the whole chatroom!*/
- /*Developed by Bi0sph3re*/
- set_time_limit(0); //This is here so the bot doesnt randomly exit the chat.
- class IRCBot { //Starting of the class
- var $owner = "Eggium"; //Owner of the bot
- var $server = "irc.penguinlodge.com"; //Server the bot will connect to.
- var $port = "6667"; //Port for the server
- var $channel = "#eggium"; //Channel on the server the bot will connect to.
- var $nick = "EggyBot"; //The nickname the bot will use.
- var $user = "EggyBot"; //USER
- var $password = "pooper123"; //Password if needed
- var $commandsEnabled = true; //If false, no one will be able to use the commands.
- var $startUpMessage = true; //If false, the bot wont send a message when it enters a channel.
- var $badWords = array("Fuck","Shit","Bitch");
- var $socket; //The socket the bot will use
- var $data; //Data read from the socket
- function run(){
- $this->setuser($this->server,$this->port);
- $this->join($this->channel);
- }
- function GetBetween($content,$start,$end){
- $r = explode($start, $content);
- if (isset($r[1])){
- $r = explode($end, $r[1]);
- return $r[0]; } return '';
- }
- function sendMessage($msg){
- $this->write = fwrite($this->socket, "PRIVMSG ".$this->channel." :".$msg."\n");
- if (!$this->write){
- die("Socket error");
- } elseif($this->write==true){
- echo "Sent Message\n";
- }
- }
- function setuser($server,$port){
- $this->socket = fsockopen($server,$port);
- if (!$this->socket){
- die("Socket error");
- } elseif($this->socket==true){
- echo "Socket succesfull\n";
- $this->send("USER ".$this->user." youtube.com ".$this->user." :EggyBot");
- $this->send("NICK ".$this->nick);
- }
- }
- function handleCommand(){
- while(1){
- while ($this->data = fgets($this->socket, 130)){
- echo nl2br($this->data);
- flush();
- $this->ping = explode(" ",$this->data);
- if ($this->ping[0]=="PING"){
- $this->send("PONG ".$this->ping[1]);
- }
- if (in_array($this->badWords, $this->data)){
- $this->sendMessage("No swearing!");
- }
- if ($this->commandsEnabled==true){
- if (strpos($this->data, "!say")){
- $this->msg = $this->GetBetween($this->data, "PRIVMSG ".$this->channel." :!say","<br />");
- $this->sendMessage($this->msg);
- }
- if (strpos($this->data, "!8ball")){
- $this->msg = $this->GetBetween($this->data, "PRIVMSG ".$this->channel." :!8ball","<br />");
- if ($this->msg===null){
- $this->sendMessage("Please ask a question");
- } else {
- $this->answers = array("Yes","No","Certainly","It's not certain.");
- $this->answer = array_rand($this->answers);
- $this->sendMessage($this->answers[$this->answer]);
- }
- }
- } else {
- if (strpos($this->data, "!say"||"!8ball")){
- $this->sendMessage("Commands are disabled by ".$this->owner);
- }
- }
- }
- }
- }
- function join($channel){
- $this->send("JOIN ".$this->channel);
- if ($this->startUpMessage=true){
- $this->send("PRIVMSG ".$this->channel." :Bot Online - I am an IRC Bot connected by ".$this->owner." and programmed by bi0sph3re");
- }
- $this->handleCommand();
- }
- function send($msg){
- $this->write = fwrite($this->socket, $msg."\0");
- if (!$this->write){
- die("Unable to write to socket");
- } elseif($this->write==true){
- echo "[FIB] Sent: ".$msg."\n";
- }
- }
- }
- $bot = new IRCBot();
- $bot->run();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement