2
[irbot.git] / sources / plug_base-class.inc.php
blob784b3d7cf1b1d7bcab4172f1a95a7a883a0c3bbf
1 <?php
3 interface plugin {
6 public function __construct($main);
7 public function start($IRCtxt);
8 public function help();
12 class plug_base implements plugin {
14 private $main;
16 public function __construct($main) {
17 $this->main = $main;
20 public function start($IRCtext) {
21 $this->Deco($IRCtext);
22 $this->Ok($IRCtext);
23 $this->Pong($IRCtext);
24 $this->kick($IRCtext);
25 $this->NickUsed($IRCtext);
26 $this->IllegalChNick($IRCtext);
27 $this->CTCP($IRCtext);
28 $this->doHelp($IRCtext);
29 $this->nat_cmd($IRCtext);
30 /*$this->quit($IRCtext);
31 $this->restart($IRCtext);
32 $this->nick($IRCtext);*/
35 public function help() {
36 $msg[] = '!help : (cette aide)';
37 $msg[] = '!quit : déconection';
38 $msg[] = '!nick <nick>: change le pseudo';
41 private function nat_cmd($IRCtext) {
42 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').' :!([^\n]+)`',$IRCtext,$T)) {
43 switch ($T[2]) {
44 case 'quit':
45 echo 'Closing Link...'."\n";
46 $this->main->MyConn->disconnect();
47 die(0);
48 break;
49 case 'restart':
50 echo 'Restart...'."\n";
51 $this->main->MyConn->disconnect();
52 sleep(5);
53 die(1);
54 default:
55 if (strpos($T[2],' ')!==false) {
56 list ($command,$param) = explode(' ',$T[2]);
57 switch ($command) {
58 case 'nick':
59 $this->main->MyConn->newNick($param);
60 break;
62 default:
63 break;
66 break;
68 print_r($T);
72 private function quit($IRCtext) {
73 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').' :!quit$`',$IRCtext,$T)) {
74 echo 'Closing Link...'."\n";
75 $this->main->MyConn->disconnect();
76 die(0);
80 private function restart($IRCtext) {
81 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').' :!restart`',$IRCtext,$T)) {
82 echo 'Closing Link...'."\n";
83 $this->main->MyConn->disconnect();
84 sleep(5);
85 die(1);
89 private function nick($IRCtext) {
90 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').' :!nick (.*)\n$`',$IRCtext,$T)) {
91 $this->main->MyConn->newNick($T1);
95 private function doHelp($IRCtxt) {
96 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').'(.*?)(!help)`', $IRCtxt, $T)) {
97 $msg = '!help : (cette aide1)'."\n";
98 $this->main->MyConn->put('NOTICE '.$T[1].' '.$msg);
99 foreach($this->main->Plist as $key => $val) {
100 $msg = $this->main->Plist[$key]->help();
101 if (is_array($msg)) {
102 echo "[DEBUG] \$msg is an array:\n";
103 print_r($msg);
104 foreach($msg as $m) {
105 $this->main->MyConn->put('NOTICE '.$T[1].' '.$m."\n");
107 } else {
108 echo "[DEBUG] \$msg is not an array\n";
109 $this->main->MyConn->put('NOTICE '.$T[1].' '.$msg);
115 // DECO
116 private function Deco($IRCtext) {
117 if (preg_match("`^ERROR :(Closing Link: )?(.*)\r?$`i", $IRCtext)) {
118 @fclose($this->main->MyConn->C);
119 sleep(3);
120 die('Closing Link'."\n");
124 // OK
125 private function Ok($IRCtext) {
126 if (preg_match("`^:[^ ]+ 001 .*?\r?\n`", $IRCtext)) {
127 $this->main->MyConn->joinChannel(IRCConn::$channel);
131 // PONG
132 private function Pong($IRCtext) {
133 if (preg_match("`^PING :(.*)\r?\n`", $IRCtext, $T)) {
134 $this->main->MyConn->put('PONG '.$T[1]);
135 echo "PING : {$T[1]}\nPONG {$T[1]}\n\n";
139 // KICK
140 private function kick($IRCtext) {
141 if (preg_match('`^:(.*?)!.*?@.*? KICK '.IRCConn::$channel.' ([^ ]+)`', $IRCtext, $T)) {
142 if($T[2] == IRCConn::$myBotName) {
143 sleep(1);
144 $this->main->MyConn->joinChannel(IRCConn::$channel);
145 $this->main->MyConn->put('PRIVMSG '.IRCConn::$channel.' :Merci '.$T[1].' !');
150 // Illegals characters in Nickname
151 private function IllegalChNick ($IRCtext) {
152 if (preg_match('`^:[^ ]+ 432 (.*?)\r?\n`', $IRCtext)){
153 IRCConn::$myBotName = 'XboT';
154 $this->main->MyConn->put('NICK :'.IRCConn::$myBotName);
158 // Nick already in use
159 private function NickUsed($IRCtext) {
160 if (preg_match('`^:[^ ]+ 433 (.*?)\r?\n`', $IRCtext)){
161 echo "Nick already in use\n\n";
162 self::$myBotName .= '_';
163 $this->main->MyConn->newNick();
167 // CTCP
168 private function CTCP($IRCtext) {
169 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)(VERSION|USERINFO|CLIENTINFO)`', $IRCtext, $T)) {
170 $this->main->MyConn->put('NOTICE '.$T[1].' :RPGBot version '.IRCConn::$botVersion.' - PHP '.phpversion().' -- par Tornald');
172 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)PING (.*?)\r?\n`', $IRCtext, $T)) {
173 $this->main->MyConn->put('NOTICE '.$T[1]." :PING\1".time()."\1");
175 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName,'`').'(.*?)(TIME)`', $IRCtext, $T)) {
176 $this->main->MyConn->put('NOTICE '.$T[1].' :'.date('Y-m-d H:i:s'));