[Plugins] Rework and refactor
This commit is contained in:
parent
4c9fe8fcaf
commit
44652c4002
3 changed files with 16 additions and 14 deletions
18
src/def.d.ts
vendored
18
src/def.d.ts
vendored
|
@ -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<Plugin>;
|
||||
fetchPlugin: (id: string) => void;
|
||||
fetchPlugin: (id: string, enabled: boolean) => void;
|
||||
evalPlugin: (plugin: Plugin) => void;
|
||||
stopPlugin: (id: string) => void;
|
||||
removePlugin: (id: string) => void;
|
||||
|
|
|
@ -14,15 +14,15 @@ export const plugins = wrapSync(createStorage<Indexable<Plugin>>("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<EvaledPlugin> = {};
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue