mirror of
https://github.com/Equicord/Equicord.git
synced 2025-05-10 17:35:37 +02:00
Fixes
This commit is contained in:
parent
92ac5787c0
commit
f605231a36
2 changed files with 36 additions and 23 deletions
|
@ -169,17 +169,24 @@ async function parseFile(fileName: string) {
|
||||||
data.hasCommands = true;
|
data.hasCommands = true;
|
||||||
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
|
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
|
||||||
data.commands = value.elements.map((e) => {
|
data.commands = value.elements.map((e) => {
|
||||||
if (!isObjectLiteralExpression(e)) throw fail("commands array contains non-object literals");
|
if (isObjectLiteralExpression(e)) {
|
||||||
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
|
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
|
||||||
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
|
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
|
||||||
});
|
});
|
||||||
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
|
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
|
||||||
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
|
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
|
||||||
});
|
});
|
||||||
if (!nameProperty || !descriptionProperty) throw fail("Command missing required properties");
|
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
|
||||||
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
|
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
|
||||||
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
|
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
|
||||||
return { name, description };
|
return { name, description };
|
||||||
|
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
|
||||||
|
const [nameArg] = e.arguments;
|
||||||
|
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
|
||||||
|
const name = nameArg.text;
|
||||||
|
return { name, description: "" };
|
||||||
|
}
|
||||||
|
throw fail("commands array contains invalid elements");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "authors":
|
case "authors":
|
||||||
|
|
|
@ -169,19 +169,25 @@ async function parseFile(fileName: string) {
|
||||||
data.hasCommands = true;
|
data.hasCommands = true;
|
||||||
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
|
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
|
||||||
data.commands = value.elements.map((e) => {
|
data.commands = value.elements.map((e) => {
|
||||||
if (!isObjectLiteralExpression(e)) throw fail("commands array contains non-object literals");
|
if (isObjectLiteralExpression(e)) {
|
||||||
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
|
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
|
||||||
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
|
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
|
||||||
});
|
});
|
||||||
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
|
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
|
||||||
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
|
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
|
||||||
});
|
});
|
||||||
if (!nameProperty || !descriptionProperty) throw fail("Command missing required properties");
|
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
|
||||||
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
|
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
|
||||||
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
|
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
|
||||||
return { name, description };
|
return { name, description };
|
||||||
|
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
|
||||||
|
const [nameArg] = e.arguments;
|
||||||
|
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
|
||||||
|
const name = nameArg.text;
|
||||||
|
return { name, description: "" };
|
||||||
|
}
|
||||||
|
throw fail("commands array contains invalid elements");
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
case "authors":
|
case "authors":
|
||||||
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
|
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
|
||||||
data.authors = value.elements.map(e => {
|
data.authors = value.elements.map(e => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue