14
[irbot.git] / sources / irc-class.inc.php
blob11ad51b8219709012b2fb706cf02b1c676f54072
1 <?php
3 class irc {
5 protected $current_msg_info = false;
6 private $ircmain;
7 private $msg, $msg_info;
9 function __construct() {
10 $this->ircmain = bot::GetInstance();
13 function parse_get($msg) {
14 $this->msg = $msg;
15 // DECO
16 if (preg_match("`^ERROR :(Closing Link: )?(.*)\r?$`i", $this->msg))
18 @fclose($this->ircmain->C);
19 sleep(3);
20 throw new Exception('Closing Link.',1);
22 // PONG
23 elseif (preg_match("`^PING :(.*)\r?\n`", $this->msg, $T))
25 $this->ircmain->put('PONG '.$T[1]);
26 echo "PING :{$T[1]}\nPONG {$T[1]}\n\n";
28 // Bot kicked, thanks kicker !
29 elseif (preg_match('`^:(.*?)!.*?@.*? KICK '.bot::$channel.' '.preg_quote(bot::$myBotName, '`').' :`', $this->msg, $T))
31 sleep(1);
32 $this->ircmain->joinChannel(bot::$channel);
33 $this->ircmain->privmsg(bot::$channel,'Merci '.$T[1].' !');
35 // OK : 001
36 // Illegals characters in Nickname : 432
37 // Nick already in use : 433
38 elseif (preg_match('`^:[^ ]+ (001|432|433) (.*?)\r?\n`', $this->msg,$T))
40 switch ($T[1]) {
41 case 001:
42 $this->ircmain->joinChannel(bot::$channel);
43 break;
45 case 432:
46 $this->ircmain->newNick('NoNameBot'.rand(0,9).rand(0,9));
47 break;
48 case 433:
49 echo "Nick already in use\n\n";
50 $this->ircmain->newNick(false);
51 default:
52 echo "Geeeh, I do not known what this mean ...\n";
53 echo "DEBUG :>".$this->msg;
54 break;
58 // :<Owner:T1> PRIVMSG <recever:T2> :<msg:T3>
59 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.bot::$myBotName.'|'.bot::$channel.") :(.*)\r`",$this->msg,$T)) {
60 $this->msg_info = array (
61 'type' => 'PRIVMSG',
62 'from' => $T[1], // owner
63 'to' => $T[2], // message for bot or channel
64 'message' => $T[3]
66 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.bot::$myBotName." :(.*)\r`",$this->msg,$T)) {
67 $this->msg_info = array (
68 'type' => 'NOTICE',
69 'from' => $T[1],
70 'to' => bot::$myBotName,
71 'message' => $T[2]
76 /**
77 * return last privmsg / notice
79 * @return array
81 public function get_msg_info() {
82 $temp = $this->msg_info;
83 $this->msg_info = array('type'=>false);
84 return $temp;