diff --git a/install.sh b/install.sh index dd90ab1..d9cb7fc 100755 --- a/install.sh +++ b/install.sh @@ -14,7 +14,7 @@ then exit 1 fi -npm install node-uuid underscore request sandbox express moment jade databank databank-redis ent +npm install wordnik node-uuid underscore request sandbox express moment jade databank databank-redis ent cd public/ wget http://twitter.github.com/bootstrap/assets/bootstrap.zip diff --git a/modules/command/commands.js b/modules/command/commands.js index 5f5e079..5bf355b 100644 --- a/modules/command/commands.js +++ b/modules/command/commands.js @@ -17,6 +17,24 @@ var commands = function(dbot) { } }, + '~commands': function(event) { + var name = event.params[1]; + if(_.has(dbot.modules, name)) { + var commands = _.keys(dbot.commands); + commands = _.filter(commands, function(cName) { + return dbot.commands[cName].module == name; + }); + event.reply(dbot.t('module_commands', { + 'module': name, + 'commands': commands.join(', ') + })); + } else { + event.reply(dbot.t('loaded_modules', { + 'modules': _.keys(dbot.modules).join(', ') + })); + } + }, + '~help': function(event) { var moduleName = event.params[1]; if(!moduleName || !_.has(dbot.modules, moduleName)) { diff --git a/modules/command/strings.json b/modules/command/strings.json index 2c74944..62738db 100644 --- a/modules/command/strings.json +++ b/modules/command/strings.json @@ -51,5 +51,8 @@ }, "access_denied": { "en": "{user}: You don't have the access level to run this command." + }, + "module_commands": { + "en": "Commands in {module}: {commands}." } } diff --git a/modules/kick/README.md b/modules/kick/README.md index b3aa217..3da8b6c 100644 --- a/modules/kick/README.md +++ b/modules/kick/README.md @@ -15,3 +15,15 @@ people. #### ~kickstats Show a list of top kickers and kickees. + +#### ~ckick [#channel] [username] [reason] +Kick a user from a channel. + +#### ~cban [#channel] [username] [reason] +Ban a user from a channel. + +#### ~nban {optional: Duration in Hours} [username] [reason] +Ban a user from the network. + +#### ~nunban [username] [reason] +Unban a user from the network. diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 29df25f..c64aa46 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -41,49 +41,128 @@ var commands = function(dbot) { // Kick and ban from all channels on the network. '~nban': function(event) { + if(!event.input) return; + var server = event.server, banner = event.user, - banee = event.input[1], - reason = event.input[2], - channels = dbot.config.servers[server].channels; + timeout = event.input[1], + banee = event.input[2], + reason = event.input[3], + adminChannel = this.config.admin_channel[event.server]; + channels = dbot.config.servers[server].channels, + network = event.server; - var i = 0; - var banChannel = function(channels) { - if(i >= channels.length) return; - var channel = channels[i]; - this.api.ban(server, banee, channel); - this.api.kick(server, banee, channel, reason + - ' (network-wide ban requested by ' + banner + ')'); - setTimeout(function() { - i++; banChannel(channels); - }, 1000); - }.bind(this); - banChannel(channels); + if(this.config.network_name[event.server]) { + network = this.config.network_name[event.server]; + } + console.log(timeout); + console.log(banee); + console.log(reason); - var notifyString = dbot.t('nbanned', { - 'banner': banner, - 'banee': banee, - 'reason': reason + dbot.api.nickserv.getUserHost(event.server, banee, function(host) { + // Add host record entry + if(host) { + if(!_.has(this.hosts, event.server)) this.hosts[event.server] = {}; + this.hosts[event.server][banee] = host; + + // Create notify string + if(!_.isUndefined(timeout)) { + timeout = parseFloat(timeout.trim()); + + var msTimeout = new Date(new Date().getTime() + (timeout * 3600000)); + if(!_.has(this.tempBans, event.server)) this.tempBans[event.server] = {}; + this.tempBans[event.server][banee] = msTimeout; + this.internalAPI.addTempBan(event.server, banee, msTimeout); + + var notifyString = dbot.t('tbanned', { + 'network': network, + 'banner': banner, + 'banee': banee, + 'hours': timeout, + 'reason': reason + }); + var quoteString = dbot.t('tban_quote', { + 'banee': banee, + 'banner': banner, + 'hours': timeout, + 'time': new Date().toUTCString(), + 'reason': reason + }); + } else { + var notifyString = dbot.t('nbanned', { + 'network': network, + 'banner': banner, + 'banee': banee, + 'reason': reason + }); + var quoteString = dbot.t('nban_quote', { + 'banee': banee, + 'banner': banner, + 'time': new Date().toUTCString(), + 'reason': reason + }); + } + + // Add qutoe category documenting ban + if(this.config.document_bans && _.has(dbot.modules, 'quotes')) { + dbot.db.quoteArrs['ban_' + banee.toLowerCase()] = [ quoteString ]; + notifyString += ' ' + dbot.t('quote_recorded', { 'user': banee }); + } + + // Notify moderators, banee + if(this.config.admin_channel[event.server]) { + channels = _.without(channels, adminChannel); + + dbot.api.report.notify(server, adminChannel, notifyString); + dbot.say(event.server, adminChannel, notifyString); + + if(!_.isUndefined(timeout)) { + dbot.say(event.server, banee, dbot.t('tbanned_notify', { + 'network': network, + 'banner': banner, + 'reason': reason, + 'hours': timeout, + 'admin_channel': adminChannel + })); + } else { + dbot.say(event.server, banee, dbot.t('nbanned_notify', { + 'network': network, + 'banner': banner, + 'reason': reason, + 'hours': timeout, + 'admin_channel': adminChannel + })); + } + } + + // Ban the user from all channels + var i = 0; + var banChannel = function(channels) { + if(i >= channels.length) return; + var channel = channels[i]; + this.api.ban(server, banee, channel); + this.api.kick(server, banee, channel, reason + + ' (network-wide ban requested by ' + banner + ')'); + setTimeout(function() { + i++; banChannel(channels); + }, 1000); + }.bind(this); + banChannel(channels); + } else { + event.reply(dbot.t('no_user', { 'user': banee })); + } + }.bind(this)); + }, + + '~nunban': function(event) { + var unbanee = event.params[1], + unbanner = event.user; + + this.api.networkUnban(event.server, unbanee, unbanner, function(err) { + if(err) { + event.reply(dbot.t('nunban_error', { 'unbanee': unbanee })); + } }); - - // TODO: When this is merged into database branch, have it use the - // api.quotes.addQuote function - if(this.config.document_bans && _.has(dbot.modules, 'quotes')) { - dbot.db.quoteArrs['ban_' + banee] = [ dbot.t('nban_quote', { - 'banee': banee, - 'banner': banner, - 'time': new Date().toUTCString(), - 'reason': reason - }) ]; - - notifyString += ' ' + dbot.t('quote_recorded', { 'user': banee }); - } - - 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 ***/ @@ -144,7 +223,7 @@ var commands = function(dbot) { commands['~kickstats'].access = 'regular'; commands['~ckick'].regex = [/^~ckick ([^ ]+) ([^ ]+) (.+)$/, 4]; - commands['~nban'].regex = [/^~nban ([^ ]+) (.+)$/, 3]; + commands['~nban'].regex = /^~nban ([\d\.^ ]+)?([^ ]+) (.+)$/; return commands; }; diff --git a/modules/kick/config.json b/modules/kick/config.json index ce9638e..2ea10c4 100644 --- a/modules/kick/config.json +++ b/modules/kick/config.json @@ -1,11 +1,14 @@ { - "dbKeys": [ "kicks", "kickers" ], + "dbKeys": [ "kicks", "kickers", "hosts", "tempBans" ], "dependencies": [ "command", "report", "users" ], "ignorable": true, "countSilently": true, - "admin_channels": { + "admin_channel": { "aberwiki": "#fishbox" }, + "network_name": { + "aberwiki": "OAOSIDL" + }, "chanserv": "ChanServ", "document_bans": false } diff --git a/modules/kick/kick.js b/modules/kick/kick.js index 7b3d160..6197b0d 100644 --- a/modules/kick/kick.js +++ b/modules/kick/kick.js @@ -1,20 +1,88 @@ var _ = require('underscore')._; var kick = function(dbot) { + this.hosts = dbot.db.hosts; + this.tempBans = dbot.db.tempBans; this.api = { 'ban': function(server, user, channel) { - dbot.say(event.server, this.config.chanserv, 'ban ' + user); + dbot.say(server, this.config.chanserv, 'ban ' + channel + ' ' + user); }, 'quiet': function(server, user, channel) { - dbot.say(event.server, this.config.chanserv, 'quiet ' + user); + dbot.say(server, this.config.chanserv, 'quiet ' + channel + ' ' + user); }, 'kick': function(server, user, channel, msg) { dbot.instance.connections[server].send('KICK ' + channel + ' ' + user + ' :' + msg); + }, + + 'unban': function(server, host, channel) { + dbot.say(server, this.config.chanserv, 'unban ' + channel + ' *!*@' + host); + }, + + 'networkUnban': function(server, unbanee, unbanner, callback) { + var channels = dbot.config.servers[server].channels, + network = this.config.network_name[server] || server, + adminChannel = this.config.admin_channel[server]; + + if(_.has(this.hosts, server) && _.has(this.hosts[server], unbanee)) { + var host = this.hosts[server][unbanee]; + + // Notify Staff + if(!_.isUndefined(adminChannel)) { + var notifyString = dbot.t('nunbanned', { + 'network': network, + 'unbanee': unbanee, + 'unbanner': unbanner + }); + dbot.api.report.notify(server, adminChannel, notifyString); + dbot.say(server, adminChannel, notifyString); + } + + // Notify Unbanee + dbot.say(server, unbanee, dbot.t('nunban_notify', { + 'network': network, + 'unbanee': unbanee, + 'unbanner': unbanner + })); + + // Unban + var i = 0; + var unbanChannel = function(channels) { + if(i >= channels.length) return; + var channel = channels[i]; + this.api.unban(server, host, channel); + setTimeout(function() { + i++; unbanChannel(channels); + }, 1000); + }.bind(this); + unbanChannel(channels); + + callback(null); // Success + } else { + // Attempt to look up the host on-the-fly + dbot.api.nickserv.getUserHost(server, unbanee, function(host) { + if(host) { + if(!_.has(this.hosts, server)) this.hosts[server] = {}; + this.hosts[server][unbanee] = host; + this.api.networkUnban(server, unbanee, unbanner); + } else { + callback(true); // No host could be found + } + }); + } } }; + + this.internalAPI = { + 'addTempBan': function(server, banee, timeout) { + dbot.api.timers.addTimeout(timeout, function() { + this.api.networkUnban(server, banee, dbot.config.name, function(err) {}); + delete this.tempBans[server][banee]; + }.bind(this)); + }.bind(this) + }; this.listener = function(event) { if(event.kickee == dbot.config.name) { @@ -44,6 +112,15 @@ var kick = function(dbot) { } }.bind(this); this.on = 'KICK'; + + this.onLoad = function() { + _.each(this.tempBans, function(bans, server) { + _.each(bans, function(timeout, nick) { + timeout = new Date(timeout); + this.internalAPI.addTempBan(server, nick, timeout); + }, this); + }, this); + }.bind(this); }; exports.fetch = function(dbot) { diff --git a/modules/kick/strings.json b/modules/kick/strings.json index 4d0081f..07d8064 100644 --- a/modules/kick/strings.json +++ b/modules/kick/strings.json @@ -25,16 +25,37 @@ "cy": "Sylw: {banner} wedi gwahardd {banee} o {channel}. Y rheswm a roddwyd oedd: \"{reason}.\"", "de": "Achtung: {banner} hat {banee} von {channel} gebannt. Grund: \"{reason}.\"" }, + "tbanned": { + "en": "Attention: {banner} has banned {banee} from the {network} network for {hours} hours. The reason given was \"{reason}.\"" + }, + "tbanned_notify": { + "en": "You have been banned from the {network} network for {hours} hours by {banner}. The reason given was \"{reason}.\" You can join {admin_channel} for more information or to discuss the ban." + }, "nbanned": { - "en": "Attention: {banner} has banned {banee} network-wide. The reason given was \"{reason}.\"", + "en": "Attention: {banner} has banned {banee} from the {network} network. The reason given was \"{reason}.\"", "cy": "Sylw: {banner} wedi gwahardd {banee} ledled y rhwydwaith. Y rheswm a roddwyd oedd: \"{reason}.\"", "de": "Achtung: {banner} hat {banee} auf dem gesamten Netzwerk gebannt. Grund: \"{reason}.\"" }, + "nbanned_notify": { + "en": "You have been banned from the {network} network by {banner}. The reason given was \"{reason}.\" You can join {admin_channel} for more information or to discuss the ban." + }, "nban_quote": { "en": "{banee} was banned from the network by {banner} on {time}. The reason given was \"{reason}.\"", "cy": "Cafodd {banee} ei wahardd o'r rhwydwaith gan {banner} ar {time}. Y rheswm a roddwyd oedd: \"{reason}.\"", "de": "{banee} wurde von {banner} auf dem gesamten Netzwerk um {time} gebannt. Grund: \"{reason}.\"" }, + "no_user": { + "en": "{user} doesn't seem to be online on this server." + }, + "nunbanned": { + "en": "Attention: {unbanee} has been unbanned from the {network} network by {unbanner}." + }, + "nunban_notify": { + "en": "You have been unbanned from the {network} network by {unbanner}." + }, + "nunban_error": { + "en": "It appears {unbanee} was not banned using the ~nban command." + }, "quote_recorded": { "en": "This has been recorded in ~ban_{user}.", "cy": "Mae hyn wedi cael ei gofnodi yn ~ban_{user}.", diff --git a/modules/nickserv/nickserv.js b/modules/nickserv/nickserv.js index 28f20ae..6feafd9 100644 --- a/modules/nickserv/nickserv.js +++ b/modules/nickserv/nickserv.js @@ -1,5 +1,8 @@ +var _ = require('underscore')._; + var nickserv = function(dbot) { this.authStack = {}; + this.userStack = {}; this.api = { 'auth': function(server, nick, callback) { @@ -8,28 +11,46 @@ var nickserv = function(dbot) { if(!_.has(this.authStack, server)) this.authStack[server] = {}; this.authStack[server][nick] = callback; - dbot.say(server, nickserv, infoCommand + ' ' + nick); + }, + + 'getUserHost': function(server, nick, callback) { + if(!_.has(this.userStack, server)) this.userStack[server] = {}; + this.userStack[server][nick] = callback; + dbot.instance.connections[server].send('USERHOST ' + nick); + setTimeout(function() { + if(_.has(this.userStack[server], nick)) callback(false); + }.bind(this), 8000); } }; this.listener = function(event) { - var nickserv = dbot.config.servers[event.server].nickserv, - statusRegex = this.config.servers[event.server].matcher, - acceptableState = this.config.servers[event.server].acceptableState; + if(event.action == 'NOTICE') { + var nickserv = dbot.config.servers[event.server].nickserv, + statusRegex = this.config.servers[event.server].matcher, + acceptableState = this.config.servers[event.server].acceptableState; - if(event.user == nickserv) { - var info = event.params.match(statusRegex); - if(info && _.has(this.authStack, event.server)) { - if(info[2] == acceptableState ) { - this.authStack[event.server][info[1]](true); - } else { - this.authStack[event.server][info[1]](false); + if(event.user == nickserv) { + var info = event.params.match(statusRegex); + if(info && _.has(this.authStack, event.server)) { + if(info[2] == acceptableState ) { + this.authStack[event.server][info[1]](true); + } else { + this.authStack[event.server][info[1]](false); + } } } + } else if(event.action == '302') { + var match = event.params.match(/:(.+)=([^@]+)@(.+)$/); + + if(match[1]) match[1] = match[1].replace('\*', ''); + if(match && _.has(this.userStack, event.server) && _.has(this.userStack[event.server], match[1])) { + this.userStack[event.server][match[1]](match[3].trim()); + delete this.userStack[event.server][match[1]]; + } } }.bind(this); - this.on = 'NOTICE'; + this.on = ['NOTICE', '302']; }; exports.fetch = function(dbot) { diff --git a/modules/project/config.json b/modules/project/config.json index 9c3f593..78aa0e3 100644 --- a/modules/project/config.json +++ b/modules/project/config.json @@ -1,3 +1,13 @@ { - "dependencies": [ "web", "quotes", "github" ] + "dependencies": ["web", "quotes", "github"], + "string_exceptions": [ + "rdns", + "imgurinfo", + "xkcd", + "link", + "log_message", + "poll_describe", + "branch", + "oaosidl" + ] } diff --git a/modules/project/project.js b/modules/project/project.js index 13a6b9d..66a1273 100644 --- a/modules/project/project.js +++ b/modules/project/project.js @@ -44,7 +44,10 @@ var project = function(dbot) { }, 'translationProgress' : function(callback){ var translation = [] ; - var str = _.values(dbot.strings); + var str = _.filter(dbot.strings, function(strings, key) { + return _.include(this.config.string_exceptions, key) != true; + }, this); + str = _.values(str); for (var i = 0; i < str.length; i++){ var cur = _.keys(str[i]); for (var j = 0; j < cur.length; j++) { diff --git a/modules/timers/timers.js b/modules/timers/timers.js index b1e968d..a3fc80f 100644 --- a/modules/timers/timers.js +++ b/modules/timers/timers.js @@ -34,6 +34,18 @@ var timers = function(dbot) { } }.bind(this), timeout)); } + }, + + 'addTimeout': function(date, callback, params) { + var now = new Date().getTime(), + timeout = date.getTime() - now; + this.runningTimeouts.push(setTimeout(function() { + try { + callback.apply(callback, params); + } catch(err) { + console.log('Callback failed: ' + err); + } + }, timeout)); } }; diff --git a/modules/words/config.json b/modules/words/config.json new file mode 100644 index 0000000..649e069 --- /dev/null +++ b/modules/words/config.json @@ -0,0 +1,3 @@ +{ + "api_key": "http://developer.wordnik.com/" +} diff --git a/modules/words/words.js b/modules/words/words.js new file mode 100644 index 0000000..eac90b0 --- /dev/null +++ b/modules/words/words.js @@ -0,0 +1,26 @@ +var Wordnik = require('wordnik'); + +var words = function(dbot) { + this.commands = { + '~define': function(event) { + var query = event.params[1]; + this.wn.definitions(query, function(err, defs) { + if(!err && defs[0]) { + event.reply(query + ': ' + defs[0].text); + } else { + event.reply('No definitions found for ' + query); + } + }); + } + }; + + this.onLoad = function() { + this.wn = new Wordnik({ + 'api_key': this.config.api_key + }); + }.bind(this); +}; + +exports.fetch = function(dbot) { + return new words(dbot); +};