diff --git a/modules/rain/README.md b/modules/rain/README.md index 547a252..d6deac9 100644 --- a/modules/rain/README.md +++ b/modules/rain/README.md @@ -6,6 +6,9 @@ Quietly judges your choice of climate. It's a well documented fact that looking out of the window is sometimes far too much effort. However, sometimes you just need toknow how wet it is outside: this module queries for the precipitation level, and tells you when you need a raincoat. +### Configuration +#### apikey +This module requires a Wunderground API key. You can register for one, for free, at http://www.wunderground.com/weather/api/ ### Commands diff --git a/modules/rain/config.json b/modules/rain/config.json index e222ae7..f176f2a 100644 --- a/modules/rain/config.json +++ b/modules/rain/config.json @@ -2,5 +2,5 @@ "dependencies": [ "command" ], "ignorable": true, "help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md", - "apikey": "1234567890abcdef" + "apikey": "7707e78c7125741e" } diff --git a/modules/rain/rain.js b/modules/rain/rain.js index ca6a38c..2b48433 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -9,15 +9,21 @@ var rain = function(dbot) { var commands = { '~rain': function(event) { var apikey = dbot.config.rain.apikey; - var place = "Aberystwyth"; // you probably need to change the formulae if you change location + var place = event.input[1]; + if (!place) { var place = "Aberystwyth"; } var url = "http://api.wunderground.com/api/" + apikey + "/conditions/q/CA/" + place + ".json"; request(url, function(error, response, body) { if(response.statusCode == "200") { var data = JSON.parse(body); - var precip = data["current_observation"]["precip_1hr_metric"]; - var score = 2 * Math.pow(precip,0.5); - score = Math.ceil(score); - if (score > 10) { score = 11; } + var obs = data["current_observation"]; + if (obs) { + var precip = obs["precip_1hr_metric"]; + var score = 2 * Math.pow(precip,0.5); + score = Math.ceil(score); + if (score > 10) { score = 11; } + } else { + var score = "u"; + } } else { var score = "e"; } @@ -26,6 +32,7 @@ var rain = function(dbot) { } }; + commands['~rain'].regex = [/~rain (.+)/, 2]; this.commands = commands; this.on = 'PRIVMSG'; diff --git a/modules/rain/strings.json b/modules/rain/strings.json index bd5a5a2..1f04bf8 100644 --- a/modules/rain/strings.json +++ b/modules/rain/strings.json @@ -37,5 +37,8 @@ }, "rain-e": { "english" : "Unable to fetch weather data." + }, + "rain-u": { + "english": "Location too ambigious to process." } }