public function init()
    {
        $this->addResponses();

        $config = $this->bot->getConfig();

        // detects someone speaking to the bot
        $responses = $this->responses;
        $address_re = "/(^{$config['nick']}(.+)|(.+){$config['nick']}[!.?]*)$/i";
        $this->bot->onChannel($address_re, function(Event $event) use ($responses) {
            $matches = $event->getMatches();
            $message = $matches[1] ? $matches[1] : $matches[2];
            
            foreach ($responses as $regex => $function) {
                if (preg_match($regex, $message, $matches)) {
                    $event->addResponse(
                        Response::msg($event->getRequest()->getSource(), $function($matches))
                    );
                }
            }
        });
    }
public function init()
    {
        $this->addResponses();

        $config = $this->bot->getConfig();

        // detects someone speaking to the bot
        $responses = $this->responses;
        $address_re = "/(^{$config['nick']}(.+)|(.+){$config['nick']}[!.?]*)$/i";
        $this->bot->onChannel($address_re, function(Event $event) use ($responses) {
            $matches = $event->getMatches();
            $message = $matches[1] ? $matches[1] : $matches[2];
            
            foreach ($responses as $regex => $function) {
                if (preg_match($regex, $message, $matches)) {
                    $event->addResponse(
                        Response::msg($event->getRequest()->getSource(), $function($matches))
                    );
                }
            }
        });
    }
public function init ( ) { $ this -> addResponses ( ) ; $ config = $ this -> bot -> getConfig ( ) ; // detects someone speaking to the bot $ responses = $ this -> responses ; $ address_re = "/(^{$config['nick']}(.+)|(.+){$config['nick']}[!.?]*)$/i" ; $ this -> bot -> onChannel ( $ address_re , function ( Event $ event ) use ( $ responses ) { $ matches = $ event -> getMatches ( ) ; $ message = $ matches [ 1 ] ? $ matches [ 1 ] : $ matches [ 2 ] ; foreach ( $ responses as $ regex => $ function ) { if ( preg_match ( $ regex , $ message , $ matches ) ) { $ event -> addResponse ( Response :: msg ( $ event -> getRequest ( ) -> getSource ( ) , $ function ( $ matches ) ) ) ; } } } ) ; }
Init the plugin and start listening to messages
Init the plugin and start listening to messages