From 44652c40028c4a6121d05798aac283c80af6e6b3 Mon Sep 17 00:00:00 2001 From: Beef Date: Mon, 30 Jan 2023 00:40:56 +0000 Subject: [PATCH] [Plugins] Rework and refactor --- src/def.d.ts | 18 +++++++++--------- src/lib/plugins.ts | 10 ++++++---- src/ui/settings/pages/Plugins.tsx | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/def.d.ts b/src/def.d.ts index c31a79e..fb27182 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -1,7 +1,7 @@ import * as _spitroast from "spitroast"; import _React from "react"; import _RN from "react-native"; -import { Events } from "./lib/emitter"; +import { Events } from "@lib/emitter"; type MetroModules = { [id: number]: any }; @@ -64,7 +64,7 @@ interface Settings { developerSettings: boolean; } -export interface ApplicationCommand { +interface ApplicationCommand { description: string; name: string; options: ApplicationCommandOption[]; @@ -77,7 +77,7 @@ export interface ApplicationCommand { type: ApplicationCommandType; } -export enum ApplicationCommandInputType { +declare enum ApplicationCommandInputType { BUILT_IN, BUILT_IN_TEXT, BUILT_IN_INTEGRATION, @@ -85,7 +85,7 @@ export enum ApplicationCommandInputType { PLACEHOLDER, } -export interface ApplicationCommandOption { +interface ApplicationCommandOption { name: string; description: string; required?: boolean; @@ -94,7 +94,7 @@ export interface ApplicationCommandOption { displayDescription: string; } -export enum ApplicationCommandOptionType { +declare enum ApplicationCommandOptionType { SUB_COMMAND = 1, SUB_COMMAND_GROUP, STRING, @@ -108,18 +108,18 @@ export enum ApplicationCommandOptionType { ATTACHMENT, } -export enum ApplicationCommandType { +declare enum ApplicationCommandType { CHAT = 1, USER, MESSAGE, } -export interface CommandContext { +interface CommandContext { channel: any; guild: any; } -export interface CommandResult { +interface CommandResult { content: string; tts?: boolean; } @@ -252,7 +252,7 @@ interface VendettaObject { }; plugins: { plugins: Indexable; - fetchPlugin: (id: string) => void; + fetchPlugin: (id: string, enabled: boolean) => void; evalPlugin: (plugin: Plugin) => void; stopPlugin: (id: string) => void; removePlugin: (id: string) => void; diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 229c804..6eede12 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -14,15 +14,15 @@ export const plugins = wrapSync(createStorage>("VENDETTA_PLUGI for (let p of Object.keys(store)) { const plugin: Plugin = store[p]; - if (store[p].update) await fetchPlugin(plugin.id); - if (store[p].enabled && plugins[p]) await startPlugin(p); + if (plugin.update) await fetchPlugin(plugin.id, false); + if (plugin.enabled && plugins[p]) await startPlugin(p); } return store; })); const loadedPlugins: Indexable = {}; -export async function fetchPlugin(id: string) { +export async function fetchPlugin(id: string, enabled = true) { if (!id.endsWith("/")) id += "/"; if (typeof id !== "string" || id in plugins) throw new Error("Plugin ID invalid or taken"); @@ -53,6 +53,8 @@ export async function fetchPlugin(id: string) { update: true, js: pluginJs, }; + + if (enabled) await startPlugin(id); } export async function evalPlugin(plugin: Plugin) { @@ -128,4 +130,4 @@ export function showSettings(plugin: Plugin) { name: plugin.manifest.name, children: settings, }); -} +} \ No newline at end of file diff --git a/src/ui/settings/pages/Plugins.tsx b/src/ui/settings/pages/Plugins.tsx index a17278a..91c64fd 100644 --- a/src/ui/settings/pages/Plugins.tsx +++ b/src/ui/settings/pages/Plugins.tsx @@ -3,7 +3,7 @@ import { Forms } from "@ui/components"; import { showToast } from "@ui/toasts"; import { getAssetIDByName } from "@ui/assets"; import { useProxy } from "@lib/storage"; -import { plugins, fetchPlugin } from "@lib/plugins"; +import { plugins, fetchPlugin, startPlugin } from "@lib/plugins"; import PluginCard from "@ui/settings/components/PluginCard"; const { FormInput, FormRow } = Forms;