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