Gå til innhold

Hvordan kjøre en phpbot i linux ?


Anbefalte innlegg

Hvordan kan jeg kjøre denne koden her i linux, på irc?

 

#!/usr/bin/php -q
<?php
/*
* Copyright (C) 2003/2004 AliTriX - [email protected] - http://alitrix.nefast.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/*
  REQUIRED:
  Hm.. there isn't a lot required, you need ofcourse PHP atleast, this one is tested on version 4.x,
  I think version 3.x works as well.
  I tested this script on u2.10.11.04+asuka(1.0.4)
*/

/* ABOUT THIS SCRIPT:
  This is a script made by AliTriX and it's a "clone" of the orginial fishbot from Quakenet.
  I didn't see the script of the real fishbot, so I don't know if my bot works the same as the original one
  and if my commands are the same. I just tested the real fishbot and tryed to make a script that looks like
  it. If you found bugs or got any idea's, your e-mail is welcome to [email protected]
*/

/* COMMANDS:
  There are no special commands, just check http://www.fishbot.net, click on the left menu on "Commands", that
  are the actions/msgs that the bot react on.
  
  IRCOP COMMANDS:
  /msg <botname> showcommands (and you get a simpel list)
*/

/*
  CHANGES:
  Check the file ChangeLog for more info!

  TODO:
  - Try to translate this script into C, if I ever learn it;)
  - Got more idea's?
*/


class FishBot {
var $ServiceName,$ServiceDesc,$ServiceNum,$BotNum;
var $BotNick,$BotUser,$BotModes,$BotHost,$ServerHost;
var $ServerPass,$DeBug,$Socket,$ChannelsFile,$Counter;
var $PingPongs, $Opers, $EB;
var $Chans = array();
var $Nicks = array();
var $Channels = array();

/******** CONFIGURATION - BEGIN  ********/
function FishBot() {
 /* Configuring the bot */
 $this->ServiceName = "fishbot"; /* Name of the bot */
 $this->ServiceDesc = "Teh f1shb0t <°)))))><"; /* The IRC Name and Discription */
 $this->ServiceNum = "AX"; /* Bot numeric */
 $this->BotNum = $this->ServiceNum . "AAA"; /*!! Don't change this one !!*/
 $this->BotNick = "fishbot"; /* Nickname of the bot */
 $this->BotUser = "fish"; /* The ident/username */
 $this->BotModes = "+iw"; /* Bot modes */
 $this->BotHost = "go.moo.oh.yes.they.do"; /* Hidden host, bot host */
 $this->ServerHost = "10.0.0.4"; /* IP/Host to connect to */
 $this->ServerPort = 6667; /* Port to connect to */
 $this->ServerPass = "fish"; /* Password to use for the connection between the service and server */
 $this->DeBug = TRUE; /* TRUE = on, FALSE = off */
 /* TIP: If you put DeBug TRUE, and you are starting the script like this: ./fishbot.php &, then it's
    better to start the robot like this: ./fishbot.php >/dev/null 2>/dev/null &, cause when he is gonna
    send a message to the terminal and it's closed, then the bot will get killed, cause there isn't a terminal
    to send anything to it. (except if you use the /dev/null or a file)*/
 
 $this->ChannelsFile = "database/channels"; /* The file where the channels should be stored, !REMEMBER! If you choose
          a directory, please make the directory FIRST then start the bot. */
 $this->PingPongs = 3; /* After how many ping-pongs should he save the channels into a file? */
 
 
 $this->EB = FALSE; /* Please don't change this */
}
/******** CONFIGURATION - END  ********/
/* DON'T CHANGE THE LINES BELOW, IF YOU DON'T KNOW WHAT YOU ARE DOING */

function LoadChannels() {
 /* Load the channels from the file */
 if (file_exists($this->ChannelsFile)) {
 	$Source = file($this->ChannelsFile);
 	foreach ($Source as $Line) {
   $Line = trim($Line);
   if (!empty($Line)) $this->Chans[] = $Line;
 	}
 }
 if ($this->DeBug) {
 	printf("Channels loaded.\n");
 	@ob_flush();
 }
}

function SaveChannels() {
 /* Save channels into the database file */
 if (!file_exists($this->ChannelsFile)) {
 	exec('touch '.$this->ChannelsFile);
 	printf("Had problems..!\n");
 	@ob_flush();
 }
 
 $handle = fopen($this->ChannelsFile,'w+');
 foreach($this->Chans as $number => $chan) {
 	@$content .= sprintf("%s\r\n",trim($chan));
 }
 if (!empty($content))
 	fwrite($handle,$content);
 fclose($handle);
 if ($this->DeBug) {
 	printf("Channels saved.\n");
 	@ob_flush();
 }
}

function StartBot() {
 /* Yup, how about begin with the real work, THE BOT! */
 printf("PID: %s\n",posix_getpid());
 $this->Socket = @fsockopen($this->ServerHost,$this->ServerPort,$ErrNr,$ErrStr);
 if (!$this->Socket) {
 	$tmp = sprintf("\n\nProblems with connecting to %s:%s\nErrorNr.: %s\nErrStr.: %s\n\n",$this->ServerHost,$this->ServerPort,$ErrNr,$ErrStr);
 	die ($tmp);
 }
 
 $Time = time();
 $tmp = sprintf('PASS :%s',$this->ServerPass);
 $this->SendRaw($tmp,1);
 $tmp = sprintf('SERVER %s 1 %s %s J10 %s]]] :%s',$this->BotHost,$Time,$Time,$this->ServiceNum,$this->ServiceDesc);
 $this->SendRaw($tmp,1);
 $tmp = sprintf('%s N %s 1 %s %s %s %s B]AAAB %s :%s',$this->ServiceNum,$this->BotNick,$Time,$this->BotUser,$this->BotHost,$this->BotModes,$this->BotNum,$this->ServiceDesc);
 $this->SendRaw($tmp,1);
 $tmp = sprintf('%s EB',$this->ServiceNum);
 $this->SendRaw($tmp,1);
 $this->Counter =0;
 
 if ($this->DeBug) {
 	printf("Bot sended his own information to the server, waiting for respond.\n");
 	@ob_flush();
 }
 
 $this->Idle();
}

function Idle() {
 /* Checking the incoming information */
 while (!feof($this->Socket)) {
 	$this->Get = fgets($this->Socket,256);
 	if (!empty($this->Get)) {
   $Args = explode(" ",$this->Get);
   $Cmd = trim($Args[1]);
   switch ($Cmd) {
   	case "EB": /* End of Burst */
     $this->EA();
     break;
   	case "G": /* Ping .. Pong :) */
     $this->Pong($Args);
     break;
   	case "I": /* Somebody invited us, nice of him :D */
     $this->JoinChan($Args);
     break;
   	case "P": /* They are talking to me */
     $this->PrivMsg($Args,$this->Get);
     break;
   	case "N": /* We got a nick-change or a nick-burst msg */
     $this->SaveNicks($Args);
     break;
   	case "K": /* Somebody kicked me? */
     $this->PartChan($Args);
     break;
   	case "M": /* A oper logged in? */
     $this->AddOper($Args);
     break;
   	case "Q": /* They quit as well, finally! :P */
     $this->DelUser($Args);
     break;
   	case "B": /* We received a burst line */
     $this->Burst($Args);
     break;
   	case "J": /* Somebody joined a channel */
     $this->AddChan($Args);
     break;
   	case "C": /* Somebody joined a channel */
     $this->AddChan($Args);
     break;
   	case "L": /* If somebody parts a channel, we have to notice that */
     $this->DelChan($Args);
     break;
   }
 	}
 }
}

function EA() {
 /* End of Burst received */
 /* [get] AB EB */
 if (empty($this->EB)) {
 	$tmp = sprintf('%s EA',$this->ServiceNum);
 	$this->SendRaw($tmp,1);
 	$this->EB = TRUE;
 	$this->JoinChannels();
 }
}

function JoinChannels() {
 /* Join the channels after receiving a EA from the server */
 foreach($this->Chans as $number => $chan) {
 	$tmp = sprintf('%s J %s',$this->BotNum,$chan);
 	$this->SendRaw($tmp,1);
 	$this->CheckEmptyChan($chan);
 }
 if ($this->DeBug) {
 	printf("Server accepted us.\n");
 	printf("Joining all channels.\n");
 	@ob_flush();
 }
}

function Pong($Args) {
 /* The server pinged us, we have to pong him back */
 /* [get] AB G !1061145822.928732 fish.go.moh.yes 1061145822.928732 */
 $this->Counter++;
 if ($this->Counter >= $this->PingPongs) {
 	$this->SaveChannels();
 	$this->Counter=0; /* Putting it on zer0, for a new save/count */
 }
 $tmp = sprintf('%s Z %s',$this->BotNum,$Args[2]);
 $this->SendRaw($tmp,0);
 if ($this->DeBug) {
 	printf("Ping Pong?!\n");
 	@ob_flush();
 }
}

function SendRaw($Line,$Show) {
 /* This sends information to the server */
 /*if ($this->DeBug && $Show) {
 	printf("[send]: %s\n",$Line);
 	@ob_flush();
 }*/
 fputs($this->Socket,$Line."\r\n");
}

function SendMsg($To,$Msg) {
 /* Sending a msg */
 $tmp = sprintf('%s P %s :%s',$this->BotNum,$To,$Msg);
 $this->SendRaw($tmp,0);
}

function JoinChan($Args) {
 /* Join the channel if the bot is getting invited */
 /* [get] ABAAG I fishbot :#chan.to.join */
 $Sender = $Args[0];
 $Victum = $Args[2];
 if (strtolower($Victum) == strtolower($this->BotNick)) {
 	$Target = trim(substr($Args[3],1)); /* #chan.to.join */
 	$tmp = sprintf('%s J %s',$this->BotNum,$Target);
 	$this->SendRaw($tmp,1);
 	$this->Chans[] = $Target;
 }
}

function PartChan($Args) {
 /* When somebody kicks us from his chan, then he doesn't need us. */
 /* [get] ABAAA K #coder-com ADAAA :AliTriX */
 
 $Victum = trim($Args[3]);
 if ($Victum == $this->BotNum) {
 	$Chan = trim($Args[2]);
 	$key = array_search($Chan,$this->Chans);
 	unset($this->Chans[$key]);
 }
}

function AddOper($Args) {
 /* When we receive a MODE, we have to check if a person is authing himself as
    a oper, so we can tell the arrays that. */
 /* [get] ABAAC M AliTriX +iw */
 $Numeric = trim($Args[0]);
 $Target = trim($Args[2]);
 if (substr($Target,0,1) != "#") { /* Only user-modes are interested */
 	$Modes = trim($Args[3]);
 	$Count = strlen($Modes);
 	$Status = false;
 	for($i=0;$i<$Count;$i++) {
   if ($Modes[$i] == "+") 
   	$Status = "+";
   elseif ($Modes[$i] == "-")
   	$Status = "-";
   else {
   	if (!empty($Status)) {
     if ($Modes[$i] == "o" && $Status == "+")
     	$this->Opers[$Numeric] = true;
     if ($Modes[$i] == "o" && $Status == "-")
     	unset($this->Opers[$Numeric]);
   	}
   }
   
 	}
 }
}

function DelUser($Args) {
 /* When a user quites, we have to notice our arrays about that. */
 /* [get] ABAAC Q :Quit: leaving */
 $Numeric = trim($Args[0]);
 unset($this->Nicks[$Numeric],$this->Opers[$Numeric]);
 foreach($this->Channels as $chan => $sub_array) {
 	foreach ($sub_array as $num => $x)
   if ($Numeric == $num) {
   	unset($this->Channels[$chan][$num]);
   	$this->CheckEmptyChan($chan);
   }
 }
}

function PrivMsg($Args,$Line) {
 /* Somebody msg'ed something to me or to a channel */
 /* [get] ABAAG P #blaat :Joh, wzp?	<-- Chan-msg
    [get] ABAAG P ADAAA :Joh, wzp?	<-- Priv-msg
 */
 $Sender = trim($Args[0]);
 $Target = trim($Args[2]);
 $Msg = explode(":",$Line,2);
 $Msg = strtolower(trim($Msg[1]));
 if ($Target != $this->BotNum) {
 	/* Chan-msg */
 	if (preg_match('/hampster/',$Msg)) {
   $tmp = sprintf('%s: There is no \'p\' in hamster you retard.',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'ag') {
   $tmp = sprintf('Ag, ag ag ag ag ag AG AG AG!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'fishbot owns') {
   $tmp = sprintf('Aye, I do.');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/vinegar/',$Msg)) {
   $tmp = sprintf('Nope, too sober for vinegar.  Try later.');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/martian/',$Msg)) {
   $tmp = sprintf('Don\'t run! We are your friends!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'just then, he fell into the sea') {
   $tmp = sprintf('Ooops!');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/aftershock/',$Msg)) {
   $tmp = sprintf('mmmm, Aftershock.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'why are you here?') {
   $tmp = sprintf('Same reason.  I love candy.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'spoon') {
   $tmp = sprintf('There is no spoon.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'bounce' || $Msg == 'wertle') {
   $tmp = sprintf('moo');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'crack') {
   $tmp = sprintf('Doh, there goes another bench!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'you can\'t just pick people at random!') {
   $tmp = sprintf('I can do anything I like, %s, I\'m eccentric!  Rrarrrrrgh!  Go!',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'flibble') {
   $tmp = sprintf('plob');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match("/the fishbot has created splidge/",$Msg) || preg_match("/fishbot created splidge/",$Msg)) {
   $tmp = sprintf('omg no! Think I could show my face around here if I was responsible for THAT?');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'now there\'s more than one of them?') {
   $tmp = sprintf('A lot more.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'i want everything') {
   $tmp = sprintf('Would that include a bullet from this gun?');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/we are getting aggravated/',$Msg)) {
   $tmp = sprintf('Yes, we are.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'how old are you, fishbot?') {
   $tmp = sprintf("\001ACTION is older than time itself.\001");
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match("/^(\W{1})ACTION strokes fishbot(\W{1})$/i",$Msg)) {
   $tmp = sprintf("\001ACTION m00s loudly at %s.\001",$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'atlantis') {
   $tmp = sprintf('Beware the underwater headquarters of the trout and their bass henchmen. From there they plan their attacks on other continents.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'oh god') {
   $tmp = sprintf('fishbot will suffice.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'fishbot') {
   $tmp = sprintf('Yes?');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'what is the matrix?') {
   $tmp = sprintf('No-one can be told what the matrix is.  You have to see it for yourself.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'what do you need?') {
   $tmp = sprintf(' Guns.  Lots of guns.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'i know kungfu') {
   $tmp = sprintf('Show me.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'cake') {
   $tmp = sprintf('fish');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'trout go moo') {
   $tmp = sprintf('Aye, that\'s cos they\'re fish.');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg  == 'kangaroo') {
   $tmp = sprintf('The kangaroo is a four winged stinging insect.');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match("/^(\W{1})ACTION slaps (.*) around a bit with a large trout(\W{1})$/i",$Msg)) {
   $tmp = sprintf(' trouted!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg  == 'sea bass') {
   $tmp = sprintf('Beware of the mutant sea bass and their laser cannons!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg  == 'trout') {
   $tmp = sprintf('Trout are freshwater fish and have underwater weapons.');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match("/has returned from playing counterstrike/i",$Msg)) {
   $tmp = sprintf('like we care fs :(');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg  == 'where are we?') {
   $tmp = sprintf('Last time I looked, we were in %s.',$Target);
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'where do you want to go today?') {
   $tmp = sprintf('anywhere but redmond :(.',$Target);
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'fish go moo' || $Msg == 'fish go m00') {
   $tmp = sprintf("\001ACTION notes that %s is truly enlightened.\001",$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/^(.*) go moo$/i',$Msg)) {
   $tmp = sprintf('%s: only when they are impersonating fish.',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/^fish go ([a-z0-9 _]+)$/i',$Msg,$x)) {
   $tmp = sprintf('%s LIES! Fish don\'t go %s! fish go m00!',$this->Num2Nick($Sender),$x[1]);
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/^you know who else (.*)$/i',$Msg)) {
   $tmp = sprintf('%s: YA MUM!',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/^(\W{1})ACTION thinks happy thoughts about pretty (.*)(\W{1})$/i',$Msg,$x)) {
   $x = str_replace(chr(1),'',$x);
   $tmp = sprintf("\001ACTION has plenty of pretty %s. Would you like one %s?\001",$x[2],$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match("/^(\W{1})ACTION snaffles a (.*) off fishbot.(\W{1})$/i",$Msg)) {
   $tmp = sprintf(':(');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'if there\'s one thing i know for sure, it\'s that fish don\'t m00.') {
   $tmp = sprintf('%s: HERETIC! UNBELIEVER!',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'fishbot: muahahaha. ph33r the dark side. :)') {
   $tmp = sprintf('%s: You smell :P.',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'ammuu?') {
   $tmp = sprintf('%s: fish go m00 oh yes they do!',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'fish') {
   $tmp = sprintf('%s: fish go m00!',$this->Num2Nick($Sender));
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'snake') {
   $tmp = sprintf('Ah snake a snake! Snake, a snake! Ooooh, it\'s a snake!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'carrots handbags cheese') {
   $tmp = sprintf('toilets russians planets hamsters weddings poets stalin KUALA LUMPUR! pygmies budgies KUALA LUMPUR!');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/sledgehammer/',$Msg)) {
   $tmp = sprintf('sledgehammers go quack!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'badger badger badger badger badger badger badger badger badger badger badger badger') {
   $tmp = sprintf('mushroom mushroom!');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'moo?') {
   $tmp = sprintf('To moo, or not to moo, that is the question. Whether \'tis nobler in the mind to suffer the slings and arrows of outrageous fish...');
   $this->SendMsg($Target,$tmp);
 	} elseif ($Msg == 'herring') {
   $tmp = sprintf('herring(n): Useful device for chopping down tall trees. Also moos (see fish).');
   $this->SendMsg($Target,$tmp);
 	} elseif (preg_match('/www.outwar.com/',$Msg)) {
   $tmp = sprintf('would you please GO AWAY with that outwar rubbish!');
   $this->SendMsg($Target,$tmp);
 	}
 } else {
 	/* Priv-msg, works only for ircops */
 	if (!empty($this->Opers[$Sender])) {
   $Parts = explode(" ",$Msg);
   $Cmd = strtolower(trim($Parts[0]));
   switch ($Cmd) {
   	case "part":
     @$Chan = trim($Parts[1]);
     if (empty($Chan)) {
     	$tmp = sprintf('You forgot to type the channelname.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s part <#chan>',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } else {
     	$tmp = array("0","0",$Chan,$this->BotNum,":0");
     	$this->PartChan($tmp);
     	$tmp = sprintf('%s L %s',$this->BotNum,$Chan);
     	$this->SendRaw($tmp,1);
     	$tmp = sprintf('Channel removed from database.');
     	$this->SendMsg($Sender,$tmp);
     }
     break;
   	case "join":
     @$Chan = trim($Parts[1]);
     if (empty($Chan)) {
     	$tmp = sprintf('You forgot to type the channelname.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s join <#chan>',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } else {
     	$tmp = array("0","0",$this->BotNick,":".$Chan);
     	$this->JoinChan($tmp);
     	$tmp = sprintf('Channel added into the database.');
     	$this->SendMsg($Sender,$tmp);
     }
     break;
   	case "say":
     @$Target = trim($Parts[1]);
     @$Msg= trim($Parts[2]);
     if (empty($Target)) {
     	$tmp = sprintf('You forgot the channelname.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s say <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } elseif (empty($Msg)) {
     	$tmp = sprintf('You forgot to type the msg.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s say <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } elseif (substr($Msg,0,1) != ":") {
     	$tmp = sprintf('Forgot the ":". You have to use :<msg>');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s say <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } else {
     	if (substr($Target,0,1) != "#") {
       $tmp = sprintf('No nicks supported at this moment :S. Only channels.');
       $this->SendMsg($Sender,$tmp);
       $tmp = sprintf('/msg %s say <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     	} else {
       $Message = explode(":",$Line,3);
       $this->SendMsg($Target,$Message[2]);
     	}
     }
     break;
   	case "action":
     @$Target = trim($Parts[1]);
     @$Msg= trim($Parts[2]);
     if (empty($Target)) {
     	$tmp = sprintf('You forgot the channelname.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s action <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } elseif (empty($Msg)) {
     	$tmp = sprintf('You forgot to type the msg.');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s action <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } elseif (substr($Msg,0,1) != ":") {
     	$tmp = sprintf('Forgot the ":". You have to use :<msg>');
     	$this->SendMsg($Sender,$tmp);
     	$tmp = sprintf('/msg %s action <#chan> :Your message',$this->BotNick);
     	$this->SendMsg($Sender,$tmp);
     } else {
     	if (substr($Target,0,1) != "#") {
       $tmp = sprintf('No nicks supported at this moment :S. Only channels.');
       $this->SendMsg($Sender,$tmp);
       $tmp = sprintf('/msg %s say <#chan> :Your message',$this->BotNick);
       $this->SendMsg($Sender,$tmp);
     	} else {
       $Message = explode(":",$Line,3);
       $Send  = sprintf("\001ACTION %s\001",$Message[2]);
       $this->SendMsg($Target,$Send);
     	}
     }
     break;
   	case "save":
     $this->SaveChannels();
     $tmp = sprintf('Channels saved.');
     $this->SendMsg($Sender,$tmp);
     break;
   	case "die":
     $this->SaveChannels();
     $tmp = sprintf('Channels saved....');
     $this->SendMsg($Sender,$tmp);
     $tmp = sprintf('Gonna close connection...');
     if ($this->DeBug) {
     	printf("Bot is gonna quit, they told me that on the server.\n");
     	@ob_flush();
     }
     $this->SendMsg($Sender,$tmp);
     $tmp = sprintf('%s SQ %s %s :They told me to quit.. hm.. bad people',$this->ServiceNum,$this->BotHost,time());
     $this->SendRaw($tmp,1);
     if ($this->DeBug) {
     	printf("Quited.\n");
     	@ob_flush();
     }
     exit;
     break;
   	case "showchans":
     $this->SendMsg($Sender,sprintf('Channels this bot is on (No list? No channel joined!)'));
     foreach($this->Chans as $index => $chan) {
     	$this->SendMsg($Sender,sprintf('%s',$chan));
     }
     break;
   	case "showcommands":
     $this->SendMsg($Sender,sprintf('join - Joins the specified channel.'));
     $this->SendMsg($Sender,sprintf('part - Parts the specified channel.'));
     $this->SendMsg($Sender,sprintf('say - Sends a msg to the target you give.'));
     $this->SendMsg($Sender,sprintf('action - Makes a action on the target you give.'));
     $this->SendMsg($Sender,sprintf('showchans - Shows the channels the bot is currently on.'));
     $this->SendMsg($Sender,sprintf('save - Will save all the channels from his array into a file.'));
     $this->SendMsg($Sender,sprintf('die - Kills the connection of the bot.'));
     break;
   	case "help":
     @$Topic = trim($Parts[1]);
     if (empty($Topic)) {
     	$this->SendMsg($Sender,sprintf('No target given. /msg %s help <topic>',$this->BotNick));
     	$this->SendMsg($Sender,sprintf('All the topics: /msg %s showcommands',$this->BotNick));
     	break;
     } else {
     	switch($Topic) {
       case "join":
       	$this->SendMsg($Sender,sprintf("\002-Join command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s join <chan>',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('This command joins the bot into the given channel.'));
       	$this->SendMsg($Sender,sprintf('Example: /msg %s join #coder-com',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('The bot will join #coder-com then.'));
       	break;
       case "part":
       	$this->SendMsg($Sender,sprintf("\002-Part command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s part <chan>',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('This command parts the bot from the given channel.'));
       	$this->SendMsg($Sender,sprintf('Example: /msg %s part #coder-com',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('The bot will part #coder-com then.'));
       	break;
       case "say":
       	$this->SendMsg($Sender,sprintf("\002-Say command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s say <chan> :<text>',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('With this command you can let the bot talk.'));
       	$this->SendMsg($Sender,sprintf('Example: /msg %s say #coder-com :i love you all',$this->BotNick));
       	break;
       case "action":
       	$this->SendMsg($Sender,sprintf("\002-Action command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s action <chan> :<text>',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('With this command you can let the bot act in a channel.'));
       	$this->SendMsg($Sender,sprintf('Example: /msg %s action #coder-com :pokes everybody',$this->BotNick));
       	break;
       case "save":
       	$this->SendMsg($Sender,sprintf("\002-Save command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s save',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('This command saves the whole channel list into the database.'));
       	break;
       case "die":
       	$this->SendMsg($Sender,sprintf("\002-Die command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s die',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('This command kills the connection of the bot.'));
       	$this->SendMsg($Sender,sprintf('Remember, the script saves the channel list and then kills the bot.'));
       	break;
       case "showchans":
       	$this->SendMsg($Sender,sprintf("\002-Showchans command-\002"));
       	$this->SendMsg($Sender,sprintf('Syntax: /msg %s showchans',$this->BotNick));
       	$this->SendMsg($Sender,sprintf('Shows all the channels the bot is on.'));
       	break;
       default:
       	$this->SendMsg($Sender,sprintf('No help found for the given topic.'));
       	break;
     	}
     	break;
     }
   	default:
     $this->SendMsg($Sender,sprintf('Unkown command. /msg %s showcommands',$this->BotNick));
     break;
   }
 	}
 }
}

function Burst($Args) {
 /* When we receive a burst message, we have to know how many users are in the chan
    so we can build a function, when the channel is empty, the bot should part.
 */
 /* [get] AB B #coder-com 1064938432 ABAAA:o 
    [get] AB B #coder-com 1064938432 +lk 15 test ABAAA:o */
 $Chan = trim(strtolower($Args[2]));
 if (preg_match("/\+/",$Args[4])) {
 	if (preg_match("/kl/",$Args[4]) || preg_match("/lk/",$Args[4]))
   $Users = $Args[7];
 	elseif (preg_match("/l/",$Args[4]) || preg_match("/k/",$Args[4]))
   $Users = $Args[6];
 } else
 	$Users = $Args[4];
 $Temp = explode(",",$Users);
 foreach ($Temp as $Index => $Num) {
 	$Num = str_replace(":ov","",$Num);
 	$Num = str_replace(":o","",$Num);
 	$Num = str_replace(":v","",$Num);
 	$Num = trim($Num);
 	$this->Channels[$Chan][$Num] = TRUE;
 }
}

function AddChan($Args) {
 /* Somebody joined a channel, we have to put that in a array */
 /* [get] ABAAC J #coder-com 1064938432
    [get] ABAAC C #coder-com 1064938432 */
 $Chan = trim(strtolower($Args[2]));
 $Num = trim($Args[0]);
 $this->Channels[$Chan][$Num] = TRUE;
}

function DelChan($Args) {
 /* Somebody parted a channel, we have to remove him from the array */
 /* [get] ABAAD L #test */
 $Chan = trim(strtolower($Args[2]));
 $Num = trim($Args[0]);
 unset($this->Channels[$Chan][$Num]);
 $this->CheckEmptyChan($Chan);
 @ob_flush();
}

function CheckEmptyChan($Chan) {
 /* This function checks if a channel is empty, if yes.. the bot should part */
 if (@count($this->Channels[$Chan])==0) {
 	unset($this->Channels[$Chan]);
 	$this->PartChan(array("0","0",$Chan,$this->BotNum,":0"));
 	$this->SendRaw(sprintf('%s L %s',$this->BotNum,$Chan),1);
 }
}

function SaveNicks($Args) {
 /* Somebody changed his nick or a server is telling us his users */
 /* [get] AP N Q 2 100 TheQBot Q.AliTriX.nl +oiwdk B]AAAB APAAA :The Q Bot
    [get] AB N AliTriX 1 1061147585 wer alitrix.homelinux.net +oiwg B]AAAB ABAAG :Ali
    [get] ABAAG N test 1061154478 */
 $Nick = $Args[2];
 $Oper = false;
 
 if (count($Args) == 4) { /* Nick change */
 	$Numeric = $Args[3];
 	$Nick = $Args[2];
 	$this->Nicks[$Numeric] = $Nick;
 	return 0;
 	
 }
 
 $Modes = $Args[7];
 if (preg_match("/\+/i",$Modes)) {
 	/* Setting the numeric */
 	if (preg_match("/r/",$Args[7]) && preg_match("/h/",$Args[7])) {
   $Numeric = $Args[11];
 	} elseif (preg_match("/r/",$Args[7]) || preg_match("/h/",$Args[7])) {
   $Numeric = $Args[10];
 	} else {
   $Numeric = $Args[9];
 	}
 	
 	if (preg_match("/o/",$Args[7])) {
   $Oper = true;
 	}
 } else {
 	$Numeric = $Args[8];
 }
 
 $this->Nicks[$Numeric] = $Nick;
 $this->Opers[$Numeric] = $Oper;
}

function Num2Nick($Numeric) {
 /* Changing a numeric into a nick */
 if (!empty($this->Nicks[$Numeric]))
 	return $this->Nicks[$Numeric];
 else
 	return "N/A";
}
}

$FishY = new FishBot;
$FishY->LoadChannels();
$FishY->StartBot();
?>

Noen somvet hvordan jeg får den inn på irc?

Lenke til kommentar
Videoannonse
Annonse
Gjest Slettet-df17e

Konfigurer det som står under

/******** CONFIGURATION - BEGIN  ********/

 

chmod a+x phpbotfila <- Setter rettigheter på fila

 

./phpbotfila <- Starter den

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...