check if modes are allowed
This commit is contained in:
parent
c2cc4ab85b
commit
aefc42fe71
@ -7,7 +7,6 @@ module.exports = (bot, trigger, lib) => {
|
||||
func: (e) => {
|
||||
var processModes = (modes) => {
|
||||
var delta, modeList = [];
|
||||
console.log(modes.split(''));
|
||||
if(modes.split('').some((token) => {
|
||||
if(token === '-') {delta = false; return;}
|
||||
if(token === '+') {delta = true; return;}
|
||||
@ -18,7 +17,15 @@ module.exports = (bot, trigger, lib) => {
|
||||
mode: token
|
||||
});
|
||||
})) return false;
|
||||
else return modeList;
|
||||
return [...new Set(modeList)];
|
||||
};
|
||||
var checkModes = (modes, allowedModes) => {
|
||||
if([...new Set(modes.map(a => a.mode))].some((mode) => {
|
||||
if(allowedModes.some((allowedMode) => {
|
||||
if(allowedMode != mode) return true;
|
||||
})) return true;
|
||||
})) return false;
|
||||
return true;
|
||||
};
|
||||
var allowedModes = [
|
||||
'q','a','o','h','v'
|
||||
@ -31,7 +38,18 @@ module.exports = (bot, trigger, lib) => {
|
||||
else
|
||||
tmp.pop();
|
||||
e.reply("input: "+JSON.stringify(tmp));
|
||||
var modes = processModes(tmp.join(' '));
|
||||
var modes;
|
||||
if(modes = processModes(tmp.join(' '))) {
|
||||
if(checkModes(modes, allowedModes)) {
|
||||
//---apply modes---
|
||||
}
|
||||
else {
|
||||
e.reply('Error! Allowed modes are: ' + allowedModes.join(',');
|
||||
}
|
||||
}
|
||||
else {
|
||||
e.reply('Syntax Error!');
|
||||
}
|
||||
e.reply("output: "+JSON.stringify(modes));
|
||||
e.reply("user: "+user);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user