Last active
May 20, 2020 15:57
-
-
Save oauo/842ef7d76a9e6ad0a0c4c1c012ea6752 to your computer and use it in GitHub Desktop.
Command Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": [], | |
"styles": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const commands = [ | |
"--command", | |
"--command value", | |
"-- command --option", | |
"-- command --no-option", | |
"-- command value --option", | |
"-dcommand value --option 5 -v", | |
"dolphin command value --option true -v yes", | |
"--command value; -- secondcommand value2" | |
]; | |
const servers = { | |
1000: ["--"] | |
} | |
const createPattern = arr => { | |
arr = arr.map(x => x.replace(/([\?\*\|\^\$\-\\+{}\[\]()<>,.])/g, "\\$1")) | |
return new RegExp(`^(${arr.join("|")}|dolphin)`) | |
} | |
const getPrefixes = n => { | |
if(servers[n]) { | |
return createPattern(servers[n]) | |
} else { | |
return /^(\-\-|\-d|dolphin)/ | |
} | |
} | |
const commandSchema = { | |
command: { | |
o: "option", | |
v: "value", | |
}, | |
}; | |
const expectedOutput = [ | |
[ | |
{ | |
command: "command", | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
value: "value", | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
flags: { | |
option: true, | |
}, | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
flags: { | |
option: false, | |
}, | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
value: "value", | |
flags: { | |
option: true, | |
}, | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
value: "value", | |
flags: { | |
option: 5, | |
value: true, | |
}, | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
value: "value", | |
flags: { | |
option: true, | |
value: "yes", | |
}, | |
}, | |
], | |
[ | |
{ | |
command: "command", | |
value: "value", | |
}, | |
{ | |
command: "secondcommand", | |
value: "value2", | |
} | |
] | |
]; | |
//const parseCommand = | |
const parseCommands = (command, server) => { | |
const prefixes = getPrefixes(server) | |
//if() | |
command.split(';').forEach(x => { | |
x.trim() | |
}); | |
}; | |
commands.forEach((element) => { | |
parseCommands(element, 0); | |
}); | |
console.log(getPrefixes()) | |
console.log(getPrefixes(1000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment