Ejemplo n.º 1
0
 /**
  * Search for IMDB Data, and give response to channel
  *
  * IRC-Syntax: PRIVMSG Movie title
  */
 public function command()
 {
     $imdbTitle = implode(' ', $this->arguments);
     $imdbTitle = preg_replace('/\\s\\s+/', ' ', $imdbTitle);
     $imdbTitle = trim($imdbTitle);
     $imdbTitle = urlencode($imdbTitle);
     if (!strlen($imdbTitle)) {
         $this->say(sprintf('Enter movie title. (Usage: !imdb movie title)'));
         return;
     }
     $apiUri = sprintf($this->apiUri, $imdbTitle);
     $getJson = func::fetch($apiUri);
     $json = json_decode($getJson, true);
     $title = $json['Title'];
     $rating = $json['imdbRating'];
     $shortPlot = $json['Plot'];
     $link = 'http://www.imdb.com/title/' . $json['imdbID'];
     /*
      * Check if response is given
      */
     if (!strlen($title)) {
         $this->say('IMDB: Error fetching data');
         return;
     }
     $this->say(sprintf('Title: %s | Rating: %s | %s | %s', $title, $rating, $shortPlot, $link));
 }
Ejemplo n.º 2
0
 private function getYtTitle($data)
 {
     preg_match('/https?:\\/\\/(?:www.)?(?:youtu.be|youtube.com)\\/(?:[a-zA-Z0-9_?=]+)/', $data, $matches);
     if (!empty($matches) && !empty($matches[0])) {
         // We've got a YT URL. Parse it.
         $matches = parse_url($matches[0]);
         // We could have parsed a youtube.com link which parses in more pieces, and one piece must always be the same.
         // We take advantage of this.
         if ($matches['path'] == '/watch') {
             $vid_id = substr($matches['query'], 2);
         } else {
             $vid_id = substr($matches['path'], 1);
         }
         // We got a video ID longer or smaller than 11 characters...? That's, um, special.
         if (empty($vid_id) || strlen($vid_id) != 11) {
             return false;
         }
         // Put it into the final URL.
         $ytApi = sprintf($this->apiUri, $vid_id);
         // Make a request.
         $Ytdata = func::fetch($ytApi);
         // Attempt to fetch the title from the garbage we received.
         preg_match("/(?<=<title type=\\'text\\'>).*(?=<\\/title>)/", $Ytdata, $ytTitle);
         // And return it.
         return $ytTitle[0];
     }
     // Sorry pals, non-YouTube URLs ain't going to cut it.
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Sends the arguments to the channel. A random joke.
  *
  * IRC-Syntax: PRIVMSG [#channel]or[user] : [message]
  */
 public function command()
 {
     $this->bot->log("Fetching joke.");
     $data = func::fetch("http://api.icndb.com/jokes/random");
     // ICNDB has escaped slashes in JSON response.
     $data = stripslashes($data);
     $joke = json_decode($data);
     if ($joke) {
         if (isset($joke->value->joke)) {
             $this->say(html_entity_decode($joke->value->joke));
             return;
         }
     }
     $this->say("I don't feel like laughing today. :(");
 }
Ejemplo n.º 4
0
 /**
  * Checks Version of Bot and Latest Version
  */
 public function command()
 {
     $jsonfile = func::fetch($this->updateUri);
     $jsondata = json_decode($jsonfile);
     $latestversion = $jsondata->update[0]->version;
     $botversion = $this->bot->botVersion;
     $result = version_compare($botversion, $latestversion);
     if ($result === -1) {
         $updated = chr(3) . "07Out of Date!";
     } elseif ($result === 0) {
         $updated = chr(3) . "03Up to Date!";
     } else {
         $updated = chr(3) . "04You Broke Something :'(";
     }
     $this->say('The Latest Bot Version is ' . $latestversion . '. Your Bot is Version is ' . $botversion . ".");
     $this->say('Your Bot is ' . $updated);
 }
Ejemplo n.º 5
0
 /**
  * Returns location name of $ip.
  *
  * @param $ip
  *
  * @return string
  */
 protected function getLocationNameFromIp($ip)
 {
     $uri = sprintf($this->ipUri, $ip);
     $response = func::fetch($uri);
     $jsonResponse = json_decode($response);
     if ($jsonResponse) {
         if (isset($jsonResponse->city)) {
             return $jsonResponse->city;
         }
     }
     return null;
 }