Merge branch 'master' of github.com:reality/depressionbot

This commit is contained in:
reality 2013-02-12 17:31:34 +00:00
commit 87387878a7
6 changed files with 113 additions and 3 deletions

View File

@ -295,6 +295,7 @@ var commands = function(dbot) {
commands['reload'].access = 'admin'; commands['reload'].access = 'admin';
commands['unload'].access = 'admin'; commands['unload'].access = 'admin';
commands['load'].access = 'admin'; commands['load'].access = 'admin';
commands['version'].access = 'admin';
commands['setconfig'].access = 'admin'; commands['setconfig'].access = 'admin';
commands['showconfig'].access = 'moderator'; commands['showconfig'].access = 'moderator';
commands['join'].access = 'moderator'; commands['join'].access = 'moderator';

View File

@ -14,7 +14,7 @@ var dent = function(dbot) {
request.post({ request.post({
'url': 'http://identi.ca/api/statuses/update.json?status=' + 'url': 'http://identi.ca/api/statuses/update.json?status=' +
content, escape(content),
'headers': { 'headers': {
'Authorization': auth 'Authorization': auth
} }

16
modules/rain/README.md Normal file
View File

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

6
modules/rain/config.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": [ "command" ],
"ignorable": true,
"help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md",
"apikey": "7707e78c7125741e"
}

43
modules/rain/rain.js Normal file
View File

@ -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);
};

44
modules/rain/strings.json Normal file
View File

@ -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."
}
}