From c7733ee38258093692b6d23a33f2efac14829372 Mon Sep 17 00:00:00 2001 From: Kagammor Date: Tue, 17 Feb 2015 01:23:51 +0100 Subject: [PATCH] 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. --- modules/weather/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/weather/weather.js b/modules/weather/weather.js index 58ce0b8..f7e50ec 100644 --- a/modules/weather/weather.js +++ b/modules/weather/weather.js @@ -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); }