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 * ********************************************************************************************/ //All events trigger a binding. You may set the same binding for eg. CHANMODE and USERMODE (or some others) //to get only one binding for both events... but i think that's senceless const EVENT_NEWSERVER = BIND_NEWSERVER; const EVENT_SQUIT = BIND_SQUIT; const EVENT_CONNECT = BIND_CONNECT; const EVENT_NICK = BIND_NICK; const EVENT_USERMODE = BIND_USERMODE; const EVENT_QUIT = BIND_QUIT; const EVENT_JOIN = BIND_JOIN; const EVENT_PART = BIND_PART; const EVENT_KICK = BIND_KICK; const EVENT_CHANMODE = BIND_CHANMODE; const EVENT_CHANMSG = BIND_CHANMSG; const EVENT_PRIVMSG = BIND_PRIVMSG; const EVENT_CHANNOTICE = BIND_CHANNOTICE; const EVENT_PRIVNOTICE = BIND_PRIVNOTICE; const EVENT_PREPARSE = BIND_PREPARSE; const EVENT_UNKNOWNCMD = BIND_UNKNOWNCMD; private function event($type, $parameters) { if(array_key_exists($type, self::$bindings)) { foreach(self::$bindings as $binding) { $binding->trigger($parameters); } } } public function event_newserver($server, $isBurst) { $this->event(self::EVENT_NEWSERVER, array($server, $isBurst)); } public function event_squit($server){ $this->event(self::EVENT_SQUIT, array($server)); } public function event_connect($user, $isBurst) { $this->event(self::EVENT_CONNECT, array($user, $isBurst)); } public function event_nick($user, $newNick) { $this->event(self::EVENT_NICK, array($user, $newNick)); } public function event_usermode($user, $modes) { $this->event(self::EVENT_USERMODE, array($user, $modes)); } public function event_quit($user, $reason) { $this->event(self::EVENT_QUIT, array($user, $reason)); } public function event_join($user, $channel, $isBurst) { $this->event(self::EVENT_JOIN, array($user, $channel, $isBurst)); } public function event_part($user, $channel, $reason) { $this->event(self::EVENT_PART, array($user, $channel, $reason)); } public function event_kick($user, $target, $channel, $reason) { $this->event(self::EVENT_KICK, array($user, $target, $channel, $reason)); } public function event_chanmode($user, $channel, $modes) { $this->event(self::EVENT_CHANMODE, array($user, $channel, $modes)); } public function event_chanmessage($user, $channel, $message) { $this->event(self::EVENT_CHANMSG, array($user, $channel, $message)); } public function event_channotice($user, $channel, $message) { $this->event(self::EVENT_CHANNOTICE, array($user, $channel, $message)); } public function event_privmessage($user, $channel, $message) { $this->event(self::EVENT_PRIVMSG, array($user, $channel, $message)); } public function event_privnotice($user, $channel, $message) { $this->event(self::EVENT_PRIVNOTICE, array($user, $channel, $message)); } public function event_preparse($from, $command, $arguments) { $this->event(self::EVENT_PREPARSE, array($from, $command, $arguments)); } public function event_unknown_cmd($from, $command, $arguments) { $this->event(self::EVENT_UNKNOWNCMD, array($from, $command, $arguments)); } } ?>