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.give + modes.revoke, allowedModes)) { if(modes.give != "") bot.mode(e.channel, '+' + modes.give + ' ' + (user+' ').repeat(modes.give.length), e.network); if(modes.revoke != "") bot.mode(e.channel, '-' + modes.revoke + ' ' + (user+' ').repeat(modes.revoke.length), 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 delta = true, give = [], revoke = []; modes.split('').forEach((token) => { if(token === '-') {delta = false; return;} if(token === '+') {delta = true; return;} if(token === ' ') return; 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.split(''))].some((mode) => { return (allowedModes.indexOf(mode) != -1)?false:true; })) return false; return true; };