meeeeeeerge

This commit is contained in:
reality 2013-06-13 19:11:42 +00:00
commit 77af2a1250
14 changed files with 347 additions and 59 deletions

View File

@ -14,7 +14,7 @@ then
exit 1 exit 1
fi 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/ cd public/
wget http://twitter.github.com/bootstrap/assets/bootstrap.zip wget http://twitter.github.com/bootstrap/assets/bootstrap.zip

View File

@ -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) { '~help': function(event) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(!moduleName || !_.has(dbot.modules, moduleName)) { if(!moduleName || !_.has(dbot.modules, moduleName)) {

View File

@ -51,5 +51,8 @@
}, },
"access_denied": { "access_denied": {
"en": "{user}: You don't have the access level to run this command." "en": "{user}: You don't have the access level to run this command."
},
"module_commands": {
"en": "Commands in {module}: {commands}."
} }
} }

View File

@ -15,3 +15,15 @@ people.
#### ~kickstats #### ~kickstats
Show a list of top kickers and kickees. 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.

View File

@ -41,49 +41,128 @@ var commands = function(dbot) {
// Kick and ban from all channels on the network. // Kick and ban from all channels on the network.
'~nban': function(event) { '~nban': function(event) {
if(!event.input) return;
var server = event.server, var server = event.server,
banner = event.user, banner = event.user,
banee = event.input[1], timeout = event.input[1],
reason = event.input[2], banee = event.input[2],
channels = dbot.config.servers[server].channels; reason = event.input[3],
adminChannel = this.config.admin_channel[event.server];
channels = dbot.config.servers[server].channels,
network = event.server;
var i = 0; if(this.config.network_name[event.server]) {
var banChannel = function(channels) { network = this.config.network_name[event.server];
if(i >= channels.length) return; }
var channel = channels[i]; console.log(timeout);
this.api.ban(server, banee, channel); console.log(banee);
this.api.kick(server, banee, channel, reason + console.log(reason);
' (network-wide ban requested by ' + banner + ')');
setTimeout(function() {
i++; banChannel(channels);
}, 1000);
}.bind(this);
banChannel(channels);
var notifyString = dbot.t('nbanned', { dbot.api.nickserv.getUserHost(event.server, banee, function(host) {
'banner': banner, // Add host record entry
'banee': banee, if(host) {
'reason': reason 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 ***/ /*** Kick Stats ***/
@ -144,7 +223,7 @@ var commands = function(dbot) {
commands['~kickstats'].access = 'regular'; commands['~kickstats'].access = 'regular';
commands['~ckick'].regex = [/^~ckick ([^ ]+) ([^ ]+) (.+)$/, 4]; commands['~ckick'].regex = [/^~ckick ([^ ]+) ([^ ]+) (.+)$/, 4];
commands['~nban'].regex = [/^~nban ([^ ]+) (.+)$/, 3]; commands['~nban'].regex = /^~nban ([\d\.^ ]+)?([^ ]+) (.+)$/;
return commands; return commands;
}; };

View File

@ -1,11 +1,14 @@
{ {
"dbKeys": [ "kicks", "kickers" ], "dbKeys": [ "kicks", "kickers", "hosts", "tempBans" ],
"dependencies": [ "command", "report", "users" ], "dependencies": [ "command", "report", "users" ],
"ignorable": true, "ignorable": true,
"countSilently": true, "countSilently": true,
"admin_channels": { "admin_channel": {
"aberwiki": "#fishbox" "aberwiki": "#fishbox"
}, },
"network_name": {
"aberwiki": "OAOSIDL"
},
"chanserv": "ChanServ", "chanserv": "ChanServ",
"document_bans": false "document_bans": false
} }

View File

@ -1,20 +1,88 @@
var _ = require('underscore')._; var _ = require('underscore')._;
var kick = function(dbot) { var kick = function(dbot) {
this.hosts = dbot.db.hosts;
this.tempBans = dbot.db.tempBans;
this.api = { this.api = {
'ban': function(server, user, channel) { '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) { '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) { 'kick': function(server, user, channel, msg) {
dbot.instance.connections[server].send('KICK ' + channel + ' ' + user + ' :' + 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) { this.listener = function(event) {
if(event.kickee == dbot.config.name) { if(event.kickee == dbot.config.name) {
@ -44,6 +112,15 @@ var kick = function(dbot) {
} }
}.bind(this); }.bind(this);
this.on = 'KICK'; 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) { exports.fetch = function(dbot) {

View File

@ -25,16 +25,37 @@
"cy": "Sylw: {banner} wedi gwahardd {banee} o {channel}. Y rheswm a roddwyd oedd: \"{reason}.\"", "cy": "Sylw: {banner} wedi gwahardd {banee} o {channel}. Y rheswm a roddwyd oedd: \"{reason}.\"",
"de": "Achtung: {banner} hat {banee} von {channel} gebannt. Grund: \"{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": { "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}.\"", "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}.\"" "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": { "nban_quote": {
"en": "{banee} was banned from the network by {banner} on {time}. The reason given was \"{reason}.\"", "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}.\"", "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}.\"" "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": { "quote_recorded": {
"en": "This has been recorded in ~ban_{user}.", "en": "This has been recorded in ~ban_{user}.",
"cy": "Mae hyn wedi cael ei gofnodi yn ~ban_{user}.", "cy": "Mae hyn wedi cael ei gofnodi yn ~ban_{user}.",

View File

@ -1,5 +1,8 @@
var _ = require('underscore')._;
var nickserv = function(dbot) { var nickserv = function(dbot) {
this.authStack = {}; this.authStack = {};
this.userStack = {};
this.api = { this.api = {
'auth': function(server, nick, callback) { 'auth': function(server, nick, callback) {
@ -8,28 +11,46 @@ var nickserv = function(dbot) {
if(!_.has(this.authStack, server)) this.authStack[server] = {}; if(!_.has(this.authStack, server)) this.authStack[server] = {};
this.authStack[server][nick] = callback; this.authStack[server][nick] = callback;
dbot.say(server, nickserv, infoCommand + ' ' + nick); 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) { this.listener = function(event) {
var nickserv = dbot.config.servers[event.server].nickserv, if(event.action == 'NOTICE') {
statusRegex = this.config.servers[event.server].matcher, var nickserv = dbot.config.servers[event.server].nickserv,
acceptableState = this.config.servers[event.server].acceptableState; statusRegex = this.config.servers[event.server].matcher,
acceptableState = this.config.servers[event.server].acceptableState;
if(event.user == nickserv) { if(event.user == nickserv) {
var info = event.params.match(statusRegex); var info = event.params.match(statusRegex);
if(info && _.has(this.authStack, event.server)) { if(info && _.has(this.authStack, event.server)) {
if(info[2] == acceptableState ) { if(info[2] == acceptableState ) {
this.authStack[event.server][info[1]](true); this.authStack[event.server][info[1]](true);
} else { } else {
this.authStack[event.server][info[1]](false); 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); }.bind(this);
this.on = 'NOTICE'; this.on = ['NOTICE', '302'];
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {

View File

@ -1,3 +1,13 @@
{ {
"dependencies": [ "web", "quotes", "github" ] "dependencies": ["web", "quotes", "github"],
"string_exceptions": [
"rdns",
"imgurinfo",
"xkcd",
"link",
"log_message",
"poll_describe",
"branch",
"oaosidl"
]
} }

View File

@ -44,7 +44,10 @@ var project = function(dbot) {
}, },
'translationProgress' : function(callback){ 'translationProgress' : function(callback){
var translation = [] ; 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++){ for (var i = 0; i < str.length; i++){
var cur = _.keys(str[i]); var cur = _.keys(str[i]);
for (var j = 0; j < cur.length; j++) { for (var j = 0; j < cur.length; j++) {

View File

@ -34,6 +34,18 @@ var timers = function(dbot) {
} }
}.bind(this), timeout)); }.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));
} }
}; };

View File

@ -0,0 +1,3 @@
{
"api_key": "http://developer.wordnik.com/"
}

26
modules/words/words.js Normal file
View File

@ -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);
};