public function init()
    {
        $config = $this->getConfig();

        if (!isset($config['api_key'])) {
            throw new \Exception('Unable to locate darksky_api_key in bot configuration.');
        }

        $this->darksky = new \DarkSky($config['api_key']);
        $plugin = $this;    // PHP 5.3, you suck.

        // Look at all this weather!
        $this->bot->onChannel('/^!ds (\w+)(.*)/', function(Event $event) use ($plugin) {
            $matches = $event->getMatches();
            switch($cmd = $matches[0]) {
                case 'now':
                case 'current':
                    $plugin->getCurrentWeather(trim($matches[1]), $event);
                    break;

                case 'forecast':
                case 'at':
                    $plugin->getPrecipitation(trim($matches[1]), $event);
                    break;

                default:
                    $plugin->addErrorMsg($event, "Unknown command: $cmd");
                    break;
            }
        });
    }
public function init()
    {
        $config = $this->getConfig();

        if (!isset($config['api_key'])) {
            throw new \Exception('Unable to locate darksky_api_key in bot configuration.');
        }

        $this->darksky = new \DarkSky($config['api_key']);
        $plugin = $this;    // PHP 5.3, you suck.

        // Look at all this weather!
        $this->bot->onChannel('/^!ds (\w+)(.*)/', function(Event $event) use ($plugin) {
            $matches = $event->getMatches();
            switch($cmd = $matches[0]) {
                case 'now':
                case 'current':
                    $plugin->getCurrentWeather(trim($matches[1]), $event);
                    break;

                case 'forecast':
                case 'at':
                    $plugin->getPrecipitation(trim($matches[1]), $event);
                    break;

                default:
                    $plugin->addErrorMsg($event, "Unknown command: $cmd");
                    break;
            }
        });
    }
public function init ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'api_key' ] ) ) { throw new \ Exception ( 'Unable to locate darksky_api_key in bot configuration.' ) ; } $ this -> darksky = new \ DarkSky ( $ config [ 'api_key' ] ) ; $ plugin = $ this ; // PHP 5.3, you suck. // Look at all this weather! $ this -> bot -> onChannel ( '/^!ds (\w+)(.*)/' , function ( Event $ event ) use ( $ plugin ) { $ matches = $ event -> getMatches ( ) ; switch ( $ cmd = $ matches [ 0 ] ) { case 'now' : case 'current' : $ plugin -> getCurrentWeather ( trim ( $ matches [ 1 ] ) , $ event ) ; break ; case 'forecast' : case 'at' : $ plugin -> getPrecipitation ( trim ( $ matches [ 1 ] ) , $ event ) ; break ; default : $ plugin -> addErrorMsg ( $ event , "Unknown command: $cmd" ) ; break ; } } ) ; }
Uses the DarkSky API to retrieve weather data
Uses the DarkSky API to retrieve weather data