sums up modes to apply

This commit is contained in:
jkhsjdhjs 2016-09-06 14:02:29 +02:00
parent eee8564c08
commit 60a9ae85a3

View File

@ -20,8 +20,19 @@ module.exports = (bot, trigger, lib) => {
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, allowedModes)) { if(checkModes(modes, allowedModes)) {
modes.forEach(mode => { var modesToApply = [], currentPrefix, queuedModes;
bot.mode(e.channel, mode + ' ' + user, e.network); while(modes.length) {
queuedModes = "";
currentPrefix = modes[0][0];
modes.some(mode => {
if(mode[0] === currentPrefix) queuedModes += mode[1];
else return true;
});
modesToApply.push(currentPrefix + queuedModes + (' ' + user).repeat(queuedModes.length));
for(var i = 0; i < queuedModes.length; i++) modes.shift();
}
modesToApply.forEach(modeStr => {
bot.mode(e.channel, modeStr, e.network);
}); });
} }
else else
@ -44,11 +55,11 @@ var processModes = modes => {
if(token === ' ') return; if(token === ' ') return;
modeArr.push(prefix + token); modeArr.push(prefix + token);
}); });
return [...new Set(modeArr)]; return modeArr;
}; };
var checkModes = (modes, allowedModes) => { var checkModes = (modes, allowedModes) => {
if(modes.some(mode => { if([... new Set(modes)].some(mode => {
return (allowedModes.indexOf(mode[1]) != -1)?false:true; return (allowedModes.indexOf(mode[1]) != -1)?false:true;
})) return false; })) return false;
return true; return true;