Skip to content

Instantly share code, notes, and snippets.

@oauo
Last active May 20, 2020 15:57
Show Gist options
  • Save oauo/842ef7d76a9e6ad0a0c4c1c012ea6752 to your computer and use it in GitHub Desktop.
Save oauo/842ef7d76a9e6ad0a0c4c1c012ea6752 to your computer and use it in GitHub Desktop.
Command Parser
{
"scripts": [],
"styles": []
}
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment