13
[irbot.git] / sources / irc-class.inc.php
blobca0155fb150598bfdd2477a7d060a5d05464dc12
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 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.bot::$myBotName.'|'.bot::$channel.") :(.*)\r`",$this->msg,$T)) {
59 $this->msg_info = array (
60 'type' => 'PRIVMSG',
61 'from' => $T[1],
62 'to' => $T[2],
63 'message' => $T[3]
65 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.bot::$myBotName." :(.*)\r`",$this->msg,$T)) {
66 $this->msg_info = array (
67 'type' => 'NOTICE',
68 'from' => $T[1],
69 'to' => bot::$myBotName,
70 'message' => $T[2]
75 /**
76 * return last privmsg / notice
78 * @return array
80 public function get_msg_info() {
81 return $this->msg_info;