mode giving + revokin should work now

This commit is contained in:
jkhsjdhjs 2016-09-06 00:34:32 +02:00
parent 4fc92320b3
commit ae0a2694e5

View File

@ -21,10 +21,9 @@ module.exports = (bot, trigger, lib) => {
if(user.toLowerCase() != bot.me.nick.toLowerCase()) { if(user.toLowerCase() != bot.me.nick.toLowerCase()) {
if(user in e.channel.names) { if(user in e.channel.names) {
if(modes = processModes(tmp.join(' '))) { if(modes = processModes(tmp.join(' '))) {
if(checkModes(modes, allowedModes)) if(checkModes(modes.give + modes.revoke, allowedModes))
modes.forEach((entry,i,a) => { if(modes.give != "") bot.mode(e.channel, '+' + modes.give + ' ' + user, e.network);
bot.mode(e.channel, (entry.delta?'+':'-')+entry.mode+' '+user, e.network); if(modes.revoke != "") bot.mode(e.channel, '-' + modes.revoke + ' ' + user, e.network);
});
else else
e.reply('Error! Allowed modes are: ' + allowedModes.join(',')); e.reply('Error! Allowed modes are: ' + allowedModes.join(','));
} }
@ -43,22 +42,19 @@ module.exports = (bot, trigger, lib) => {
}; };
var processModes = (modes) => { var processModes = (modes) => {
var delta, modeList = []; var delta = true, give = [], revoke = [];
if(modes.split('').some((token) => { modes.split('').forEach((token) => {
if(token === '-') {delta = false; return;} if(token === '-') {delta = false; return;}
if(token === '+') {delta = true; return;} if(token === '+') {delta = true; return;}
if(token === ' ') return; if(token === ' ') return;
if(typeof delta === "undefined") return true; if(delta) give.push(token);
modeList.push({ else revoke.push(token);
delta: delta, });
mode: token return {give: [...new Set(give)].join(''), revoke: [...new Set(revoke)].join('')};
});
})) return false;
return [...new Set(modeList)];
}; };
var checkModes = (modes, allowedModes) => { var checkModes = (modes, allowedModes) => {
if([...new Set(modes.map(a => a.mode))].some((mode) => { if([...new Set(modes.split(''))].some((mode) => {
for(var i = 0; i <= allowedModes.length; i++) for(var i = 0; i <= allowedModes.length; i++)
if(allowedModes[i] == mode) return false; if(allowedModes[i] == mode) return false;
return true; return true;