3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-11 12:32:36 +01:00

Don't show comma if no city is given

The OpenWeatherMap API may return weather for areas unlinked to a city, on which body.name will be undefined. This would previously show up as (for example) "[ , United Kingdom]". This simple ternary will only return a comma if it is also returning a city name.
This commit is contained in:
Kagammor 2015-02-17 01:23:51 +01:00
parent 5aeeb77065
commit c7733ee382

View File

@ -20,7 +20,7 @@ var weather = function(dbot) {
'json': true
}, function(err, response, body) {
if(!err && body && _.has(body, 'cod') && body.cod === 200) {
event.reply('['+body.name+', '+body.sys.country+']' + ' Condition: ' + body.weather[0].description + ' | Temp: ' + Math.round(body.main.temp) + 'C/'+Math.round(body.main.temp* 9 / 5 + 32)+'F | Humidity: ' + body.main.humidity + '% | Wind Speed: ' + body.wind.speed + 'KM/H');
event.reply('['+(body.name ? body.name +', ':'')+body.sys.country+']' + ' Condition: ' + body.weather[0].description + ' | Temp: ' + Math.round(body.main.temp) + 'C/'+Math.round(body.main.temp* 9 / 5 + 32)+'F | Humidity: ' + body.main.humidity + '% | Wind Speed: ' + body.wind.speed + 'KM/H');
} else {
event.reply('There is no weather in ' + city);
}