Removed dependency on commandMap (I think ignore might still look at it for now). Underscorised command. [#81]

This commit is contained in:
reality 2013-01-12 16:14:17 +00:00
parent af20b5cbfb
commit 0769d0bd69
2 changed files with 24 additions and 21 deletions

View File

@ -4,14 +4,15 @@
* command and then runs that command, given the user isn't banned from or * command and then runs that command, given the user isn't banned from or
* ignoring that command. * ignoring that command.
*/ */
var _ = require('underscore')._;
var command = function(dbot) { var command = function(dbot) {
/** /**
* Is user banned from using command? * Is user banned from using command?
*/ */
var isBanned = function(user, command) { var isBanned = function(user, command) {
var banned = false; var banned = false;
if(dbot.db.bans.hasOwnProperty(command)) { if(_.has(dbot.db.bans, command)) {
if(dbot.db.bans[command].include(user) || dbot.db.bans['*'].include(user)) { if(_.include(dbot.db.bans[command], user) || _.include(dbot.db.bans['*'], user)) {
banned = true; banned = true;
} }
} }
@ -26,12 +27,12 @@ var command = function(dbot) {
var accessNeeded = dbot.commands[command].access; var accessNeeded = dbot.commands[command].access;
if(accessNeeded == 'admin') { if(accessNeeded == 'admin') {
if(!dbot.config.admins.include(user)) { if(!_.include(dbot.config.admins, user)) {
access = false; access = false;
} }
} else if(accessNeeded == 'moderator') { } else if(accessNeeded == 'moderator') {
if(!dbot.config.moderators.include(user) && if(!_.include(dbot.config.moderators, user) &&
!dbot.config.admins.include(user)) { !_.include(dbot.config.admins, user)) {
access = false; access = false;
} }
} }
@ -43,9 +44,9 @@ var command = function(dbot) {
* Is user ignoring command? * Is user ignoring command?
*/ */
var isIgnoring = function(user, command) { var isIgnoring = function(user, command) {
var module = dbot.commandMap[command]; var module = dbot.commands[command].module;
var ignoring = false; var ignoring = false;
if(dbot.db.ignores.hasOwnProperty(user) && dbot.db.ignores[user].include(module)) { if(_.has(dbot.db.ignores, user) && _.include(dbot.db.ignores[user], module)) {
ignoring = true; ignoring = true;
} }
return ignoring; return ignoring;
@ -57,7 +58,7 @@ var command = function(dbot) {
*/ */
var applyRegex = function(commandName, event) { var applyRegex = function(commandName, event) {
var applies = false; var applies = false;
if(dbot.commands[commandName].hasOwnProperty('regex')) { if(_.has(dbot.commands[commandName], 'regex')) {
var cRegex = dbot.commands[commandName].regex; var cRegex = dbot.commands[commandName].regex;
var q = event.message.valMatch(cRegex[0], cRegex[1]); var q = event.message.valMatch(cRegex[0], cRegex[1]);
if(q) { if(q) {
@ -77,7 +78,7 @@ var command = function(dbot) {
'commands': { 'commands': {
'~usage': function(event) { '~usage': function(event) {
var commandName = event.params[1]; var commandName = event.params[1];
if(dbot.usage.hasOwnProperty(commandName)) { if(_.has(dbot.usage, commandName)) {
event.reply(dbot.t('usage', { event.reply(dbot.t('usage', {
'command': commandName, 'command': commandName,
'usage': dbot.usage[commandName] 'usage': dbot.usage[commandName]
@ -91,11 +92,11 @@ var command = function(dbot) {
'~help': function(event) { '~help': function(event) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(!dbot.modules.hasOwnProperty(moduleName)) { if(!_.has(dbot.modules, moduleName)) {
var moduleName = dbot.commandMap[moduleName]; var moduleName = dbot.commands[moduleName].module;
} }
if(moduleName && dbot.config[moduleName].hasOwnProperty('help')) { if(moduleName && _.has(dbot.config[moduleName], 'help')) {
var help = dbot.config[moduleName].help; var help = dbot.config[moduleName].help;
event.reply(dbot.t('help_link', { event.reply(dbot.t('help_link', {
'module': moduleName, 'module': moduleName,
@ -115,7 +116,7 @@ var command = function(dbot) {
*/ */
'listener': function(event) { 'listener': function(event) {
var commandName = event.params[0]; var commandName = event.params[0];
if(!dbot.commands.hasOwnProperty(commandName)) { if(!_.has(dbot.commands, commandName)) {
commandName = '~'; commandName = '~';
} }
@ -138,7 +139,7 @@ var command = function(dbot) {
dbot.save(); dbot.save();
} else { } else {
if(commandName !== '~') { if(commandName !== '~') {
if(dbot.usage.hasOwnProperty(commandName)){ if(_.has(dbot.usage, commandName)) {
event.reply('Usage: ' + dbot.usage[commandName]); event.reply('Usage: ' + dbot.usage[commandName]);
} else { } else {
event.reply(dbot.t('syntax_error')); event.reply(dbot.t('syntax_error'));

16
run.js
View File

@ -81,9 +81,9 @@ 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;
if(this.strings.hasOwnProperty(string)) { if(_.has(this.strings, string)) {
var lang = this.config.language; var lang = this.config.language;
if(!this.strings[string].hasOwnProperty(lang)) { if(!_.has(this.strings[string], lang)) {
lang = "english"; lang = "english";
} }
@ -257,18 +257,20 @@ DBot.prototype.reloadModules = function() {
this.save(); this.save();
}; };
// I honestly don't know what the fuck this is meant to do. Why is it getting a
// reference to all the pages?
DBot.prototype.reloadPages = function() { DBot.prototype.reloadPages = function() {
for( var m in this.modules ) { _.each(this.modules, function(module) {
if( Object.prototype.isFunction(this.modules[m].reloadPages)) { if(_.isFunction(module.reloadPages)) {
this.modules[m].reloadPages(this.pages); module.reloadPages(this.pages);
}
} }
}, this);
} }
DBot.prototype.cleanNick = function(key) { DBot.prototype.cleanNick = function(key) {
key = key.toLowerCase(); key = key.toLowerCase();
while(key.endsWith("_")) { while(key.endsWith("_")) {
if(this.db.quoteArrs.hasOwnProperty(key)) { if(_.has(this.db.quoteArrs, key)) {
return key; return key;
} }
key = key.substring(0, key.length-1); key = key.substring(0, key.length-1);