diff --git a/modules/admin/commands.js b/modules/admin/commands.js index 55adce9..edc26d5 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -252,6 +252,7 @@ var commands = function(dbot) { event.reply(dbot.t("no_config_key")); } }); + } else { event.reply(dbot.t("config_keys_location", { "path": "root", 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/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/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. diff --git a/modules/kick/commands.js b/modules/kick/commands.js index d5cd3b3..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, @@ -107,7 +72,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 ***/ @@ -164,6 +133,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]; 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}.\"" diff --git a/run.js b/run.js index aa168ec..2450afb 100644 --- a/run.js +++ b/run.js @@ -143,7 +143,7 @@ DBot.prototype.reloadModules = function() { // Enforce having command. it can still be reloaded, but dbot _will not_ // function without it, so not having it should be impossible - if(!moduleNames.include("command")) { + if(!_.include(moduleNames, 'command')) { moduleNames.push("command"); } diff --git a/snippets.js b/snippets.js index b552bf3..3aca93f 100644 --- a/snippets.js +++ b/snippets.js @@ -1,49 +1,4 @@ -/*** Array ***/ - -Array.prototype.each = function(fun) { - for(var i=0;i