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

WHY DOES THE RAIN GO DOWN NOT UP

This commit is contained in:
Douglas Gardner 2013-01-30 13:29:49 +00:00
parent c9161c10ae
commit 178495bd69
4 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -2,5 +2,5 @@
"dependencies": [ "command" ],
"ignorable": true,
"help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md",
"apikey": "1234567890abcdef"
"apikey": "7707e78c7125741e"
}

View File

@ -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 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';

View File

@ -37,5 +37,8 @@
},
"rain-e": {
"english" : "Unable to fetch weather data."
},
"rain-u": {
"english": "Location too ambigious to process."
}
}