f9b5b2679a841ab6e29f08c440e498bd5912c15b
[PHP-P10.git] / Bots / ModManager.class.php
1 <?php
2 /******************************* PHP-P10 v2 *****************************
3  * Copyright (C) 2011  Philipp Kreil (pk910)                            *
4  *                                                                      *
5  * This program is free software: you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation, either version 3 of the License, or    *
8  * (at your option) any later version.                                  *
9  *                                                                      * 
10  * This program is distributed in the hope that it will be useful,      *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
13  * GNU General Public License for more details.                         *
14  *                                                                      *
15  * You should have received a copy of the GNU General Public License    *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  *                                                                      *
18  ************************************************************************
19  * 
20  *  Bots/ModManager.class.php
21  *
22  * module manager bot...
23  *
24  */
25
26 class {$_NAME} extends Bot {
27         private $uplink;
28         private $modman;
29         
30         public function load($uplink, $old = false) {
31                 $this->uplink = $uplink;
32                 if(!$old) {
33                         $nick = "ModuleMan";
34                         $ident = "modman";
35                         $host = "Services.WebGamesNet.net";
36                         $ip = "0::0";
37                         $realname = "Module Manager";
38                         $modes = "ioknISD";
39                         $this->modman = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
40                         if(is_a($this->modman, "P10_User")) {
41                                 $this->uplink->join($this->modman, "#opers", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
42                                 $this->uplink->join($this->modman, "#dev", P10_Channel::USERPRIV_VOICE);
43                         }
44                 } else {
45                         $this->modman = $old;
46                 }
47                 
48                 ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg");
49                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
50                 ModCMD::bind($this, BIND_CTCP, "recive_ctcp");
51         }
52         
53         public function unload($rehash = false) {
54                 if($rehash) {
55                         return $this->modman;
56                 } else {
57                         $this->uplink->delUser($this->modman, "Bye.");
58                 }
59         }
60         
61         public function recive_privmsg($user, $channel, $message) {
62                 if(!$user->getModes()->hasMode('o')) return 0;
63                 $exp=explode(" ",$message);
64                 switch (strtolower($exp[0])) {
65                         case "~loadmod":
66                                 if(BotLoader::load($exp[1],$exp[2])) {
67                                         $this->uplink->privmsg($this->modman, $channel, "done.");
68                                 } else {
69                                         $this->uplink->privmsg($this->modman, $channel, "error.");
70                                 }
71                                 break;
72                         case "~unloadmod":
73                                 if(BotLoader::unload($exp[1])) {
74                                         $this->uplink->privmsg($this->modman, $channel, "done.");
75                                 } else {
76                                         $this->uplink->privmsg($this->modman, $channel, "error.");
77                                 }
78                                 break;
79                         case "~rehash":
80                                 if(BotLoader::rehash($exp[1])) {
81                                         $this->uplink->privmsg($this->modman, $channel, "done.");
82                                 } else {
83                                         $this->uplink->privmsg($this->modman, $channel, "error.");
84                                 }
85                                 break;
86                         case "~list":
87                                 foreach(BotLoader::listBots() as $name => $bot) {
88                                         $this->uplink->privmsg($this->modman, $channel, $name);
89                                 }
90                                 break;
91                         case "~debug":
92                                 $exp=explode(" ",$message,2);
93                                 ob_start();
94                                 $ret = eval($exp[1]);
95                                 $out = ob_get_contents();
96                                 ob_end_clean();
97                                 $lines = explode("\n",$out);
98                                 for($i=0;$i<count($lines);$i++) {
99                                         if($lines[$i]!="") {
100                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
101                                         }
102                                 }
103                                 $lines = explode("\n",$ret);
104                                 for($i=0;$i<count($lines);$i++) {
105                                         if($lines[$i]!="") {
106                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
107                                         }
108                                 }
109                                 break;
110                 }
111         }
112         
113         public function recive_quit($user, $reason) {
114                 if($user === $this->modman) {
115                         $this->load($this->uplink);
116                 }
117         }
118         
119         public function recive_ctcp($user, $target, $command, $text, $publicCtcp) {
120                 if(!$publicCtcp) {
121                         switch($command) {
122                                 case"PING":
123                                         $this->uplink->ctcp_reply($target, $user, "PING", ($text - (60*60*1337 + 42*60))); //1337 42 ftw!
124                                         break;
125                                 case"VERSION":
126                                         $this->uplink->ctcp_reply($target, $user, "VERSION", "PHP-P10 Pack by pk910. Source: http://devserv.pk910.de/git/?p=PHP-P10.git");
127                                         break;
128                                 case"TIME":
129                                         $this->uplink->ctcp_reply($target, $user, "TIME", date('r'));
130                                         break;
131                                 case"FINGER":
132                                         $this->uplink->ctcp_reply($target, $user, "FINGER", "PHP-P10 Pack (C) ".date('Y')." pk910. Visit us on irc://irc.webgamesnet.net/PHP");
133                                         break;
134                         }
135                 }
136         }
137 }
138
139 ?>