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

Deal with non-present nick.

parent 7443cea6
No related branches found
No related tags found
No related merge requests found
......@@ -15,64 +15,69 @@ Bot_Commands["WEATHER"].command = function (target,onick,ouh,srv,lvl,cmd) {
cmd.shift();
if(cmd[0])
nick=cmd[0];
lstr=get_nicklocation(srv.users[nick.toUpperCase()].uh, srv.users[nick.toUpperCase()].servername, nick);
if (!lstr) {
var usr = new User(system.matchuser(nick));
if (typeof(usr)=='object')
lstr = usr.location;
if(srv.users[nick.toUpperCase()] == undefined) {
srv.o(target, nick+', who the f^@% is '+nick+"?");
}
if(!lstr && cmd[0])
lstr=cmd.join(' ');
var query = encodeURIComponent(lstr);
else {
lstr=get_nicklocation(srv.users[nick.toUpperCase()].uh, srv.users[nick.toUpperCase()].servername, nick);
if (!lstr) {
var usr = new User(system.matchuser(nick));
if (typeof(usr)=='object')
lstr = usr.location;
}
if(!lstr && cmd[0])
lstr=cmd.join(' ');
var 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_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;
try {
var Location = new XML((new HTTPRequest().Get(location_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
}
catch(e) {
srv.o(target, "Unable to resolve location "+lstr);
return true;
}
try {
var Location = new XML((new HTTPRequest().Get(location_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
}
catch(e) {
srv.o(target, "Unable to resolve location "+lstr);
return true;
}
switch(Location.location.length()) {
case 0:
if(Location.nearby_weather_stations.length()==0) {
srv.o(target, "Unable to locate "+lstr);
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;
}
// Fall-through
case 1:
var Weather = new XML((new HTTPRequest().Get(weather_url)).replace(/<\?.*\?>[\r\n\s]*/,''));
default:
srv.o(target, "Multiple matches for "+lstr);
if(Location.location.length() > 7)
srv.o(target, lstr+" matches "+Location.location.length()+" places... listing the first 7.");
var outstr = "";
var outcnt = 0;
for (i in Location.location) {
if (outcnt)
outstr += "; ";
outstr += Location.location[i].name;
outcnt++;
if (outcnt>=7)
break;
}
srv.o(target, lstr+': '+outstr+'.');
break;
}
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);
if(Location.location.length() > 7)
srv.o(target, lstr+" matches "+Location.location.length()+" places... listing the first 7.");
var outstr = "";
var outcnt = 0;
for (i in Location.location) {
if (outcnt)
outstr += "; ";
outstr += Location.location[i].name;
outcnt++;
if (outcnt>=7)
break;
}
srv.o(target, lstr+': '+outstr+'.');
break;
}
return true;
}
......
......@@ -27,29 +27,34 @@ Bot_Commands["WHEREIS"].command = function (target,onick,ouh,srv,lvl,cmd) {
return true;
}
location=get_nicklocation(srv.users[find.toUpperCase()].uh, srv.users[find.toUpperCase()].servername, find);
if (location) {
lstr=find+' is ';
if(location.cityName=='')
lstr += 'somewhere in ';
else
lstr += 'around '+location.cityName+', ';
if(location.regionName!='')
lstr += location.regionName+', ';
if(location.countryName!='')
lstr += location.countryName;
if(srv.users[find.toUpperCase()] == undefined) {
lstr=find+', who the f^@% is '+find+"?";
}
else {
var usr = new User(system.matchuser(cmd[1]));
location=get_nicklocation(srv.users[find.toUpperCase()].uh, srv.users[find.toUpperCase()].servername, find);
if (location) {
lstr=find+' is ';
if(location.cityName=='')
lstr += 'somewhere in ';
else
lstr += 'around '+location.cityName+', ';
if(location.regionName!='')
lstr += location.regionName+', ';
if(location.countryName!='')
lstr += location.countryName;
}
else {
var usr = new User(system.matchuser(cmd[1]));
if (typeof(usr)=='object' && usr.location)
lstr = find+' is located at '+usr.location;
}
if (typeof(usr)=='object' && usr.location)
lstr = find+' is located at '+usr.location;
}
if(!lstr)
lstr="Unable to locate "+find;
if(!lstr)
lstr="Unable to locate "+find;
}
srv.o(target, lstr);
......
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