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