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) => {
|
func: (e) => {
|
||||||
var processModes = (modes) => {
|
var processModes = (modes) => {
|
||||||
var delta, modeList = [];
|
var delta, modeList = [];
|
||||||
console.log(modes.split(''));
|
|
||||||
if(modes.split('').some((token) => {
|
if(modes.split('').some((token) => {
|
||||||
if(token === '-') {delta = false; return;}
|
if(token === '-') {delta = false; return;}
|
||||||
if(token === '+') {delta = true; return;}
|
if(token === '+') {delta = true; return;}
|
||||||
|
@ -18,7 +17,15 @@ module.exports = (bot, trigger, lib) => {
|
||||||
mode: token
|
mode: token
|
||||||
});
|
});
|
||||||
})) return false;
|
})) 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 = [
|
var allowedModes = [
|
||||||
'q','a','o','h','v'
|
'q','a','o','h','v'
|
||||||
|
@ -31,7 +38,18 @@ module.exports = (bot, trigger, lib) => {
|
||||||
else
|
else
|
||||||
tmp.pop();
|
tmp.pop();
|
||||||
e.reply("input: "+JSON.stringify(tmp));
|
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("output: "+JSON.stringify(modes));
|
||||||
e.reply("user: "+user);
|
e.reply("user: "+user);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user