continued BotLoader, added ModManager.class.php & timers
[PHP-P10.git] / Bots / ModManager.class.php
diff --git a/Bots/ModManager.class.php b/Bots/ModManager.class.php
new file mode 100644 (file)
index 0000000..4eac48c
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+/********************************* PHP-P10 ******************************
+ *    P10 uplink class by pk910   (c)2011 pk910                         *
+ ************************************************************************
+ *                          Version 2 (OOP)                             *
+ *                                                                      *
+ * PHP-P10 is free software; you can redistribute it and/or modify      *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with PHP-P10; if not, write to the Free Software Foundation,   *
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
+ *                                                                      *
+ ************************************************************************
+ * 
+ *  Bots/ModManager.class.php
+ *
+ * module manager bot...
+ *
+ */
+
+class {$_NAME} extends Bot {
+       private $uplink;
+       private $modman;
+       
+       public function load($uplink, $old = false) {
+               $this->uplink = $uplink;
+               if(!$old) {
+                       $nick = "ModuleMan";
+                       $ident = "modman";
+                       $host = "Services.WebGamesNet.net";
+                       $ip = "0::0";
+                       $realname = "Module Manager";
+                       $modes = "ioknISD";
+                       $this->modman = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
+                       if(is_a($this->modman, "P10_User")) {
+                               $this->uplink->join($this->modman, "#opers", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
+                               $this->uplink->join($this->modman, "#dev", P10_Channel::USERPRIV_VOICE);
+                       }
+               } else {
+                       $this->modman = $old;
+               }
+               
+               ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg");
+               ModCMD::bind($this, BIND_QUIT, "recive_quit");
+       }
+       
+       public function unload($rehash = false) {
+               if($rehash) {
+                       return $this->modman;
+               } else {
+                       $this->uplink->delUser($this->modman, "Bye.");
+               }
+       }
+       
+       function recive_privmsg($user, $channel, $message) {
+               if(!$user->getModes()->hasMode('o')) return 0;
+               $exp=explode(" ",$message);
+               switch (strtolower($exp[0])) {
+                       case "~loadmod":
+                               if(BotLoader::load($exp[1],$exp[2])) {
+                                       $this->uplink->privmsg($this->modman, $channel, "done.");
+                               } else {
+                                       $this->uplink->privmsg($this->modman, $channel, "error.");
+                               }
+                               break;
+                       case "~unloadmod":
+                               if(BotLoader::unload($exp[1])) {
+                                       $this->uplink->privmsg($this->modman, $channel, "done.");
+                               } else {
+                                       $this->uplink->privmsg($this->modman, $channel, "error.");
+                               }
+                               break;
+                       case "~rehash":
+                               if(BotLoader::rehash($exp[1])) {
+                                       $this->uplink->privmsg($this->modman, $channel, "done.");
+                               } else {
+                                       $this->uplink->privmsg($this->modman, $channel, "error.");
+                               }
+                               break;
+                       case "~debug":
+                               $exp=explode(" ",$message,2);
+                               ob_start();
+                               $ret = eval($exp[1]);
+                               $out = ob_get_contents();
+                               ob_end_clean();
+                               $lines = explode("\n",$out);
+                               for($i=0;$i<count($lines);$i++) {
+                                       if($lines[$i]!="") {
+                                               $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
+                                       }
+                               }
+                               $lines = explode("\n",$ret);
+                               for($i=0;$i<count($lines);$i++) {
+                                       if($lines[$i]!="") {
+                                               $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
+                                       }
+                               }
+                               break;
+               }
+       }
+       
+       function recive_quit($user, $reason) {
+               if($user === $this->modman) {
+                       $this->load($this->uplink);
+               }
+       }
+}
+
+?>
\ No newline at end of file