mirror of
https://github.com/reality/dbot.git
synced 2024-11-30 16:09:27 +01:00
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" ],
|
||||
"moderators": [ "whatever" ],
|
||||
"moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "quotes", "spelling", "youare" ],
|
||||
"language": "english",
|
||||
"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 {
|
||||
'name': 'admin',
|
||||
'ignorable': false,
|
||||
|
||||
/**
|
||||
* 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'
|
||||
'commands': commands
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,29 @@ var command = function(dbot) {
|
||||
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?
|
||||
*/
|
||||
@ -101,7 +124,7 @@ var command = function(dbot) {
|
||||
if(isBanned(event.user, commandName)) {
|
||||
event.reply(dbot.t('command_ban', {'user': event.user}));
|
||||
} else {
|
||||
if(!isIgnoring(event.user, commandName)) {
|
||||
if(!isIgnoring(event.user, commandName) && hasAccess(event.user, commandName)) {
|
||||
if(applyRegex(commandName, event)) {
|
||||
try {
|
||||
dbot.commands[commandName](event);
|
||||
|
2
run.js
2
run.js
@ -5,7 +5,7 @@ require('./snippets');
|
||||
|
||||
var DBot = function(timers) {
|
||||
// Load external files
|
||||
var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moduleNames', 'language', 'debugMode' ];
|
||||
var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moderators', 'moduleNames', 'language', 'debugMode' ];
|
||||
try {
|
||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||
} catch(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user