From e1f4d0c200e5718256f04c35db7fc4f5019b81a1 Mon Sep 17 00:00:00 2001 From: Dafydd Francis Date: Fri, 21 Dec 2012 14:10:21 +0000 Subject: [PATCH 01/11] Update modules/js/js.js jesus --- modules/js/js.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/js/js.js b/modules/js/js.js index 76d5f91..d6f5dd1 100644 --- a/modules/js/js.js +++ b/modules/js/js.js @@ -28,10 +28,14 @@ var js = function(dbot) { event.reply(ret); } } + }, + 'jesus': function (event) { + event.reply(event.user + ": s/(.)(.)(.)(..)/\4\2 \1\3/") } }; commands['~js'].regex = [/^~js (.*)/, 2]; commands['~ajs'].regex = [/^~ajs (.*)/, 2]; + commands['jesus'].regex = [/^jesus$/, 2]; return { 'name': 'js', From 0a63518b624bb8ec123ff17aaba8e8f58baf8f96 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:12:10 +0000 Subject: [PATCH 02/11] Add beginnings of a reworked ~isitraining --- modules/rain/README.md | 23 +++++++++++++++++++++++ modules/rain/config.json | 6 ++++++ modules/rain/rain.js | 29 +++++++++++++++++++++++++++++ modules/rain/strings.json | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 modules/rain/README.md create mode 100644 modules/rain/config.json create mode 100644 modules/rain/rain.js create mode 100644 modules/rain/strings.json diff --git a/modules/rain/README.md b/modules/rain/README.md new file mode 100644 index 0000000..24c52d0 --- /dev/null +++ b/modules/rain/README.md @@ -0,0 +1,23 @@ +## Link + +Retrieves page titles. + +### Description + +This module stores the last posted link in each channel, and provides a command +for retrieving the title of a given link or the last posted link in the channel. + +### Configuration + +#### autoTitle: false +If this is set to true, the bot will automatically post the titles of links as +they are posted in the channel. + +### Commands + +#### ~title [link] +If called with a link, the bot will attempt to find and return the title of that +page. If called without a link, the bot will attempt the same on the last link +which was posted in the current channel. +#### ~ud [headword] +Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided. diff --git a/modules/rain/config.json b/modules/rain/config.json new file mode 100644 index 0000000..9c3dc3e --- /dev/null +++ b/modules/rain/config.json @@ -0,0 +1,6 @@ +{ + "autoTitle": false, + "dependencies": [ "command" ], + "ignorable": true, + "help": "http://github.com/reality/depressionbot/blob/master/modules/link/README.md" +} diff --git a/modules/rain/rain.js b/modules/rain/rain.js new file mode 100644 index 0000000..55104d1 --- /dev/null +++ b/modules/rain/rain.js @@ -0,0 +1,29 @@ +/** + * Module Name: Link + * Description: Stores recent channel links, with commands to retrieve + * information about links. + */ +var request = require('request'), + _ = require('underscore')._; + +var rain = function(dbot) { + var commands = { + '~rain': function(event) { + var precip = event.params[1]; + var score = 2 * Math.pow(precip,0.5); + score = Math.ceil(score); + if (score > 10) e + score = 11; + } + event.reply(dbot.t("rain-"+score) + " [ " + score + "]"); + } + }; + + 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..5100e0b --- /dev/null +++ b/modules/rain/strings.json @@ -0,0 +1,38 @@ + { + "rain-0": { + "english" : "It's not raining." + }, + "rain-1": { + "english" : "It's raining." + }, + "rain-2": { + "english" : "It's raining rather a lot." + }, + "rain-3": { + "english" : "It's raining shitloads." + }, + "rain-4": { + "english" : "It's raining fucktons." + }, + "rain-5": { + "english" : "It's raining whales (in Wales)!" + }, + "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" + } +} From 251d69194b011390bee97991be296adfd757f433 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:21:46 +0000 Subject: [PATCH 03/11] Update documentation; contract if statement --- modules/rain/README.md | 20 +++++--------------- modules/rain/config.json | 3 +-- modules/rain/rain.js | 11 ++++------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/modules/rain/README.md b/modules/rain/README.md index 24c52d0..547a252 100644 --- a/modules/rain/README.md +++ b/modules/rain/README.md @@ -1,23 +1,13 @@ -## Link +## Rain -Retrieves page titles. +Quietly judges your choice of climate. ### Description -This module stores the last posted link in each channel, and provides a command -for retrieving the title of a given link or the last posted link in the channel. +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 - -#### autoTitle: false -If this is set to true, the bot will automatically post the titles of links as -they are posted in the channel. ### Commands -#### ~title [link] -If called with a link, the bot will attempt to find and return the title of that -page. If called without a link, the bot will attempt the same on the last link -which was posted in the current channel. -#### ~ud [headword] -Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided. +#### ~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 index 9c3dc3e..eb3ca8c 100644 --- a/modules/rain/config.json +++ b/modules/rain/config.json @@ -1,6 +1,5 @@ { - "autoTitle": false, "dependencies": [ "command" ], "ignorable": true, - "help": "http://github.com/reality/depressionbot/blob/master/modules/link/README.md" + "help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md" } diff --git a/modules/rain/rain.js b/modules/rain/rain.js index 55104d1..81b6feb 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -1,7 +1,6 @@ /** - * Module Name: Link - * Description: Stores recent channel links, with commands to retrieve - * information about links. + * Module Name: Rain + * Description: Quietly judges your choice of climate. */ var request = require('request'), _ = require('underscore')._; @@ -12,10 +11,8 @@ var rain = function(dbot) { var precip = event.params[1]; var score = 2 * Math.pow(precip,0.5); score = Math.ceil(score); - if (score > 10) e - score = 11; - } - event.reply(dbot.t("rain-"+score) + " [ " + score + "]"); + if (score > 10) { score = 11; } + event.reply(dbot.t("rain-"+score)); } }; From e1a8360b277c0b8ffd1da3698dbeae6af35a8a1b Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:27:08 +0000 Subject: [PATCH 04/11] add api key to config --- modules/rain/config.json | 3 ++- modules/rain/rain.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/rain/config.json b/modules/rain/config.json index eb3ca8c..e222ae7 100644 --- a/modules/rain/config.json +++ b/modules/rain/config.json @@ -1,5 +1,6 @@ { "dependencies": [ "command" ], "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" } diff --git a/modules/rain/rain.js b/modules/rain/rain.js index 81b6feb..c6f2165 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -8,6 +8,7 @@ var request = require('request'), var rain = function(dbot) { var commands = { '~rain': function(event) { + var apikey = dbot.config.rain.apikey; var precip = event.params[1]; var score = 2 * Math.pow(precip,0.5); score = Math.ceil(score); From 0e9827a2fc18e9d482f3032333c726e62b6adf5b Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:38:27 +0000 Subject: [PATCH 05/11] further development was precipitated --- modules/rain/rain.js | 19 ++++++++++++++----- modules/rain/strings.json | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/rain/rain.js b/modules/rain/rain.js index c6f2165..5af0b5c 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -9,11 +9,20 @@ var rain = function(dbot) { var commands = { '~rain': function(event) { var apikey = dbot.config.rain.apikey; - var precip = event.params[1]; - var score = 2 * Math.pow(precip,0.5); - score = Math.ceil(score); - if (score > 10) { score = 11; } - event.reply(dbot.t("rain-"+score)); + var place = "Aberystwyth"; // you probably need to change the formulae if you change location + 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["precip_1hr_metric"]; + var score = 2 * Math.pow(precip,0.5); + score = Math.ceil(score); + if (score > 10) { score = 11; } + } else { + var score = "e"; + } + event.reply(dbot.t("rain-"+score+"[ " + score + " ]")); + }); } }; diff --git a/modules/rain/strings.json b/modules/rain/strings.json index 5100e0b..bd5a5a2 100644 --- a/modules/rain/strings.json +++ b/modules/rain/strings.json @@ -34,5 +34,8 @@ }, "rain-11": { "english" : "LOL U PROBABLY DIED" + }, + "rain-e": { + "english" : "Unable to fetch weather data." } } From c9161c10ae6cdd99b129cbbe3487b08da291ab5e Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:43:17 +0000 Subject: [PATCH 06/11] it was raining cats and dogs; there were poodles all over the road --- modules/rain/rain.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/rain/rain.js b/modules/rain/rain.js index 5af0b5c..ca6a38c 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -14,14 +14,14 @@ var rain = function(dbot) { request(url, function(error, response, body) { if(response.statusCode == "200") { var data = JSON.parse(body); - var precip = data["precip_1hr_metric"]; + var precip = data["current_observation"]["precip_1hr_metric"]; var score = 2 * Math.pow(precip,0.5); score = Math.ceil(score); if (score > 10) { score = 11; } } else { var score = "e"; } - event.reply(dbot.t("rain-"+score+"[ " + score + " ]")); + event.reply(dbot.t("rain-"+score)); }); } }; From 178495bd696dc87d84e971b10e4e4faf4ce68035 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 13:29:49 +0000 Subject: [PATCH 07/11] WHY DOES THE RAIN GO DOWN NOT UP --- modules/rain/README.md | 3 +++ modules/rain/config.json | 2 +- modules/rain/rain.js | 17 ++++++++++++----- modules/rain/strings.json | 3 +++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/rain/README.md b/modules/rain/README.md index 547a252..d6deac9 100644 --- a/modules/rain/README.md +++ b/modules/rain/README.md @@ -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 diff --git a/modules/rain/config.json b/modules/rain/config.json index e222ae7..f176f2a 100644 --- a/modules/rain/config.json +++ b/modules/rain/config.json @@ -2,5 +2,5 @@ "dependencies": [ "command" ], "ignorable": true, "help": "http://github.com/reality/depressionbot/blob/master/modules/rain/README.md", - "apikey": "1234567890abcdef" + "apikey": "7707e78c7125741e" } diff --git a/modules/rain/rain.js b/modules/rain/rain.js index ca6a38c..2b48433 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -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 score = 2 * Math.pow(precip,0.5); - score = Math.ceil(score); - if (score > 10) { score = 11; } + 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'; diff --git a/modules/rain/strings.json b/modules/rain/strings.json index bd5a5a2..1f04bf8 100644 --- a/modules/rain/strings.json +++ b/modules/rain/strings.json @@ -37,5 +37,8 @@ }, "rain-e": { "english" : "Unable to fetch weather data." + }, + "rain-u": { + "english": "Location too ambigious to process." } } From 3f2bb2bde1f26375e85138d2740b82543f7d1c0e Mon Sep 17 00:00:00 2001 From: Dafydd Francis Date: Wed, 30 Jan 2013 22:13:08 +0000 Subject: [PATCH 08/11] Just wanna post hashtags #yolo --- modules/dent/dent.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); From f4a118db89855681c4b60811f35f987648758316 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Thu, 7 Feb 2013 16:47:05 +0000 Subject: [PATCH 09/11] complete module --- modules/rain/rain.js | 4 ++-- modules/rain/strings.json | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/rain/rain.js b/modules/rain/rain.js index 2b48433..f04c381 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -11,7 +11,7 @@ var rain = function(dbot) { 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/CA/" + place + ".json"; + 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); @@ -27,7 +27,7 @@ var rain = function(dbot) { } else { var score = "e"; } - event.reply(dbot.t("rain-"+score)); + event.reply(dbot.t("rain-"+score,{"place": place})); }); } }; diff --git a/modules/rain/strings.json b/modules/rain/strings.json index 1f04bf8..60904e6 100644 --- a/modules/rain/strings.json +++ b/modules/rain/strings.json @@ -1,12 +1,12 @@ { "rain-0": { - "english" : "It's not raining." + "english" : "It's not raining in {place}." }, "rain-1": { - "english" : "It's raining." + "english" : "It's raining in {place}." }, "rain-2": { - "english" : "It's raining rather a lot." + "english" : "It's raining rather a lot in {place}." }, "rain-3": { "english" : "It's raining shitloads." @@ -15,7 +15,7 @@ "english" : "It's raining fucktons." }, "rain-5": { - "english" : "It's raining whales (in Wales)!" + "english" : "It's raining whales (in {place})!" }, "rain-6": { "english" : "IT'S SO FUCKING WET OUT HERE MAN" From 7053b34bc46b2caf2ae3b023038b9fc07a64f64e Mon Sep 17 00:00:00 2001 From: Dafydd Francis Date: Mon, 11 Feb 2013 16:12:44 +0000 Subject: [PATCH 10/11] Update modules/js/js.js --- modules/js/js.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/js/js.js b/modules/js/js.js index 430ba66..d6094ff 100644 --- a/modules/js/js.js +++ b/modules/js/js.js @@ -25,14 +25,10 @@ var js = function(dbot) { if(ret !== undefined) { event.reply(ret); } - }, - 'jesus': function (event) { - event.reply(event.user + ": s/(.)(.)(.)(..)/\4\2 \1\3/") } }; commands['~js'].regex = [/^~js (.*)/, 2]; commands['~ajs'].regex = [/^~ajs (.*)/, 2]; - commands['jesus'].regex = [/^jesus$/, 2]; commands['~ajs'].access = 'admin'; this.name = 'js'; From 532b1daaa6f6f97c2a2bf414b0de2bbc4a280e2c Mon Sep 17 00:00:00 2001 From: Sam Nicholls Date: Mon, 11 Feb 2013 16:36:01 +0000 Subject: [PATCH 11/11] Restrict version command to admin --- modules/admin/commands.js | 1 + 1 file changed, 1 insertion(+) 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';