2016-09-05 22:13:31 +00:00
|
|
|
var allowedModes = [
|
|
|
|
'q','a','o','h','v'
|
|
|
|
];
|
|
|
|
|
2016-09-05 11:18:58 +00:00
|
|
|
module.exports = (bot, trigger, lib) => {
|
|
|
|
trigger.add({
|
|
|
|
name: 'umode',
|
2016-09-05 21:07:15 +00:00
|
|
|
call: /^\!umode .*/i,
|
2016-09-05 11:18:58 +00:00
|
|
|
level: 100,
|
|
|
|
active: 1,
|
|
|
|
func: (e) => {
|
2016-09-05 21:07:15 +00:00
|
|
|
var tmp = e.message.trim().split(' ');
|
|
|
|
tmp.shift();
|
|
|
|
var user = tmp[tmp.length - 1];
|
|
|
|
if(user.match(/(\+|-)/))
|
|
|
|
user = e.user.getNick();
|
|
|
|
else
|
|
|
|
tmp.pop();
|
|
|
|
e.reply("input: "+JSON.stringify(tmp));
|
2016-09-05 21:21:26 +00:00
|
|
|
var modes;
|
2016-09-05 11:25:29 +00:00
|
|
|
if(user.toLowerCase() != bot.me.nick.toLowerCase()) {
|
2016-09-05 22:13:31 +00:00
|
|
|
if(user in e.channel.names) {
|
|
|
|
if(modes = processModes(tmp.join(' '))) {
|
2016-09-05 22:34:32 +00:00
|
|
|
if(checkModes(modes.give + modes.revoke, allowedModes))
|
|
|
|
if(modes.give != "") bot.mode(e.channel, '+' + modes.give + ' ' + user, e.network);
|
|
|
|
if(modes.revoke != "") bot.mode(e.channel, '-' + modes.revoke + ' ' + user, e.network);
|
2016-09-05 22:13:31 +00:00
|
|
|
else
|
|
|
|
e.reply('Error! Allowed modes are: ' + allowedModes.join(','));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.reply('Syntax Error!');
|
2016-09-05 18:23:31 +00:00
|
|
|
}
|
2016-09-05 11:21:52 +00:00
|
|
|
else
|
2016-09-05 22:13:31 +00:00
|
|
|
e.reply('user not found!');
|
2016-09-05 11:18:58 +00:00
|
|
|
}
|
|
|
|
else
|
2016-09-05 22:13:31 +00:00
|
|
|
e.reply('f0ck you hard');
|
|
|
|
e.reply("output: "+JSON.stringify(modes));
|
2016-09-05 11:18:58 +00:00
|
|
|
},
|
|
|
|
desc: 'change Usermodes'
|
|
|
|
});
|
2016-09-05 22:13:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var processModes = (modes) => {
|
2016-09-05 22:34:32 +00:00
|
|
|
var delta = true, give = [], revoke = [];
|
|
|
|
modes.split('').forEach((token) => {
|
2016-09-05 22:13:31 +00:00
|
|
|
if(token === '-') {delta = false; return;}
|
|
|
|
if(token === '+') {delta = true; return;}
|
|
|
|
if(token === ' ') return;
|
2016-09-05 22:34:32 +00:00
|
|
|
if(delta) give.push(token);
|
|
|
|
else revoke.push(token);
|
|
|
|
});
|
|
|
|
return {give: [...new Set(give)].join(''), revoke: [...new Set(revoke)].join('')};
|
2016-09-05 22:13:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var checkModes = (modes, allowedModes) => {
|
2016-09-05 22:34:32 +00:00
|
|
|
if([...new Set(modes.split(''))].some((mode) => {
|
2016-09-05 22:13:31 +00:00
|
|
|
for(var i = 0; i <= allowedModes.length; i++)
|
|
|
|
if(allowedModes[i] == mode) return false;
|
|
|
|
return true;
|
|
|
|
})) return false;
|
|
|
|
return true;
|
2016-09-05 11:18:58 +00:00
|
|
|
};
|