16
[irbot.git] / sources / irc-class.inc.php
bloba3ac9243c9ed393af9d80af053e51f3cf6663a92
1 <?php
2 /**
3 * This file is part of IrBot, irc robot.
4 * Copyright (C) 2007 Bellière Ludovic
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 class irc {
22 protected $current_msg_info = false;
23 private $ircmain;
24 private $msg, $msg_info;
26 function __construct() {
27 $this->ircmain = bot::GetInstance();
30 function parse_get($msg) {
31 $this->msg = $msg;
32 // DECO
33 if (preg_match("`^ERROR :(Closing Link: )?(.*)\r?$`i", $this->msg))
35 @fclose($this->ircmain->C);
36 sleep(3);
37 throw new Exception('Closing Link.',1);
39 // PONG
40 elseif (preg_match("`^PING :(.*)\r?\n`", $this->msg, $T))
42 $this->ircmain->put('PONG '.$T[1]);
43 echo "PING :{$T[1]}\nPONG {$T[1]}\n\n";
45 // Bot kicked, thanks kicker !
46 elseif (preg_match('`^:(.*?)!.*?@.*? KICK '.bot::$channel.' '.preg_quote(bot::$myBotName, '`').' :`', $this->msg, $T))
48 sleep(1);
49 $this->ircmain->joinChannel(bot::$channel);
50 $this->ircmain->privmsg(bot::$channel,'Merci '.$T[1].' !');
52 // OK : 001
53 // Illegals characters in Nickname : 432
54 // Nick already in use : 433
55 elseif (preg_match('`^:[^ ]+ (001|432|433) (.*?)\r?\n`', $this->msg,$T))
57 switch ($T[1]) {
58 case 001:
59 $this->ircmain->joinChannel(bot::$channel);
60 break;
62 case 432:
63 $this->ircmain->newNick('NoNameBot'.rand(0,9).rand(0,9));
64 break;
65 case 433:
66 echo "Nick already in use\n\n";
67 $this->ircmain->newNick(false);
68 default:
69 echo "Geeeh, I do not known what this mean ...\n";
70 echo "DEBUG :>".$this->msg;
71 break;
75 // :<Owner:T1> PRIVMSG <recever:T2> :<msg:T3>
76 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.bot::$myBotName.'|'.bot::$channel.") :(.*)\r`",$this->msg,$T)) {
77 $this->msg_info = array (
78 'type' => 'PRIVMSG',
79 'from' => $T[1], // owner
80 'to' => $T[2], // message for bot or channel
81 'message' => $T[3]
83 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.bot::$myBotName." :(.*)\r`",$this->msg,$T)) {
84 $this->msg_info = array (
85 'type' => 'NOTICE',
86 'from' => $T[1],
87 'to' => bot::$myBotName,
88 'message' => $T[2]
93 /**
94 * return last privmsg / notice
96 * @return array
98 public function get_msg_info() {
99 $temp = $this->msg_info;
100 $this->msg_info = array('type'=>false);
101 return $temp;
105 * Return the current incoming line
107 * @return string
109 public function get_msg() {
110 return $this->msg;