f0ckv1/src/trigger/umode.js
2016-09-06 13:36:52 +02:00

56 lines
1.5 KiB
JavaScript

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)) {
modes.forEach(mode => {
bot.mode(e.channel, mode + ' ' + user, 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;
if(delta) modeArr.push(prefix + token);
else modeArr.push(prefix + token);
});
return [...new Set(modeArr)];
};
var checkModes = (modes, allowedModes) => {
if(modes.some(mode => {
return (allowedModes.indexOf(mode[1]) != -1)?false:true;
})) return false;
return true;
};