Commands In Plugin Json

This commit is contained in:
thororen1234 2024-10-31 04:34:18 -04:00
parent df4d56aacf
commit 6bd3b06de5
4 changed files with 42 additions and 7 deletions

View file

@ -20,15 +20,21 @@ import { Dirent, readdirSync, readFileSync, writeFileSync } from "fs";
import { access, readFile } from "fs/promises"; import { access, readFile } from "fs/promises";
import { join, sep } from "path"; import { join, sep } from "path";
import { normalize as posixNormalize, sep as posixSep } from "path/posix"; import { normalize as posixNormalize, sep as posixSep } from "path/posix";
import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript"; import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, PropertyAssignment, ScriptTarget, StringLiteral, SyntaxKind } from "typescript";
import { getPluginTarget } from "./utils.mjs"; import { getPluginTarget } from "./utils.mjs";
import { ApplicationCommandOptionType } from "@api/Commands";
interface Dev { interface Dev {
name: string; name: string;
id: string; id: string;
} }
interface Command {
name: string;
description: string;
}
interface PluginData { interface PluginData {
name: string; name: string;
description: string; description: string;
@ -37,6 +43,7 @@ interface PluginData {
dependencies: string[]; dependencies: string[];
hasPatches: boolean; hasPatches: boolean;
hasCommands: boolean; hasCommands: boolean;
commands: Command[];
required: boolean; required: boolean;
enabledByDefault: boolean; enabledByDefault: boolean;
target: "discordDesktop" | "vencordDesktop" | "equicordDesktop" | "desktop" | "web" | "dev"; target: "discordDesktop" | "vencordDesktop" | "equicordDesktop" | "desktop" | "web" | "dev";
@ -161,6 +168,35 @@ async function parseFile(fileName: string) {
break; break;
case "commands": case "commands":
data.hasCommands = true; data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (!isObjectLiteralExpression(e)) {
throw fail("commands array contains non-object literals");
}
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("Command missing required properties");
const name = isStringLiteral(nameProperty.initializer)
? nameProperty.initializer.text
: '';
const description = isStringLiteral(descriptionProperty.initializer)
? descriptionProperty.initializer.text
: '';
return {
name,
description
};
});
break; 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");

View file

@ -18,10 +18,10 @@ async function getcuteneko(): Promise<string> {
export default definePlugin({ export default definePlugin({
name: "CuteNekos", name: "CuteNekos",
authors: [Devs.echo], authors: [Devs.echo],
description: "Neko Command", description: "Send Nekos to others",
commands: [{ commands: [{
name: "nekos", name: "nekos",
description: "Baby don't hurt me no more", description: "Send Neko",
execute: async opts => ({ execute: async opts => ({
content: await getcuteneko() content: await getcuteneko()
}) })

View file

@ -8,7 +8,6 @@ import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
async function getcutepats(): Promise<string> { async function getcutepats(): Promise<string> {
// Indi wants bad things
const res = await fetch("https://api.waifu.pics/sfw/pat"); const res = await fetch("https://api.waifu.pics/sfw/pat");
const url = (await res.json()).url as string; const url = (await res.json()).url as string;
return url; return url;
@ -19,10 +18,10 @@ async function getcutepats(): Promise<string> {
export default definePlugin({ export default definePlugin({
name: "CutePats", name: "CutePats",
authors: [EquicordDevs.thororen], authors: [EquicordDevs.thororen],
description: "Pat Command", description: "Sending Head Pats",
commands: [{ commands: [{
name: "pat", name: "pat",
description: "Baby don't hurt me no more", description: "Sends a headpat gif",
execute: async opts => ({ execute: async opts => ({
content: await getcutepats() content: await getcutepats()
}) })

View file

@ -44,7 +44,7 @@ export default definePlugin({
commands: [ commands: [
{ {
name: "gifroulette", name: "gifroulette",
description: "Time to tempt your fate", description: "Tempt fate and send a gif",
execute: (opts, other) => ({ execute: (opts, other) => ({
content: getMessage(opts, other) content: getMessage(opts, other)
}), }),