Skip to content
Snippets Groups Projects
Commit e8683efc authored by deuce's avatar deuce
Browse files

Cleanup

parent 8283ce21
No related branches found
No related tags found
No related merge requests found
Bot_Commands["WEATHER"] = new Bot_Command(0,false,false);
Bot_Commands["WEATHER"].command = function (target,onick,ouh,srv,lvl,cmd) {
var i;
var lstr;
if (!cmd[1])
cmd[1] = onick;
......@@ -8,22 +10,41 @@ Bot_Commands["WEATHER"].command = function (target,onick,ouh,srv,lvl,cmd) {
var usr = new User(system.matchuser(cmd[1]));
cmd.shift();
if (typeof(usr)=='object')
query = usr.location;
if (!query)
query = cmd.join(' ');
query = query.replace(/[ ]/,'%20');
lstr = usr.location;
if (!lstr)
lstr = cmd.join(' ');
query = encodeURIComponent(lstr);
var weather_url = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + query;
var location_url = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=" + query;
var Weather = new XML((new HTTPRequest().Get(weather_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
var Location = new XML((new HTTPRequest().Get(location_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
var str = Weather.display_location.full + " - "
+ Weather.temperature_string
+ " (Observed at: " + Weather.observation_location.city
+ ")";
/* if (Weather.display_location.full=="" || !Weather.temperature_string=="")
str = "No result."; */
switch(Location.location.length()) {
case 0:
if(Location.nearby_weather_stations.length()==0) {
srv.o(target, "Unable to locate "+lstr);
break;
}
// Fall-through
case 1:
var Weather = new XML((new HTTPRequest().Get(weather_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
var str = Weather.display_location.full;
str += " - " + Weather.weather;
str += ", "+ Weather.temp_c+" degrees ("+(parseInt(Weather.temp_c)+273)+"K, "+Weather.temp_f+"F)";
str += " Wind "+Weather.wind_string;
if(Weather.display_location.city != Weather.observation_location.city)
str += " (Observed at: " + Weather.observation_location.city + ")";
str += ' (Provided by Weather Underground, Inc.)';
srv.o(target, str);
break;
default:
srv.o(target, "Multiple matches for "+lstr);
for(i in Location.location)
srv.o(target, lstr+': '+Location.location[i].name);
break;
}
srv.o(target, str);
return true;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment