fixes mode apply order
This commit is contained in:
parent
52824f54b3
commit
b13782a3f5
@ -19,9 +19,10 @@ module.exports = (bot, trigger, lib) => {
|
||||
var modes;
|
||||
if(user.toLowerCase() != bot.me.nick.toLowerCase()) {
|
||||
if(modes = processModes(tmp.join(' '))) {
|
||||
if(checkModes(modes.give + modes.revoke, allowedModes)) {
|
||||
if(modes.give != "") bot.mode(e.channel, '+' + modes.give + ' ' + (user+' ').repeat(modes.give.length), e.network);
|
||||
if(modes.revoke != "") bot.mode(e.channel, '-' + modes.revoke + ' ' + (user+' ').repeat(modes.revoke.length), e.network);
|
||||
if(checkModes(modes, allowedModes)) {
|
||||
modes.forEach(mode => {
|
||||
bot.mode(e.channel, mode + ' ' + user, e.network);
|
||||
});
|
||||
}
|
||||
else
|
||||
e.reply('Error! Allowed modes are: ' + allowedModes.join(','));
|
||||
@ -36,21 +37,20 @@ module.exports = (bot, trigger, lib) => {
|
||||
});
|
||||
};
|
||||
|
||||
var processModes = (modes) => {
|
||||
var delta = true, give = [], revoke = [];
|
||||
modes.split('').forEach((token) => {
|
||||
if(token === '-') {delta = false; return;}
|
||||
if(token === '+') {delta = true; return;}
|
||||
var processModes = modes => {
|
||||
var prefix = '+', modeArr = [];
|
||||
modes.split('').forEach(token => {
|
||||
if(token === '-' || token === '+') {prefix = token; return;}
|
||||
if(token === ' ') return;
|
||||
if(delta) give.push(token);
|
||||
else revoke.push(token);
|
||||
if(delta) modeArr.push(prefix + token);
|
||||
else modeArr.push(prefix + token);
|
||||
});
|
||||
return {give: [...new Set(give)].join(''), revoke: [...new Set(revoke)].join('')};
|
||||
return [...new Set(modeArr)];
|
||||
};
|
||||
|
||||
var checkModes = (modes, allowedModes) => {
|
||||
if([...new Set(modes.split(''))].some((mode) => {
|
||||
return (allowedModes.indexOf(mode) != -1)?false:true;
|
||||
if(modes.some(mode => {
|
||||
return (allowedModes.indexOf(mode[1]) != -1)?false:true;
|
||||
})) return false;
|
||||
return true;
|
||||
};
|
Loading…
Reference in New Issue
Block a user