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];
|
2016-09-06 01:51:52 +00:00
|
|
|
if(!(user in e.channel.names))
|
2016-09-05 21:07:15 +00:00
|
|
|
user = e.user.getNick();
|
|
|
|
else
|
|
|
|
tmp.pop();
|
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-06 12:02:29 +00:00
|
|
|
if(modes = processModes(tmp.join(''))) {
|
2016-09-06 11:36:52 +00:00
|
|
|
if(checkModes(modes, allowedModes)) {
|
2016-09-06 12:02:29 +00:00
|
|
|
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);
|
2016-09-06 11:36:52 +00:00
|
|
|
});
|
2016-09-05 22:13:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-09-06 01:57:49 +00:00
|
|
|
e.reply('Error! Allowed modes are: ' + allowedModes.join(','));
|
2016-09-05 18:23:31 +00:00
|
|
|
}
|
2016-09-05 11:21:52 +00:00
|
|
|
else
|
2016-09-06 01:57:49 +00:00
|
|
|
e.reply('Syntax Error!');
|
2016-09-05 11:18:58 +00:00
|
|
|
}
|
|
|
|
else
|
2016-09-05 22:13:31 +00:00
|
|
|
e.reply('f0ck you hard');
|
2016-09-05 11:18:58 +00:00
|
|
|
},
|
|
|
|
desc: 'change Usermodes'
|
|
|
|
});
|
2016-09-05 22:13:31 +00:00
|
|
|
};
|
|
|
|
|
2016-09-06 11:36:52 +00:00
|
|
|
var processModes = modes => {
|
|
|
|
var prefix = '+', modeArr = [];
|
|
|
|
modes.split('').forEach(token => {
|
|
|
|
if(token === '-' || token === '+') {prefix = token; return;}
|
2016-09-05 22:13:31 +00:00
|
|
|
if(token === ' ') return;
|
2016-09-06 11:45:37 +00:00
|
|
|
modeArr.push(prefix + token);
|
2016-09-05 22:34:32 +00:00
|
|
|
});
|
2016-09-06 12:02:29 +00:00
|
|
|
return modeArr;
|
2016-09-05 22:13:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var checkModes = (modes, allowedModes) => {
|
2016-09-06 12:02:29 +00:00
|
|
|
if([... new Set(modes)].some(mode => {
|
2016-09-06 11:36:52 +00:00
|
|
|
return (allowedModes.indexOf(mode[1]) != -1)?false:true;
|
2016-09-05 22:13:31 +00:00
|
|
|
})) return false;
|
|
|
|
return true;
|
2016-09-05 11:18:58 +00:00
|
|
|
};
|