1
[irbot.git] / sources / plug_base-class.inc.php
blob6b2f8bfcbf298673739f8e5afad37ebf20d28459
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->quit($IRCtext);
32 public function help() {
33 $msg[] = '!help : (cette aide)';
36 private function quit($IRCtext) {
37 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').' :(!quit)`',$IRCtext,$T)) {
38 echo 'Closing Link...'."\n";
39 $this->main->MyConn->disconnect();
40 sleep(5);
41 die(0);
45 private function doHelp($IRCtxt) {
46 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$channel, '`').'(.*?)(!help)`', $IRCtxt, $T)) {
47 $msg = '!help : (cette aide1)'."\n";
48 $this->main->MyConn->put('NOTICE '.$T[1].' '.$msg);
49 foreach($this->main->Plist as $key => $val) {
50 $msg = $this->main->Plist[$key]->help();
51 if(is_array($msg)) {
52 foreach($msg as $m) {
53 $this->main->MyConn->put('NOTICE '.$T[1].' '.$m."\n");
55 } else {
56 $this->main->MyConn->put('NOTICE '.$T[1].' '.$msg);
62 // DECO
63 private function Deco($IRCtext) {
64 if (preg_match("`^ERROR :(Closing Link: )?(.*)\r?$`i", $IRCtext)) {
65 @fclose($this->main->MyConn->C);
66 sleep(3);
67 die('Closing Link'."\n");
71 // OK
72 private function Ok($IRCtext) {
73 if (preg_match("`^:[^ ]+ 001 .*?\r?\n`", $IRCtext)) {
74 $this->main->MyConn->joinChannel(IRCConn::$channel);
78 // PONG
79 private function Pong($IRCtext) {
80 if (preg_match("`^PING :(.*)\r?\n`", $IRCtext, $T)) {
81 $this->main->MyConn->put('PONG '.$T[1]);
82 echo "PING : {$T[1]}\nPONG {$T[1]}\n\n";
86 // KICK
87 private function kick($IRCtext) {
88 if(preg_match('`^:(.*?)!.*?@.*? KICK '.IRCConn::$channel.' ([^ ]+)`', $IRCtext, $T)) {
89 if($T[2] == IRCConn::$myBotName) {
90 sleep(1);
91 $this->main->MyConn->joinChannel(IRCConn::$channel);
92 $this->main->MyConn->put('PRIVMSG '.IRCConn::$channel.' :Merci '.$T[1].' !');
97 // Illegals characters in Nickname
98 private function IllegalChNick ($IRCtext) {
99 if(preg_match('`^:[^ ]+ 432 (.*?)\r?\n`', $IRCtext)){
100 IRCConn::$myBotName = 'XboT';
101 $this->main->MyConn->put('NICK :'.IRCConn::$myBotName);
105 // Nick already in use
106 private function NickUsed($IRCtext) {
107 if(preg_match('`^:[^ ]+ 433 (.*?)\r?\n`', $IRCtext)){
108 echo "Nick already in use\n\n";
109 $this->main->MyConn->newNick();
110 $this->main->MyConn->put('NICK :'.IRCConn::$myBotName);
114 // CTCP
115 private function CTCP($IRCtext) {
116 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)(VERSION|USERINFO|CLIENTINFO)`', $IRCtext, $T)) {
117 $this->main->MyConn->put('NOTICE '.$T[1].' RPGBot version '.IRCConn::$botVersion.' - PHP '.phpversion().' -- par Tornald');
119 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)PING (.*?)\r?\n`', $IRCtext, $T)) {
120 $this->main->MyConn->put('NOTICE '.$T[1]." PING\1".time()."\1");
122 if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName,'`').'(.*?)(TIME)`', $IRCtext, $T)) {
123 $this->main->MyConn->put('NOTICE '.$T[1].' '.date('Y-m-d H:i:s'));