diff --git a/modules/rain/README.md b/modules/rain/README.md new file mode 100644 index 0000000..d6deac9 --- /dev/null +++ b/modules/rain/README.md @@ -0,0 +1,16 @@ +## Rain + +Quietly judges your choice of climate. + +### Description + +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 + +#### ~rain +Polls the rainfall in the last hour, and returns an appropriate string. diff --git a/modules/rain/config.json b/modules/rain/config.json new file mode 100644 index 0000000..f176f2a --- /dev/null +++ b/modules/rain/config.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ "command" ], + "ignorable": true, + "help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md", + "apikey": "7707e78c7125741e" +} diff --git a/modules/rain/rain.js b/modules/rain/rain.js new file mode 100644 index 0000000..f04c381 --- /dev/null +++ b/modules/rain/rain.js @@ -0,0 +1,43 @@ +/** + * Module Name: Rain + * Description: Quietly judges your choice of climate. + */ +var request = require('request'), + _ = require('underscore')._; + +var rain = function(dbot) { + var commands = { + '~rain': function(event) { + var apikey = dbot.config.rain.apikey; + var place = event.input[1]; + if (!place) { var place = "Aberystwyth"; } + var url = "http://api.wunderground.com/api/" + apikey + "/conditions/q/" + place + ".json"; + request(url, function(error, response, body) { + if(response.statusCode == "200") { + var data = JSON.parse(body); + 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"; + } + event.reply(dbot.t("rain-"+score,{"place": place})); + }); + } + }; + + commands['~rain'].regex = [/~rain (.+)/, 2]; + this.commands = commands; + this.on = 'PRIVMSG'; + +}; + +exports.fetch = function(dbot) { + return new rain(dbot); +}; diff --git a/modules/rain/strings.json b/modules/rain/strings.json new file mode 100644 index 0000000..60904e6 --- /dev/null +++ b/modules/rain/strings.json @@ -0,0 +1,44 @@ + { + "rain-0": { + "english" : "It's not raining in {place}." + }, + "rain-1": { + "english" : "It's raining in {place}." + }, + "rain-2": { + "english" : "It's raining rather a lot in {place}." + }, + "rain-3": { + "english" : "It's raining shitloads." + }, + "rain-4": { + "english" : "It's raining fucktons." + }, + "rain-5": { + "english" : "It's raining whales (in {place})!" + }, + "rain-6": { + "english" : "IT'S SO FUCKING WET OUT HERE MAN" + }, + "rain-7": { + "english" : "I AM SO MOIST RIGHT NOW" + }, + "rain-8": { + "english" : "You used a #3 pencil instead of #2, didn't you?" + }, + "rain-9": { + "english" : "WELCOME TO ATLANTIS" + }, + "rain-10": { + "english" : "GET INSIDE" + }, + "rain-11": { + "english" : "LOL U PROBABLY DIED" + }, + "rain-e": { + "english" : "Unable to fetch weather data." + }, + "rain-u": { + "english": "Location too ambigious to process." + } +}