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:
parent
c9161c10ae
commit
178495bd69
@ -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.
|
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
|
### Commands
|
||||||
|
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
"dependencies": [ "command" ],
|
"dependencies": [ "command" ],
|
||||||
"ignorable": true,
|
"ignorable": true,
|
||||||
"help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md",
|
"help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md",
|
||||||
"apikey": "1234567890abcdef"
|
"apikey": "7707e78c7125741e"
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,21 @@ var rain = function(dbot) {
|
|||||||
var commands = {
|
var commands = {
|
||||||
'~rain': function(event) {
|
'~rain': function(event) {
|
||||||
var apikey = dbot.config.rain.apikey;
|
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";
|
var url = "http://api.wunderground.com/api/" + apikey + "/conditions/q/CA/" + place + ".json";
|
||||||
request(url, function(error, response, body) {
|
request(url, function(error, response, body) {
|
||||||
if(response.statusCode == "200") {
|
if(response.statusCode == "200") {
|
||||||
var data = JSON.parse(body);
|
var data = JSON.parse(body);
|
||||||
var precip = data["current_observation"]["precip_1hr_metric"];
|
var obs = data["current_observation"];
|
||||||
var score = 2 * Math.pow(precip,0.5);
|
if (obs) {
|
||||||
score = Math.ceil(score);
|
var precip = obs["precip_1hr_metric"];
|
||||||
if (score > 10) { score = 11; }
|
var score = 2 * Math.pow(precip,0.5);
|
||||||
|
score = Math.ceil(score);
|
||||||
|
if (score > 10) { score = 11; }
|
||||||
|
} else {
|
||||||
|
var score = "u";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var score = "e";
|
var score = "e";
|
||||||
}
|
}
|
||||||
@ -26,6 +32,7 @@ var rain = function(dbot) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
commands['~rain'].regex = [/~rain (.+)/, 2];
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
this.on = 'PRIVMSG';
|
this.on = 'PRIVMSG';
|
||||||
|
|
||||||
|
@ -37,5 +37,8 @@
|
|||||||
},
|
},
|
||||||
"rain-e": {
|
"rain-e": {
|
||||||
"english" : "Unable to fetch weather data."
|
"english" : "Unable to fetch weather data."
|
||||||
|
},
|
||||||
|
"rain-u": {
|
||||||
|
"english": "Location too ambigious to process."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user