diff --git a/modules/admin/commands.js b/modules/admin/commands.js index a5d3719..c648760 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -295,6 +295,7 @@ var commands = function(dbot) { commands['reload'].access = 'admin'; commands['unload'].access = 'admin'; commands['load'].access = 'admin'; + commands['version'].access = 'admin'; commands['setconfig'].access = 'admin'; commands['showconfig'].access = 'moderator'; commands['join'].access = 'moderator'; diff --git a/modules/dent/dent.js b/modules/dent/dent.js index 8ee57e0..5638ccc 100644 --- a/modules/dent/dent.js +++ b/modules/dent/dent.js @@ -9,12 +9,12 @@ var dent = function(dbot) { var username = dbot.config.dent.username, password = dbot.config.dent.password, info, - auth = "Basic " + + auth = "Basic " + new Buffer(username + ":" + password).toString("base64"); request.post({ 'url': 'http://identi.ca/api/statuses/update.json?status=' + - content, + escape(content), 'headers': { 'Authorization': auth } @@ -36,7 +36,7 @@ var dent = function(dbot) { this.onLoad = function() { if(dbot.config.dent.dentQuotes === true && _.has(dbot.modules, 'quotes')) { dbot.api.command.addHook('~qadd', function(key, text) { - this.api.post(key + ': ' + text); + this.api.post(key + ': ' + text); }.bind(this)); } }.bind(this); 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." + } +}