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

@ -18,10 +18,21 @@ module.exports = (bot, trigger, lib) => {
tmp.pop();
var modes;
if(user.toLowerCase() != bot.me.nick.toLowerCase()) {
if(modes = processModes(tmp.join(' '))) {
if(modes = processModes(tmp.join(''))) {
if(checkModes(modes, allowedModes)) {
modes.forEach(mode => {
bot.mode(e.channel, mode + ' ' + user, e.network);
var modesToApply = [], currentPrefix, queuedModes;
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
@ -44,11 +55,11 @@ var processModes = modes => {
if(token === ' ') return;
modeArr.push(prefix + token);
});
return [...new Set(modeArr)];
return modeArr;
};
var checkModes = (modes, allowedModes) => {
if(modes.some(mode => {
if([... new Set(modes)].some(mode => {
return (allowedModes.indexOf(mode[1]) != -1)?false:true;
})) return false;
return true;