forked from GitHub/dbot
Moderator + admin access level for commands [#124]
* May now add property 'access' to commands specifying 'moderator' or 'admin' level access * Add 'moderators' key to config * Convert commands in admin module to use command marshalling listener rather than its own
This commit is contained in:
parent
04901cc0ba
commit
f8d4896eb6
@ -12,6 +12,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admins": [ "batman" ],
|
"admins": [ "batman" ],
|
||||||
|
"moderators": [ "whatever" ],
|
||||||
"moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "quotes", "spelling", "youare" ],
|
"moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "quotes", "spelling", "youare" ],
|
||||||
"language": "english",
|
"language": "english",
|
||||||
"debugMode": true
|
"debugMode": true
|
||||||
|
@ -148,21 +148,21 @@ var admin = function(dbot) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
commands['greload'].access = 'admin';
|
||||||
|
commands['reload'].access = 'admin';
|
||||||
|
commands['unload'].access = 'admin';
|
||||||
|
commands['load'].access = 'admin';
|
||||||
|
commands['join'].access = 'moderator';
|
||||||
|
commands['part'].access = 'moderator';
|
||||||
|
commands['opme'].access = 'moderator';
|
||||||
|
commands['say'].access = 'moderator';
|
||||||
|
commands['ban'].access = 'moderator';
|
||||||
|
commands['unban'].access = 'moderator';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': 'admin',
|
'name': 'admin',
|
||||||
'ignorable': false,
|
'ignorable': false,
|
||||||
|
'commands': commands
|
||||||
/**
|
|
||||||
* Run the appropriate admin command given the input (and user).
|
|
||||||
*/
|
|
||||||
'listener': function(event) {
|
|
||||||
var commandName = event.params[0];
|
|
||||||
if(commands.hasOwnProperty(commandName) && dbot.config.admins.include(event.user)) {
|
|
||||||
commands[commandName](event);
|
|
||||||
dbot.save();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'on': 'PRIVMSG'
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,6 +18,29 @@ var command = function(dbot) {
|
|||||||
return banned;
|
return banned;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the user have the correct access level to use the command?
|
||||||
|
*/
|
||||||
|
var hasAccess = function(user, command) {
|
||||||
|
var access = true;
|
||||||
|
var accessNeeded = dbot.commands[command].access;
|
||||||
|
|
||||||
|
if(accessNeeded == 'admin') {
|
||||||
|
if(!dbot.config.admins.include(user)) {
|
||||||
|
access = false;
|
||||||
|
}
|
||||||
|
} else if(accessNeeded == 'moderator') {
|
||||||
|
if(!dbot.config.moderators.include(user) &&
|
||||||
|
!dbot.config.admins.include(user)) {
|
||||||
|
access = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(accessNeeded);
|
||||||
|
console.log(user);
|
||||||
|
|
||||||
|
return access;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is user ignoring command?
|
* Is user ignoring command?
|
||||||
*/
|
*/
|
||||||
@ -101,7 +124,7 @@ var command = function(dbot) {
|
|||||||
if(isBanned(event.user, commandName)) {
|
if(isBanned(event.user, commandName)) {
|
||||||
event.reply(dbot.t('command_ban', {'user': event.user}));
|
event.reply(dbot.t('command_ban', {'user': event.user}));
|
||||||
} else {
|
} else {
|
||||||
if(!isIgnoring(event.user, commandName)) {
|
if(!isIgnoring(event.user, commandName) && hasAccess(event.user, commandName)) {
|
||||||
if(applyRegex(commandName, event)) {
|
if(applyRegex(commandName, event)) {
|
||||||
try {
|
try {
|
||||||
dbot.commands[commandName](event);
|
dbot.commands[commandName](event);
|
||||||
|
2
run.js
2
run.js
@ -5,7 +5,7 @@ require('./snippets');
|
|||||||
|
|
||||||
var DBot = function(timers) {
|
var DBot = function(timers) {
|
||||||
// Load external files
|
// Load external files
|
||||||
var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moduleNames', 'language', 'debugMode' ];
|
var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moderators', 'moduleNames', 'language', 'debugMode' ];
|
||||||
try {
|
try {
|
||||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user