merge clash

This commit is contained in:
Luke Slater 2013-03-22 10:49:22 +00:00
commit ccc8d6c6e9
19 changed files with 262 additions and 71 deletions

View File

@ -3,6 +3,17 @@ cat LICENCE
git submodule init git submodule init
git submodule update git submodule update
if [ ! -e /usr/bin/node ] && [ ! -e /usr/local/bin/node ];
then
echo 'node.js is not installed. Please install it before running install.sh.'
exit 1
fi
if [ ! -e /usr/bin/npm ] && [ ! -e /usr/local/bin/npm ];
then
echo 'npm is not installed. Please install it before running install.sh'
exit 1
fi
npm install underscore request sandbox express moment jade@0.25 npm install underscore request sandbox express moment jade@0.25
cd public/ cd public/

View File

@ -26,7 +26,7 @@ var commands = function(dbot) {
} }
var currentOption; var currentOption;
if(configKey.length != 1) { if(configKey && configKey.length != 1) {
configKey = _.last(configKey); configKey = _.last(configKey);
if(_.has(userConfigPath, configKey) && !_.isUndefined(userConfigPath[configKey])) { if(_.has(userConfigPath, configKey) && !_.isUndefined(userConfigPath[configKey])) {
currentOption = userConfigPath[configKey]; currentOption = userConfigPath[configKey];
@ -173,8 +173,10 @@ var commands = function(dbot) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(_.include(moduleNames, moduleName)) { if(_.include(moduleNames, moduleName)) {
var moduleDir = '../' + moduleName + '/'; var moduleDir = '../' + moduleName + '/';
try {
var cacheKey = require.resolve(moduleDir + moduleName); var cacheKey = require.resolve(moduleDir + moduleName);
delete require.cache[cacheKey]; delete require.cache[cacheKey];
} catch(err) { }
dbot.config.moduleNames = _.without(dbot.config.moduleNames, moduleName); dbot.config.moduleNames = _.without(dbot.config.moduleNames, moduleName);
dbot.reloadModules(); dbot.reloadModules();
@ -184,32 +186,6 @@ var commands = function(dbot) {
} }
}, },
// Ban user from command or *
'ban': function(event) {
var username = event.params[1];
var command = event.params[2];
if(!_.has(dbot.db.bans, command)) {
dbot.db.bans[command] = [ ];
}
dbot.db.bans[command].push(username);
event.reply(dbot.t('banned', {'user': username, 'command': command}));
},
// Unban a user from command or *
'unban': function(event) {
var username = event.params[1];
var command = event.params[2];
if(_.has(dbot.db.bans, command) && _.include(dbot.db.bans[command], username)) {
_.reject(dbot.db.bans[command], function(bans) {
return bans == username;
}, this);
event.reply(dbot.t('unbanned', {'user': username, 'command': command}));
} else {
event.reply(dbot.t('unban_error', {'user': username}));
}
},
/*** Config options ***/ /*** Config options ***/
'setconfig': function(event) { 'setconfig': function(event) {
@ -297,13 +273,12 @@ var commands = function(dbot) {
commands['load'].access = 'admin'; commands['load'].access = 'admin';
commands['version'].access = 'admin'; commands['version'].access = 'admin';
commands['setconfig'].access = 'admin'; commands['setconfig'].access = 'admin';
commands['pushconfig'].access = 'admin';
commands['showconfig'].access = 'moderator'; commands['showconfig'].access = 'moderator';
commands['join'].access = 'moderator'; commands['join'].access = 'moderator';
commands['part'].access = 'moderator'; commands['part'].access = 'moderator';
commands['opme'].access = 'moderator'; commands['opme'].access = 'moderator';
commands['say'].access = 'moderator'; commands['say'].access = 'moderator';
commands['ban'].access = 'moderator';
commands['unban'].access = 'moderator';
return commands; return commands;
}; };

View File

@ -1,6 +1,5 @@
{ {
"ignorable": false, "ignorable": false,
"dbKeys": [ "bans" ],
"dependencies": [ "command" ], "dependencies": [ "command" ],
"help": "http://github.com/reality/depressionbot/blob/master/modules/admin/README.md" "help": "http://github.com/reality/depressionbot/blob/master/modules/admin/README.md"
} }

View File

@ -4,8 +4,10 @@ var api = function(dbot) {
return { return {
'isBanned': function(user, command) { 'isBanned': function(user, command) {
var banned = false; var banned = false;
if(_.has(dbot.db.bans, command)) { if(_.has(dbot.db.bans, user)) {
if(_.include(dbot.db.bans[command], user) || _.include(dbot.db.bans['*'], user)) { if(_.include(dbot.db.bans[user], command) ||
_.include(dbot.db.bans[user], dbot.commands[command].module) ||
_.include(dbot.db.bans[user], '*')) {
banned = true; banned = true;
} }
} }
@ -39,7 +41,8 @@ var api = function(dbot) {
'isIgnoring': function(item, command) { 'isIgnoring': function(item, command) {
var module = dbot.commands[command].module; var module = dbot.commands[command].module;
return (_.has(dbot.db.ignores, item) && return (_.has(dbot.db.ignores, item) &&
_.include(dbot.db.ignores[item], module)); (_.include(dbot.db.ignores[item], module) ||
_.include(dbot.db.ignores[item], '*')));
}, },
/** /**

View File

@ -18,8 +18,27 @@ var commands = function(dbot) {
'~help': function(event) { '~help': function(event) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(!moduleName) {
helpfulModules = _.filter(dbot.modules, function(element, index, array) {
return _.has(dbot.config[element], 'help');
});
event.reply(dbot.t('usage', {
'command': '~help',
'usage': '~help [module]'
}));
event.reply(dbot.t('loaded_modules_with_help', {
'modules': helpfulModules.join(', ')
}));
return;
}
if(!_.has(dbot.modules, moduleName)) { if(!_.has(dbot.modules, moduleName)) {
if(_.has(dbot.commands, moduleName)) {
var moduleName = dbot.commands[moduleName].module; var moduleName = dbot.commands[moduleName].module;
} else {
var moduleName = undefined;
}
} }
if(moduleName && _.has(dbot.config[moduleName], 'help')) { if(moduleName && _.has(dbot.config[moduleName], 'help')) {

View File

@ -1,5 +1,5 @@
{ {
"ignorable": false, "ignorable": false,
"help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md", "help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md",
"dbKeys": [ "ignores" ] "dbKeys": [ "ignores", "bans" ]
} }

View File

@ -26,5 +26,8 @@
"no_help": { "no_help": {
"en": "No help found for {module}.", "en": "No help found for {module}.",
"na'vi": "Fì{module}ìri oel ke tsun run srungit" "na'vi": "Fì{module}ìri oel ke tsun run srungit"
},
"loaded_modules_with_help": {
"en": "Loaded modules with help information: {modules}."
} }
} }

17
modules/dns/README.md Normal file
View File

@ -0,0 +1,17 @@
## DNS
Performs and reports upon basic DNS functions.
### Description
This module utilises the domain name system to discover basic information about
domain names and IP addresses.
### Commands
#### ~lookup [domain name]
Looks up the specified domain name in the domain name system. If a match is found,
the first corresponding A or AAAA record is displayed.
#### ~rdns [IP address]
Looks up the specified IP address in the domain name system. If a match is found,
the first corresponding rDNS domain name is displayed.

42
modules/dns/dns.js Normal file
View File

@ -0,0 +1,42 @@
/**
* Module Name: DNS
* Description: Performs and reports on basic DNS functions.
*/
var dnsmod = require('dns');
var dns = function(dbot) {
var commands = {
'~lookup': function(event) {
domain = event.params[1];
dnsmod.lookup(domain, function (error, addr) {
if (error) {
console.log(error);
event.reply(dbot.t("lookup-error",{"domain": domain, "code": error.code}));
} else {
event.reply(dbot.t("lookup",{"domain": domain, "address": addr}));
}
});
},
'~rdns': function(event) {
ip = event.params[1];
try {
dnsmod.reverse(ip, function (error, domain) {
if (error) {
throw error;
}
event.reply(dbot.t("rdns",{"domain": domain, "ip": ip}));
});
} catch (err) {
event.reply(dbot.t("rdns-error",{"domain": domain, "ip": ip, "error": err}));
}
}
};
this.commands = commands;
this.on = 'PRIVMSG';
};
exports.fetch = function(dbot) {
return new dns(dbot);
};

14
modules/dns/strings.json Normal file
View File

@ -0,0 +1,14 @@
{
"lookup-error": {
"en": "{domain} is \u000303AVAILABLE! \u000314({code})"
},
"lookup": {
"en": "{domain} is \u000305TAKEN! \u000314({address})"
},
"rdns": {
"en": "{ip} \u2192 {domain}"
},
"rdns-error": {
"en": "Unable to lookup {ip}. \u000314({error})"
}
}

View File

@ -1,6 +1,6 @@
{ {
"ignorable": false, "ignorable": false,
"dependencies": [ "command" ], "dependencies": [ "command" ],
"dbKeys": [ "ignores" ], "dbKeys": [ "ignores", "bans" ],
"help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md" "help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md"
} }

View File

@ -24,7 +24,7 @@ var ignore = function(dbot) {
'modules': ignorableModules.join(', ') 'modules': ignorableModules.join(', ')
})); }));
} else { } else {
if(_.include(ignorableModules, module)) { if(module == '*' || _.include(ignorableModules, module)) {
if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) { if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) {
event.reply(dbot.t('already_ignoring', { 'user': event.user })); event.reply(dbot.t('already_ignoring', { 'user': event.user }));
} else { } else {
@ -72,12 +72,72 @@ var ignore = function(dbot) {
} }
}, },
'~ban': function(event) {
var user = event.params[1];
var module = event.params[2];
if(_.isUndefined(user) || _.isUndefined(module)) {
event.reply(dbot.t('ban_usage', {'user': event.user}));
return;
}
if(module == '*' || _.include(dbot.config.moduleNames, module) || _.include(dbot.commands, module)) {
if(_.has(dbot.db.bans, user) && _.include(dbot.db.bans[user], module)) {
event.reply(dbot.t('already_banned', {
'user': event.user,
'banned': user
}));
return;
}
if(_.has(dbot.db.bans, event.params[1])) {
dbot.db.bans[event.params[1]].push(module);
} else {
dbot.db.bans[event.params[1]] = [module];
}
event.reply(dbot.t('banned_success', {
'user': event.user,
'banned': user,
'module': module
}));
} else {
event.reply(dbot.t('invalid_ban', {'user': event.user}));
}
},
'~unban': function(event) {
var bannedModules = [];
var user = event.params[1];
var module = event.params[2];
if(_.isUndefined(user) || _.isUndefined(module)) {
event.reply(dbot.t('unban_usage', {'user': event.user}));
} else {
if(_.has(dbot.db.bans, user) && _.include(dbot.db.bans[user], module)) {
dbot.db.bans[user].splice(dbot.db.bans[user].indexOf(module), 1);
event.reply(dbot.t('unbanned_success', {
'user': event.user,
'banned': user,
'module': module
}));
} else {
event.reply(dbot.t('invalid_unban', {
'user': event.user,
'banned': user
}));
}
}
},
'~ignorechannel': function(event) { '~ignorechannel': function(event) {
var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]); var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]);
var module = event.params[2]; var module = event.params[2];
// Ignoring the value of 'ignorable' at the moment // Ignoring the value of 'ignorable' at the moment
if(_.include(dbot.config.moduleNames, module)) { if(module == '*' || _.include(dbot.config.moduleNames, module)) {
if(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = []; if(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = [];
if(!_.include(dbot.db.ignores[channel], module)) { if(!_.include(dbot.db.ignores[channel], module)) {
dbot.db.ignores[channel].push(module); dbot.db.ignores[channel].push(module);
@ -118,6 +178,8 @@ var ignore = function(dbot) {
} }
}; };
commands['~ban'].access = 'moderator';
commands['~unban'].access = 'moderator';
commands['~ignorechannel'].access = 'moderator'; commands['~ignorechannel'].access = 'moderator';
commands['~unignorechannel'].access = 'moderator'; commands['~unignorechannel'].access = 'moderator';

View File

@ -41,6 +41,27 @@
"na'vi": "{user}: Nga terìng mikyun {module}ne set", "na'vi": "{user}: Nga terìng mikyun {module}ne set",
"cy": "{user}: Ddim yn anwybyddu {module} bellach" "cy": "{user}: Ddim yn anwybyddu {module} bellach"
}, },
"ban_usage": {
"en": "{user}: Usage: ~ban [user] [module/command]. Use * for all modules and commands."
},
"already_banned": {
"en": "{user}: {banned} is already banned from that module."
},
"banned_success": {
"en": "{user}: {banned} is now banned from {module}."
},
"invalid_ban": {
"en": "{user}: That isn't a valid module name."
},
"unban_usage": {
"en": "{user}: Usage: ~unban [user] [module]."
},
"invalid_unban": {
"en": "{user}: {banned} is not banned from that module or it doesn't exist."
},
"unbanned_success": {
"en": "{user}: {banned} is no longer banned from {module}."
},
"ignoring_channel": { "ignoring_channel": {
"en": "Now ignoring {module} in {channel}", "en": "Now ignoring {module} in {channel}",
"na'vi": "Oe ke stayawm {module}ur mì {channel}" "na'vi": "Oe ke stayawm {module}ur mì {channel}"

View File

@ -110,7 +110,7 @@ var commands = function(dbot) {
'category': key 'category': key
})); }));
} else { } else {
event.reply(dbot.t('no_quotes', {'category': q[1]})); event.reply(dbot.t('no_quotes', {'category': key}));
} }
} else { } else {
event.reply(dbot.t('rmlast_spam')); event.reply(dbot.t('rmlast_spam'));
@ -187,21 +187,30 @@ var commands = function(dbot) {
}, },
'~rq': function(event) { '~rq': function(event) {
if(_.keys(quotes).length > 0) {
var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)]; var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)];
event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category)); event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category));
} else {
event.reply(dbot.t('no_results'));
}
}, },
'~link': function(event) { '~link': function(event) {
var key = event.input[1].toLowerCase(); var key = event.input[1].toLowerCase();
if(_.has(quotes, key)) { if(_.has(quotes, key)) {
if(_.has(dbot.config, 'web') && _.has(dbot.config.web, 'webHost') &&
_.has(dbot.config.web, 'webPort')) {
event.reply(dbot.t('quote_link', { event.reply(dbot.t('quote_link', {
'category': key, 'category': key,
'url': dbot.t('url', { 'url': dbot.t('url', {
'host': dbot.config.web.webHost, 'host': dbot.config.web.webHost,
'port': dbot.config.web.webPort, 'port': dbot.config.web.webPort,
'path': 'quotes/' + key 'path': 'quotes/' + encodeURIComponent(key)
}) })
})); }));
} else {
event.reply(dbot.t('web_not_configured'));
}
} else { } else {
event.reply(dbot.t('category_not_found', { 'category': key })); event.reply(dbot.t('category_not_found', { 'category': key }));
} }
@ -213,7 +222,7 @@ var commands = function(dbot) {
commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~qadd'].regex = [/^~qadd ([\d\w-]+[\d\w\s-]*)[ ]?=[ ]?(.+)$/, 3];
commands['~link'].regex = [/^~link ([\d\w\s-]*)/, 2]; commands['~link'].regex = [/^~link ([\d\w\s-]*)/, 2];
commands['~rmconfirm'].access = 'moderator'; commands['~rmconfirm'].access = 'moderator';

View File

@ -126,5 +126,8 @@
"rm_cache_limit": { "rm_cache_limit": {
"en": "Attention: Too many quotes removed, rmCache must be cleared or reinstated manually with ~rmconfirm or ~rmdeny.", "en": "Attention: Too many quotes removed, rmCache must be cleared or reinstated manually with ~rmconfirm or ~rmdeny.",
"na'vi": "Oel zerok 'upxareti apxay set, sweylu txo nga 'aivku upxareti ìlä ~rmconfirm fu ~rmdeny." "na'vi": "Oel zerok 'upxareti apxay set, sweylu txo nga 'aivku upxareti ìlä ~rmconfirm fu ~rmdeny."
},
"web_not_configured": {
"en": "Cannot link to category. Web module is either not loaded or misconfigured."
} }
} }

View File

@ -12,11 +12,7 @@ var commands = function(dbot) {
if(aliasCount != 0) { if(aliasCount != 0) {
var aliases = _.first(aliases, 10); var aliases = _.first(aliases, 10);
var including = 'including: '; var including = 'including: ' + aliases.join(', ') + '.';
for(var i=0;i<aliases.length;i++) {
including += aliases[i] + ', ';
}
including = including.slice(0, -2) + '.';
event.reply(dbot.t('primary', { event.reply(dbot.t('primary', {
'user': alias, 'user': alias,
@ -26,7 +22,7 @@ var commands = function(dbot) {
event.reply(dbot.t('primary', { event.reply(dbot.t('primary', {
'user': alias, 'user': alias,
'count': aliasCount 'count': aliasCount
})); }).slice(0, -2) + ".");
} }
} else if(_.has(knownUsers.aliases, alias)) { } else if(_.has(knownUsers.aliases, alias)) {
event.reply(dbot.t('alias', { event.reply(dbot.t('alias', {
@ -101,6 +97,10 @@ var commands = function(dbot) {
} }
}; };
commands['~alias'].regex = [/^~alias ([\d\w[\]{}^|\\`_-]+?)/, 2];
commands['~setaliasparent'].regex = [/^~setaliasparent ([\d\w[\]{}^|\\`_-]+?)/, 2];
commands['~mergeusers'].regex = [/^~mergeusers ([\d\w[\]{}^|\\`_-]+?)\s*?([\d\w[\]{}^|\\`_-]+?)/, 3];
commands['~setaliasparent'].access = 'moderator'; commands['~setaliasparent'].access = 'moderator';
commands['~mergeusers'].access = 'moderator'; commands['~mergeusers'].access = 'moderator';

5
modules/users/usage.json Normal file
View File

@ -0,0 +1,5 @@
{
"~alias": "~alias [nick]",
"~setaliasparent": "~setaliasparent [nick]",
"~mergeusers": "~mergeusers [primary] [secondary]"
}

View File

@ -38,7 +38,7 @@ var users = function(dbot) {
var knownUsers = this.getServerUsers(event.server); var knownUsers = this.getServerUsers(event.server);
var nick = event.user; var nick = event.user;
if(event.action == 'JOIN') { if(event.action == 'JOIN' && nick != dbot.config.name) {
if(!_.has(knownUsers.channelUsers, event.channel.name)) { if(!_.has(knownUsers.channelUsers, event.channel.name)) {
knownUsers.channelUsers[event.channel.name] = []; knownUsers.channelUsers[event.channel.name] = [];
} }
@ -55,7 +55,9 @@ var users = function(dbot) {
channelUsers.push(nick); channelUsers.push(nick);
} }
} else if(event.action == 'NICK') { } else if(event.action == 'NICK') {
var newNick = event.params.substr(1); // remove the first character from the NICK message if it is a :,
// due to some IRCd's disregarding RFC 1459 and adding a :
var newNick = (event.params[0] == ":" ? event.params.substr(1) : event.params);
if(!this.api.isKnownUser(newNick)) { if(!this.api.isKnownUser(newNick)) {
knownUsers.aliases[newNick] = this.api.resolveUser(event.server, event.user); knownUsers.aliases[newNick] = this.api.resolveUser(event.server, event.user);
dbot.api.event.emit('nick_change', [ event.server, newNick ]); dbot.api.event.emit('nick_change', [ event.server, newNick ]);

16
run.js
View File

@ -86,16 +86,17 @@ DBot.prototype.say = function(server, channel, message) {
// Format given stored string in config language // Format given stored string in config language
DBot.prototype.t = function(string, formatData) { DBot.prototype.t = function(string, formatData) {
var formattedString; var formattedString = 'String not found. Something has gone screwy. Maybe.';
if(_.has(this.strings, string)) { if(_.has(this.strings, string)) {
var lang = this.config.language; var lang = this.config.language;
if(!_.has(this.strings[string], lang)) { if(!_.has(this.strings[string], lang)) {
lang = "en"; lang = "en";
} }
if(_.has(this.strings[string], lang)) {
formattedString = this.strings[string][lang].format(formatData); formattedString = this.strings[string][lang].format(formatData);
} else { }
formattedString = 'String not found. Something has gone screwy. Maybe.';
} }
return formattedString; return formattedString;
@ -154,9 +155,15 @@ DBot.prototype.reloadModules = function() {
this.instance.removeListeners(); this.instance.removeListeners();
_.each(moduleNames, function(name) { _.each(moduleNames, function(name) {
this.status[name] = true;
var moduleDir = './modules/' + name + '/'; var moduleDir = './modules/' + name + '/';
try {
var cacheKey = require.resolve(moduleDir + name); var cacheKey = require.resolve(moduleDir + name);
delete require.cache[cacheKey]; delete require.cache[cacheKey];
} catch(err) {
this.status[name] = 'Error loading module: ' + err + ' ' + err.stack.split('\n')[2].trim();
return;
}
try { try {
var webKey = require.resolve(moduleDir + 'web'); var webKey = require.resolve(moduleDir + 'web');
@ -166,8 +173,6 @@ DBot.prototype.reloadModules = function() {
delete require.cache[webKey]; delete require.cache[webKey];
} }
this.status[name] = true;
try { try {
// Load the module config data // Load the module config data
var config = {}; var config = {};
@ -292,6 +297,7 @@ DBot.prototype.reloadModules = function() {
module.onLoad(); module.onLoad();
} catch(err) { } catch(err) {
this.status[name] = 'Error in onLoad: ' + err + ' ' + err.stack.split('\n')[1].trim(); this.status[name] = 'Error in onLoad: ' + err + ' ' + err.stack.split('\n')[1].trim();
console.log('MODULE ONLOAD ERROR (' + name + '): ' + err );
} }
} }
}, this); }, this);