From 2b57300f65a9e0e321b1ac7262180643befcc3dc Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 08:15:16 +0000 Subject: [PATCH 1/8] Fix [#443] --- modules/admin/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/admin/commands.js b/modules/admin/commands.js index 2680b40..00c4185 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -253,7 +253,7 @@ var commands = function(dbot) { if(configPathString) { var configKey = _.last(configPathString.split('.')); - if(configKey) { + if(!configKey) { event.reply(dbot.t("no_config_path")); return; } From be7d5a41cdb2318c884be8ccfc814d9eda96f9d7 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 08:52:24 +0000 Subject: [PATCH 2/8] use current channel if no admin channel defined [#261] --- modules/kick/commands.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index d5cd3b3..7f9f671 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -107,7 +107,11 @@ var commands = function(dbot) { notifyString += ' ' + dbot.t('quote_recorded', { 'user': banee }); } - dbot.api.report.notify(server, this.config.admin_channels[event.server], notifyString); + var notifyChannel = event.channel.name; + if(this.config.admin_channels[event.server]) { + notifyChannel = this.config.admin_channels[event.server]; + } + dbot.api.report.notify(server, notifyChannel, notifyString); }, /*** Kick Stats ***/ From 53b7bbe5a819ca710711d3e4b887d17acda80f78 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 08:58:11 +0000 Subject: [PATCH 3/8] kickcount and kickstats do not need elevated access [#261] --- modules/kick/commands.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 7f9f671..28eab89 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -168,6 +168,9 @@ var commands = function(dbot) { command.access = 'moderator'; }); + commands['~kickcount'].access = 'regular'; + commands['~kickstats'].access = 'regular'; + commands['~ckick'].regex = [/^~ckick ([^ ]+) ([^ ]+) (.+)$/, 4]; commands['~nban'].regex = [/^~nban ([^ ]+) (.+)$/, 3]; From 28825fd22b2897dbd4884b42e7ae50d04e99e37a Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 09:06:55 +0000 Subject: [PATCH 4/8] clean [#261] up enough for 0.4 --- modules/kick/commands.js | 35 ----------------------------------- modules/kick/strings.json | 8 +++++--- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 28eab89..75fed4c 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -39,41 +39,6 @@ var commands = function(dbot) { })); }, - /*'~cquiet': function(event) { - var server = event.server, - quieter = event.user, - quietee = event.input[2], - channel = event.input[1], - reason = event.input[3]; - - this.api.quiet(server, quietee, channel); - - dbot.api.report(server, channel, dbot.t('cquieted', { - 'quieter': quieter, - 'quietee': quietee, - 'channel': channel, - 'reason': reason - })); - }, - - '~nquiet': function(event) { - var server = event.server, - quieter = event.user, - quietee = event.input[1], - channels = dbot.config.servers[server].channels, - reason = event.input[2]; - - _.each(channels, function(channel) { - this.api.quiet(server, quietee, channel); - }, this); - - dbot.api.report(server, channel, dbot.t('nquieted', { - 'quieter': quieter, - 'quietee': quietee, - 'reason': reason - })); - },*/ - // Kick and ban from all channels on the network. '~nban': function(event) { var server = event.server, diff --git a/modules/kick/strings.json b/modules/kick/strings.json index f71fd0e..cd527d9 100644 --- a/modules/kick/strings.json +++ b/modules/kick/strings.json @@ -10,12 +10,14 @@ "en": "Thou shalt not kick {botname}", "es": "No expulsás {botname}", "na'vi": "Ngal {botname}it ke tsun tsrive'i", - "cy": "Ni ddylech cicio {botname}" + "cy": "Ni ddylech cicio {botname}", + "nl": "Gij zult {botname} niet kicken" }, "ckicked": { "en": "Attention: {kicker} has kicked {kickee} from {channel}. The reason given was: \"{reason}.\"", - "cy": "Ni ddylech cicio {botname}", - "nl": "Gij zult {botname} niet kicken" + }, + "cbanned": { + "en": "Attention: {banner} has banned {banee} from {channel}. The reason given was \"{reason}.\"" }, "nbanned": { "en": "Attention: {banner} has banned {banee} network-wide. The reason given was \"{reason}.\"" From 7713169721f326e940458ca16b9d4fe2b85faf2e Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 09:59:25 +0000 Subject: [PATCH 5/8] help for api module [#352] --- modules/api/README.md | 45 +++++++++++++++++++++++++++++++++++++++++ modules/web/config.json | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 modules/api/README.md diff --git a/modules/api/README.md b/modules/api/README.md new file mode 100644 index 0000000..4ebb156 --- /dev/null +++ b/modules/api/README.md @@ -0,0 +1,45 @@ +## API + +Creates external REST APIs for module API functions. + +### Description + +This module uses the web module to expose module API functionality externally +through a REST API. As it stands, it's only really useful for viewing various +information returned by API functions, as there is no system for API keys or +anything like that to protect against misuse of functionality which modifies +data. + +To externalise an API function, two properties must be set on a particular API +function, like so: + + api['resolveUser'].external = true; + api['resolveUser'].extMap = [ 'server', 'nick', 'callback' ]; + +The first, 'external' flag simply lets the API module know that this function is +intended to be exposed externally - and functions will always be considered not +to be externally available unless this flag is explicitly set. + +The second is a mapping of parameters to the module. This should match the +function prototype given when the function is declared (unfortunately these +can't be mapped automatically because the closure use means we get 'native code' +returned and can't scan the function headers for the parameter names). + +Then, to access this function remotely we can simply make a GET request to the +web counterpart to the internal API function path. So, internally you'd access +the resolveUser function at _dbot.api.users.resolveUser_, we can get to it +externally with _/api/users/resolveUser_ - supplying parameters as they are +named in the extMap. + +The response to the API call will be given in the form of JSON: + + { + err: Error, such as 'API function not enabled for external access' + data: API call response + } + +If there is a _callback_ parameter named in the extMap, then the API module +automatically hijacks this parameter and uses the data it's called with to +supply the response to the API call with data. If there is no callback +parameter, then it's a blocking API request and the response will be the return +value of the call. diff --git a/modules/web/config.json b/modules/web/config.json index e6b635e..d49b7e6 100644 --- a/modules/web/config.json +++ b/modules/web/config.json @@ -1,6 +1,6 @@ { "webHost": "nourishedcloud.com", - "webPort": 8080, + "webPort": 8050, "externalPath": false, "help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md" } From da3e99dd90a98829965dc4d7132f61902b6aa7fb Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 10:00:39 +0000 Subject: [PATCH 6/8] ffs --- modules/web/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/web/config.json b/modules/web/config.json index d49b7e6..e6b635e 100644 --- a/modules/web/config.json +++ b/modules/web/config.json @@ -1,6 +1,6 @@ { "webHost": "nourishedcloud.com", - "webPort": 8050, + "webPort": 8080, "externalPath": false, "help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md" } From f4f34d285235d6e39723f9da5841f48fbacab1da Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 11:28:04 +0000 Subject: [PATCH 7/8] documentation for imgur [#352] --- modules/imgur/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/imgur/README.md diff --git a/modules/imgur/README.md b/modules/imgur/README.md new file mode 100644 index 0000000..7e08b5d --- /dev/null +++ b/modules/imgur/README.md @@ -0,0 +1,34 @@ +## imgur + +Various imgur functionality. + +### Description + +Posts information on imgur links which are pasted into the channel and provides +functionality to generate a random imgur link. + +### Commands + +#### ~ri +Generate a random imgur image and post a link to it in the channel. + +### API + +#### getRandomImage(callback) +Generate a random imgur image by generating random slugs and then testing for +their existence until it finds one which exists (and hasn't been deleted). +Callback is given with two parameters, the URL of the generated image, and the +slug for the generated image. + +#### getImageInfoString(slug, callback) +Return a string containing info about the image with the given slug from the +imgur API. Callback is called with one argument, the info string. + +#### getImageInfo(slug, callback) +Return data from the imgur API on an image with the given slug. Callback is +called with one argument, the information returned by the API. + +### Hooks + +#### link +Posts information about an imgur link when one is linked in the channel. From 15fd9c32e4d49111ef2504a388bca6c008bb3a72 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 17 May 2013 13:29:28 +0000 Subject: [PATCH 8/8] Initial go at [#448] --- modules/api/api.js | 16 ++++++++++++++++ views/api/api.jade | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 views/api/api.jade diff --git a/modules/api/api.js b/modules/api/api.js index 1c10b98..408dc0a 100644 --- a/modules/api/api.js +++ b/modules/api/api.js @@ -5,6 +5,22 @@ var _ = require('underscore')._; var api = function(dbot) { + this.pages = { + '/api': function(req, res) { + var externalApi = {}; + _.each(dbot.api, function(moduleApi, moduleName) { + externalApi[moduleName] = {}; + _.each(moduleApi, function(method, methodName) { + if(method.external == true) { + externalApi[moduleName][methodName] = method.extMap; + } + }); + }); + + res.render('api', { 'name': dbot.config.name, 'api': externalApi }); + } + }; + this.onLoad = function() { dbot.modules.web.app.get('/api/:module/:method', function(req, res) { var module = req.params.module, diff --git a/views/api/api.jade b/views/api/api.jade new file mode 100644 index 0000000..895c272 --- /dev/null +++ b/views/api/api.jade @@ -0,0 +1,21 @@ +extends ../layout + +block content + div#backlink + a(href='/') « Home + div#row + h4 External API Functions + div#row + table.tabe.table-hover.data + thead + tr + th Module + th Path + th Arguments + tbody + -each module,moduleName in api + -each func,funcName in api[moduleName] + tr + td #{moduleName} + td /api/#{moduleName}/#{funcName} + td #{func}