private function addDefaultHandlers()
    {
        $log = $this->log;

        // When the server PINGs us, just respond with PONG and the server's host
        $this->onPing(function(Event $event) {
            $event->addResponse(Response::pong($event->getRequest()->getMessage()));
        });

        // If an ERROR message is encountered, just log it for now.
        $this->onError(function(Event $event) use ($log) {
            $log->debug("--- ERROR: {$event->getRequest()->getMessage()}");
        });

        $plugins = & $this->plugins;
        $this->onMessages('/^!help\s*$/', function(Event $event) use (& $plugins) {
            foreach ($plugins as $plugin) {
                $messages = $plugin->displayHelp($event);

                // Surely there's a better way to do this... <sadface>
                if (is_array($messages)) {
                    foreach ($messages as $message) {
                        $event->addResponse(
                            Response::msg($event->getRequest()->getSendingUser(), $message)
                        );
                    }
                } else {
                    $event->addResponse(
                        Response::msg($event->getRequest()->getSendingUser(), $messages)
                    );
                }
            }
        });
    }
private function addDefaultHandlers()
    {
        $log = $this->log;

        // When the server PINGs us, just respond with PONG and the server's host
        $this->onPing(function(Event $event) {
            $event->addResponse(Response::pong($event->getRequest()->getMessage()));
        });

        // If an ERROR message is encountered, just log it for now.
        $this->onError(function(Event $event) use ($log) {
            $log->debug("--- ERROR: {$event->getRequest()->getMessage()}");
        });

        $plugins = & $this->plugins;
        $this->onMessages('/^!help\s*$/', function(Event $event) use (& $plugins) {
            foreach ($plugins as $plugin) {
                $messages = $plugin->displayHelp($event);

                // Surely there's a better way to do this... <sadface>
                if (is_array($messages)) {
                    foreach ($messages as $message) {
                        $event->addResponse(
                            Response::msg($event->getRequest()->getSendingUser(), $message)
                        );
                    }
                } else {
                    $event->addResponse(
                        Response::msg($event->getRequest()->getSendingUser(), $messages)
                    );
                }
            }
        });
    }
private function addDefaultHandlers ( ) { $ log = $ this -> log ; // When the server PINGs us, just respond with PONG and the server's host $ this -> onPing ( function ( Event $ event ) { $ event -> addResponse ( Response :: pong ( $ event -> getRequest ( ) -> getMessage ( ) ) ) ; } ) ; // If an ERROR message is encountered, just log it for now. $ this -> onError ( function ( Event $ event ) use ( $ log ) { $ log -> debug ( "--- ERROR: {$event->getRequest()->getMessage()}" ) ; } ) ; $ plugins = & $ this -> plugins ; $ this -> onMessages ( '/^!help\s*$/' , function ( Event $ event ) use ( & $ plugins ) { foreach ( $ plugins as $ plugin ) { $ messages = $ plugin -> displayHelp ( $ event ) ; // Surely there's a better way to do this... <sadface> if ( is_array ( $ messages ) ) { foreach ( $ messages as $ message ) { $ event -> addResponse ( Response :: msg ( $ event -> getRequest ( ) -> getSendingUser ( ) , $ message ) ) ; } } else { $ event -> addResponse ( Response :: msg ( $ event -> getRequest ( ) -> getSendingUser ( ) , $ messages ) ) ; } } } ) ; }
Loads default event handlers for basic IRC commands that won't be
unique to each bot.
Loads default event handlers for basic IRC commands that won t be unique to each bot .