var allowedModes = [ 'q','a','o','h','v' ]; module.exports = (bot, trigger, lib) => { trigger.add({ name: 'umode', call: /^\!umode .*/i, level: 100, active: 1, func: (e) => { var tmp = e.message.trim().split(' '); tmp.shift(); var user = tmp[tmp.length - 1]; if(!(user in e.channel.names)) user = e.user.getNick(); else tmp.pop(); var modes; if(user.toLowerCase() != bot.me.nick.toLowerCase()) { if(modes = processModes(tmp.join(''))) { if(checkModes(modes, allowedModes)) { 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 e.reply('Error! Allowed modes are: ' + allowedModes.join(',')); } else e.reply('Syntax Error!'); } else e.reply('f0ck you hard'); }, desc: 'change Usermodes' }); }; var processModes = modes => { var prefix = '+', modeArr = []; modes.split('').forEach(token => { if(token === '-' || token === '+') {prefix = token; return;} if(token === ' ') return; modeArr.push(prefix + token); }); return modeArr; }; var checkModes = (modes, allowedModes) => { if([... new Set(modes)].some(mode => { return (allowedModes.indexOf(mode[1]) != -1)?false:true; })) return false; return true; };