12
[irbot.git] / sources / irc-class.inc.php
blob0e2f89979f0d4b5998e066660c606b1f04e716f5
1 <?php
3 class irc {
5 protected $current_msg_info = false;
6 private $ircmain;
8 function __construct() {
9 $this->ircmain = main::GetInstance();
12 function parse_get($msg) {
13 // DECO
14 if (preg_match("`^ERROR :(Closing Link: )?(.*)\r?$`i", $this->msg))
16 @fclose($this->ircmain->C);
17 sleep(3);
18 throw new Exception('Closing Link.',1);
20 // PONG
21 elseif (preg_match("`^PING :(.*)\r?\n`", $this->msg, $T))
23 $this->ircmain->put('PONG '.$T[1]);
24 echo "PING :{$T[1]}\nPONG {$T[1]}\n\n";
26 // Bot kicked, thanks kicker !
27 elseif (preg_match('`^:(.*?)!.*?@.*? KICK '.main::$channel.' '.preg_quote(main::$myBotName, '`').' :`', $this->msg, $T))
29 sleep(1);
30 $this->ircmain->joinChannel(main::$channel);
31 $this->ircmain->privmsg(main::$channel,'Merci '.$T[1].' !');
33 // OK : 001
34 // Illegals characters in Nickname : 432
35 // Nick already in use : 433
36 elseif (preg_match('`^:[^ ]+ (001|432|433) (.*?)\r?\n`', $this->msg,$T))
38 switch ($T[1]) {
39 case 001:
40 $this->ircmain->joinChannel(main::$channel);
41 break;
43 case 432:
44 $this->ircmain->newNick('NoNameBot'.rand(0,9).rand(0,9));
45 break;
46 case 433:
47 echo "Nick already in use\n\n";
48 $this->ircmain->newNick(false);
49 default:
50 echo "Geeeh, I do not known what this mean ...\n";
51 echo "DEBUG :>".$this->msg;
52 break;
56 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.main::$myBotName.'|'.main::$channel.") :(.*)\r`",$msg,$T)) {
57 $msg_info = array (
58 'type' => 'PRIVMSG',
59 'from' => $T[1],
60 'to' => $T[2],
61 'message' => $T[3]
63 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.main::$myBotName." :(.*)\r`",$msg,$T)) {
64 $msg_info = array (
65 'type' => 'NOTICE',
66 'from' => $T[1],
67 'to' => main::$myBotName,
68 'message' => $T[2]
73 /**
74 * return last privmsg / notice
76 * @return array
78 public function get_msg_info() {
79 return $msg_info;