28
[irbot.git] / sources / irc-class.inc.php
blob6fe7705cb13c5692cd94a581c8fb5299cf073f98
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;
33 echo debug() ? "IRC:: -> ".$msg."\n" : '';
34 // DECO
35 if (preg_match("`^ERROR :(Closing Link: )?(.*)$`i", $this->msg))
37 $this->ircmain->disconnect('ERROR: Closing Link');
38 sleep(3);
39 throw new Exception('Closing Link.',1);
41 // PONG
42 elseif (ereg("^PING ", $this->msg)) {
43 $pong = split(':',$this->msg);
44 $this->ircmain->put('PONG '.$pong[1]);
45 echo "PING :{$pong[1]}\nPONG {$pong[1]}\n\n";
47 // Bot kicked, thanks kicker !
48 elseif (preg_match('`^:(.*?)!.*?@.*? KICK '.bot::$channel.' '.preg_quote(bot::$myBotName, '`').' :`', $this->msg, $T))
50 sleep(1);
51 $this->ircmain->joinChannel(bot::$channel);
52 $this->ircmain->privmsg(bot::$channel,'Merci '.$T[1].' !');
54 // OK : 001
55 // Illegals characters in Nickname : 432
56 // Nick already in use : 433
57 elseif (preg_match('`^:[^ ]+ (001|432|433) (.*?)`', $this->msg,$T))
59 switch ($T[1]) {
60 case 001:
61 $this->ircmain->joinChannel(bot::$channel);
62 break;
64 case 432:
65 $this->ircmain->newNick('NoNameBot'.rand(0,9).rand(0,9));
66 break;
67 case 433:
68 echo "Nick already in use\n\n";
69 $this->ircmain->newNick(false);
70 default:
71 echo "Geeeh, I do not known what this mean ...\n";
72 echo "DEBUG :>".$this->msg;
73 break;
77 // :<Owner:T1> PRIVMSG <recever:T2> :<msg:T3>
78 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.bot::$myBotName.'|'.bot::$channel.") :(.*)`",$this->msg,$T)) {
79 $this->msg_info = array (
80 'type' => 'PRIVMSG',
81 'from' => $T[1], // owner
82 'to' => $T[2], // message for bot or channel
83 'message' => $T[3]
85 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.bot::$myBotName." :(.*)`",$this->msg,$T)) {
86 $this->msg_info = array (
87 'type' => 'NOTICE',
88 'from' => $T[1],
89 'to' => bot::$myBotName,
90 'message' => $T[2]
95 /**
96 * return last privmsg / notice
98 * @return array
100 public function get_msg_info() {
101 $temp = $this->msg_info;
102 $this->msg_info = array('type'=>false);
103 return $temp;
107 * Return the current incoming line
109 * @return string
111 public function get_msg() {
112 return $this->msg;