added bind and unbind functions & added the simple ExampleBot. (doesn't run right...
[PHP-P10.git] / ModCMD / ModCMD.class.php
index cbd65111e94435b233c5428e6e738a1bbf9b819c..6c735a6bb28fcd90063559897bfcdf2f5d95c669 100644 (file)
@@ -60,6 +60,44 @@ class ModCMD implements EventHandler {
                return self::$eventHandler;
        }
        
+       public static function bind($bot, $type, $method) {
+               if(is_a($bot, "Bot") && method_exists($bot, $method)) {
+                       if(array_key_exists($type, self::$bindings)) {
+                               foreach(self::$bindings[$type] as $binding) {
+                                       if($binding->match($bot, $method))
+                                               return;
+                               }
+                       } else 
+                               self::$bindings[$type] = array();
+                       self::$bindings[$type][] = new Binding($bot, $method);
+               }
+       }
+       
+       public static function unbind($bot, $type, $method) {
+               if(is_a($bot, "Bot")) {
+                       if(array_key_exists($type, self::$bindings)) {
+                               foreach(self::$bindings[$type] as $id => $binding) {
+                                       if($binding->match($bot, $method)) {
+                                               unset(self::$bindings[$type][$id]);
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       public static function unbindBot($bot) {
+               if(is_a($bot, "Bot")) {
+                       foreach(self::$bindings as $type => $bindings) {
+                               foreach($bindings as $id => $binding) {
+                                       if($binding->match($bot, null)) {
+                                               unset(self::$bindings[$type][$id]);
+                                       }
+                               }
+                       }
+               }
+       }
+       
        /********************************************************************************************
         *                                       EVENT HANDLER                                      *
         ********************************************************************************************/
@@ -85,7 +123,7 @@ class ModCMD implements EventHandler {
        private function event($type, $parameters) {
                if(array_key_exists($type, self::$bindings)) {
                        foreach(self::$bindings as $binding) {
-                               $binding->trigger();
+                               $binding->trigger($parameters);
                        }
                }
        }