/**
  * @HandlesCommand("weather")
  * @Matches("/^weather (.+)$/i")
  */
 public function weatherCommand($message, $channel, $sender, $sendto, $args)
 {
     $location = $args[1];
     $blob = '';
     $geolookup = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=" . urlencode($location);
     $current = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" . urlencode($location);
     $forecast = "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=" . urlencode($location);
     $alerts = "http://api.wunderground.com/auto/wui/geo/AlertsXML/index.xml?query=" . urlencode($location);
     $geolookup = file_get_contents($geolookup);
     // Geolookup
     if (xml::spliceData($geolookup, "<wui_error>", "</wui_error>") != "") {
         $sendto->reply("No information is available for <highlight>" . $location . "<end>.");
         return;
     }
     $locations = xml::spliceMultiData($geolookup, "<name>", "</name>");
     if (count($locations) > 1) {
         $blob .= "Multiple hits for {$location}.\n\n";
         foreach ($locations as $spot) {
             $blob .= $this->text->make_chatcmd($spot, "/tell <myname> weather {$spot}") . "\n";
         }
         $msg = $this->text->make_blob('Weather Locations', $blob);
         $sendto->reply($msg);
         return;
     }
     $sendto->reply("Collecting data for <highlight>" . $location . "<end>.");
     $current = file_get_contents($current);
     $forecast = file_get_contents($forecast);
     $alerts = file_get_contents($alerts);
     // CURRENT
     $updated = xml::spliceData($current, "<observation_time_rfc822>", "</observation_time_rfc822>");
     if ($updated == ", :: GMT") {
         $sendto->reply("No information is available for <highlight>" . $location . "<end>.");
         return;
     }
     $credit = xml::spliceData($current, "<credit>", "</credit>");
     $crediturl = xml::spliceData($current, "<credit_URL>", "</credit_URL>");
     $observeLoc = xml::spliceData($current, "<observation_location>", "</observation_location>");
     $fullLoc = xml::spliceData($observeLoc, "<full>", "</full>");
     $country = xml::spliceData($observeLoc, "<country>", "</country>");
     $lat = xml::spliceData($observeLoc, "<latitude>", "</latitude>");
     $lon = xml::spliceData($observeLoc, "<longitude>", "</longitude>");
     $elevation = xml::spliceData($observeLoc, "<elevation>", "</elevation>");
     $weather = xml::spliceData($current, "<weather>", "</weather>");
     $tempstr = xml::spliceData($current, "<temperature_string>", "</temperature_string>");
     $humidity = xml::spliceData($current, "<relative_humidity>", "</relative_humidity>");
     $windstr = xml::spliceData($current, "<wind_string>", "</wind_string>");
     $windgust = xml::spliceData($current, "<wind_gust_mph>", "</wind_gust_mph>");
     $pressurestr = xml::spliceData($current, "<pressure_string>", "</pressure_string>");
     $dewstr = xml::spliceData($current, "<dewpoint_string>", "</dewpoint_string>");
     $heatstr = xml::spliceData($current, "<heat_index_string>", "</heat_index_string>");
     $windchillstr = xml::spliceData($current, "<windchill_string>", "</windchill_string>");
     $visibilitymi = xml::spliceData($current, "<visibility_mi>", "</visibility_mi>");
     $visibilitykm = xml::spliceData($current, "<visibility_km>", "</visibility_km>");
     $latlonstr = number_format(abs($lat), 1);
     if (abs($lat) == $lat) {
         $latlonstr .= "N ";
     } else {
         $latlonstr .= "S ";
     }
     $latlonstr .= number_format(abs($lon), 1);
     if (abs($lon) == $lon) {
         $latlonstr .= "E ";
     } else {
         $latlonstr .= "W ";
     }
     $latlonstr .= $this->text->make_chatcmd("Google Map", "/start http://maps.google.com/maps?q={$lat},{$lon}") . " ";
     $latlonstr .= $this->text->make_chatcmd("Wunder Map", "/start http://www.wunderground.com/wundermap/?lat={$lat}&lon={$lon}&zoom=10") . "\n\n";
     $blob .= "Credit: <highlight>" . $this->text->make_chatcmd($credit, "/start {$crediturl}") . "<end>\n";
     $blob .= "Last Updated: <highlight>{$updated}<end>\n\n";
     $blob .= "Location: <highlight>{$fullLoc}, {$country}<end>\n";
     $blob .= "Lat/Lon: <highlight>{$latlonstr}<end>";
     $blob .= "Currently: <highlight>{$tempstr}, {$weather}<end>\n";
     $blob .= "Humidity: <highlight>{$humidity}<end>\n";
     $blob .= "Dew Point: <highlight>{$dewstr}<end>\n";
     $blob .= "Wind: <highlight>{$windstr}<end>";
     if ($windgust) {
         $blob .= " (Gust:{$windgust} mph)\n";
     } else {
         $blob .= "\n";
     }
     if ($heatstr != "NA") {
         $blob .= "Heat Index: <highlight>{$heatstr}<end>\n";
     }
     if ($windchillstr != "NA") {
         $blob .= "Windchill: <highlight>{$windchillstr}<end>\n";
     }
     $blob .= "Pressure: <highlight>{$pressurestr}<end>\n";
     $blob .= "Visibility: <highlight>{$visibilitymi} miles, {$visibilitykm} km<end>\n";
     $blob .= "Elevation: <highlight>{$elevation}<end>\n";
     // ALERTS
     $alertitems = xml::spliceMultiData($alerts, "<AlertItem>", "</AlertItem>");
     if (count($alertitems) == 0) {
         $blob .= "\n<header2>Alerts:<end> None reported.\n\n";
     } else {
         foreach ($alertitems as $thisalert) {
             $blob .= "\n<header2>Alert: " . xml::spliceData($thisalert, "<description>", "</description>") . "<end>\n\n";
             // gotta find date/expire manually.
             $start = strpos($thisalert, ">", strpos($thisalert, "<date epoch=")) + 1;
             $end = strpos($thisalert, "<", $start);
             $blob .= "Issued:<highlight>" . substr($thisalert, $start, $end - $start) . "<end>\n";
             $start = strpos($thisalert, ">", strpos($thisalert, "<expires epoch=")) + 1;
             $end = strpos($thisalert, "<", $start);
             $blob .= "Expires:<highlight>" . substr($thisalert, $start, $end - $start) . "<end>\n";
             $blob .= xml::spliceData($thisalert, "<message>", "</message>") . "";
         }
     }
     // FORECAST
     $simpleforecast = xml::spliceData($forecast, "<simpleforecast>", "</simpleforecast>");
     $forecastday = xml::spliceMultiData($simpleforecast, "<forecastday>", "</forecastday>");
     if (count($forecastday) > 0) {
         foreach ($forecastday as $day) {
             if (!($condition = xml::spliceData($day, "<conditions>", "</conditions>"))) {
                 break;
             }
             $low[0] = xml::spliceData($day, "<low>", "</low>");
             $low[1] = xml::spliceData($low[0], "<fahrenheit>", "</fahrenheit");
             $low[2] = xml::spliceData($low[0], "<celsius>", "</celsius");
             $high[0] = xml::spliceData($day, "<high>", "</high>");
             $high[1] = xml::spliceData($high[0], "<fahrenheit>", "</fahrenheit");
             $high[2] = xml::spliceData($high[0], "<celsius>", "</celsius");
             $pop = xml::spliceData($day, "<pop>", "</pop>");
             $blob .= xml::spliceData($day, "<weekday>", "</weekday>") . ": <highlight>{$condition}<end>";
             if (0 == $pop) {
                 $blob .= "\n";
             } else {
                 $blob .= " ({$pop}% Precip)\n";
             }
             $blob .= "High: <highlight>";
             $blob .= $high[1] . "F";
             $blob .= $high[2] . "C<end>    ";
             $blob .= "Low: <highlight>" . $low[1] . "F";
             $blob .= $low[2] . "C<end>\n\n";
         }
     }
     $msg = $this->text->make_blob('Weather: ' . $location, $blob);
     $sendto->reply($msg);
 }
Esempio n. 2
0
 public function get_by_id($guild_id, $rk_num = 0, $forceUpdate = false)
 {
     // if no server number is specified use the one on which the bot is logged in
     if ($rk_num == 0) {
         $rk_num = $this->chatBot->vars["dimension"];
     }
     $name = ucfirst(strtolower($name));
     $url = "http://people.anarchy-online.com/org/stats/d/{$rk_num}/name/{$guild_id}/basicstats.xml";
     $groupName = "guild_roster";
     $filename = "{$guild_id}.{$rk_num}.xml";
     if ($this->chatBot->vars["my_guild_id"] == $guild_id) {
         $maxCacheAge = 21600;
     } else {
         $maxCacheAge = 86400;
     }
     $cb = function ($data) {
         if (xml::spliceData($data, "<id>", "</id>") != "") {
             return true;
         } else {
             return false;
         }
     };
     $cacheResult = $this->cacheManager->lookup($url, $groupName, $filename, $cb, $maxCacheAge, $forceUpdate);
     // if there is still no valid data available give an error back
     if ($cacheResult->success !== true) {
         return null;
     }
     $guild = new stdClass();
     $guild->guild_id = $guild_id;
     // parsing of the memberdata
     $members = xml::splicemultidata($cacheResult->data, "<member>", "</member>");
     $guild->orgname = xml::spliceData($cacheResult->data, "<name>", "</name>");
     $guild->orgside = xml::spliceData($cacheResult->data, "<side>", "</side");
     // pre fetch the charids...this speeds things up immensely
     foreach ($members as $xmlmember) {
         $name = xml::splicedata($xmlmember, "<nickname>", "</nickname>");
         if (!isset($this->chatBot->id[$name])) {
             $this->chatBot->send_packet(new AOChatPacket("out", AOCP_CLIENT_LOOKUP, $name));
         }
     }
     foreach ($members as $member) {
         $name = xml::splicedata($member, "<nickname>", "</nickname>");
         $charid = $this->chatBot->get_uid($name);
         if ($charid == null) {
             $charid = 0;
         }
         $guild->members[$name] = new stdClass();
         $guild->members[$name]->charid = $charid;
         $guild->members[$name]->firstname = xml::spliceData($member, '<firstname>', '</firstname>');
         $guild->members[$name]->name = xml::spliceData($member, '<nickname>', '</nickname>');
         $guild->members[$name]->lastname = xml::spliceData($member, '<lastname>', '</lastname>');
         $guild->members[$name]->level = xml::spliceData($member, '<level>', '</level>');
         $guild->members[$name]->breed = xml::spliceData($member, '<breed>', '</breed>');
         $guild->members[$name]->gender = xml::spliceData($member, '<gender>', '</gender>');
         $guild->members[$name]->faction = $guild->orgside;
         $guild->members[$name]->profession = xml::spliceData($member, '<profession>', '</profession>');
         $guild->members[$name]->prof_title = xml::spliceData($member, '<profession_title>', '</profession_title>');
         $guild->members[$name]->ai_rank = xml::spliceData($member, '<defender_rank>', '</defender_rank>');
         $guild->members[$name]->ai_level = xml::spliceData($member, '<defender_rank_id>', '</defender_rank_id>');
         $guild->members[$name]->guild_id = $guild->guild_id;
         $guild->members[$name]->guild = $guild->orgname;
         $guild->members[$name]->guild_rank = xml::spliceData($member, '<rank_name>', '</rank_name>');
         $guild->members[$name]->guild_rank_id = xml::spliceData($member, '<rank>', '</rank>');
         $guild->members[$name]->dimension = $rk_num;
         $guild->members[$name]->source = 'org_roster';
     }
     // this is done separately from the loop above to prevent nested transaction errors from occuring
     // when looking up charids for characters
     if ($cacheResult->usedCache === false) {
         $this->db->beginTransaction();
         $sql = "UPDATE players SET guild_id = 0, guild = '' WHERE guild_id = ? AND dimension = ?";
         $this->db->exec($sql, $guild->guild_id, $rk_num);
         foreach ($guild->members as $member) {
             $this->playerManager->update($member);
         }
         $this->db->commit();
     }
     return $guild;
 }
Esempio n. 3
0
 private function lookup_url($url)
 {
     $response = $this->http->get($url)->waitAndReturnResponse();
     $playerbio = $response->body;
     $xml = new stdClass();
     // parsing of the player data
     $xml->firstname = xml::spliceData($playerbio, '<firstname>', '</firstname>');
     $xml->name = xml::spliceData($playerbio, '<nick>', '</nick>');
     $xml->lastname = xml::spliceData($playerbio, '<lastname>', '</lastname>');
     $xml->level = xml::spliceData($playerbio, '<level>', '</level>');
     $xml->breed = xml::spliceData($playerbio, '<breed>', '</breed>');
     $xml->gender = xml::spliceData($playerbio, '<gender>', '</gender>');
     $xml->faction = xml::spliceData($playerbio, '<faction>', '</faction>');
     $xml->profession = xml::spliceData($playerbio, '<profession>', '</profession>');
     $xml->prof_title = xml::spliceData($playerbio, '<profession_title>', '</profession_title>');
     $xml->ai_rank = xml::spliceData($playerbio, '<defender_rank>', '</defender_rank>');
     $xml->ai_level = xml::spliceData($playerbio, '<defender_rank_id>', '</defender_rank_id>');
     $xml->guild_id = xml::spliceData($playerbio, '<organization_id>', '</organization_id>');
     $xml->guild = xml::spliceData($playerbio, '<organization_name>', '</organization_name>');
     $xml->guild_rank = xml::spliceData($playerbio, '<rank>', '</rank>');
     $xml->guild_rank_id = xml::spliceData($playerbio, '<rank_id>', '</rank_id>');
     return $xml;
 }