[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 * as _spitroast from "spitroast";
|
||||||
import _React from "react";
|
import _React from "react";
|
||||||
import _RN from "react-native";
|
import _RN from "react-native";
|
||||||
import { Events } from "./lib/emitter";
|
import { Events } from "@lib/emitter";
|
||||||
|
|
||||||
type MetroModules = { [id: number]: any };
|
type MetroModules = { [id: number]: any };
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ interface Settings {
|
||||||
developerSettings: boolean;
|
developerSettings: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommand {
|
interface ApplicationCommand {
|
||||||
description: string;
|
description: string;
|
||||||
name: string;
|
name: string;
|
||||||
options: ApplicationCommandOption[];
|
options: ApplicationCommandOption[];
|
||||||
|
@ -77,7 +77,7 @@ export interface ApplicationCommand {
|
||||||
type: ApplicationCommandType;
|
type: ApplicationCommandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ApplicationCommandInputType {
|
declare enum ApplicationCommandInputType {
|
||||||
BUILT_IN,
|
BUILT_IN,
|
||||||
BUILT_IN_TEXT,
|
BUILT_IN_TEXT,
|
||||||
BUILT_IN_INTEGRATION,
|
BUILT_IN_INTEGRATION,
|
||||||
|
@ -85,7 +85,7 @@ export enum ApplicationCommandInputType {
|
||||||
PLACEHOLDER,
|
PLACEHOLDER,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandOption {
|
interface ApplicationCommandOption {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
@ -94,7 +94,7 @@ export interface ApplicationCommandOption {
|
||||||
displayDescription: string;
|
displayDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ApplicationCommandOptionType {
|
declare enum ApplicationCommandOptionType {
|
||||||
SUB_COMMAND = 1,
|
SUB_COMMAND = 1,
|
||||||
SUB_COMMAND_GROUP,
|
SUB_COMMAND_GROUP,
|
||||||
STRING,
|
STRING,
|
||||||
|
@ -108,18 +108,18 @@ export enum ApplicationCommandOptionType {
|
||||||
ATTACHMENT,
|
ATTACHMENT,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ApplicationCommandType {
|
declare enum ApplicationCommandType {
|
||||||
CHAT = 1,
|
CHAT = 1,
|
||||||
USER,
|
USER,
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommandContext {
|
interface CommandContext {
|
||||||
channel: any;
|
channel: any;
|
||||||
guild: any;
|
guild: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommandResult {
|
interface CommandResult {
|
||||||
content: string;
|
content: string;
|
||||||
tts?: boolean;
|
tts?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ interface VendettaObject {
|
||||||
};
|
};
|
||||||
plugins: {
|
plugins: {
|
||||||
plugins: Indexable<Plugin>;
|
plugins: Indexable<Plugin>;
|
||||||
fetchPlugin: (id: string) => void;
|
fetchPlugin: (id: string, enabled: boolean) => void;
|
||||||
evalPlugin: (plugin: Plugin) => void;
|
evalPlugin: (plugin: Plugin) => void;
|
||||||
stopPlugin: (id: string) => void;
|
stopPlugin: (id: string) => void;
|
||||||
removePlugin: (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)) {
|
for (let p of Object.keys(store)) {
|
||||||
const plugin: Plugin = store[p];
|
const plugin: Plugin = store[p];
|
||||||
|
|
||||||
if (store[p].update) await fetchPlugin(plugin.id);
|
if (plugin.update) await fetchPlugin(plugin.id, false);
|
||||||
if (store[p].enabled && plugins[p]) await startPlugin(p);
|
if (plugin.enabled && plugins[p]) await startPlugin(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return store;
|
return store;
|
||||||
}));
|
}));
|
||||||
const loadedPlugins: Indexable<EvaledPlugin> = {};
|
const loadedPlugins: Indexable<EvaledPlugin> = {};
|
||||||
|
|
||||||
export async function fetchPlugin(id: string) {
|
export async function fetchPlugin(id: string, enabled = true) {
|
||||||
if (!id.endsWith("/")) id += "/";
|
if (!id.endsWith("/")) id += "/";
|
||||||
if (typeof id !== "string" || id in plugins) throw new Error("Plugin ID invalid or taken");
|
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,
|
update: true,
|
||||||
js: pluginJs,
|
js: pluginJs,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (enabled) await startPlugin(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function evalPlugin(plugin: Plugin) {
|
export async function evalPlugin(plugin: Plugin) {
|
||||||
|
@ -128,4 +130,4 @@ export function showSettings(plugin: Plugin) {
|
||||||
name: plugin.manifest.name,
|
name: plugin.manifest.name,
|
||||||
children: settings,
|
children: settings,
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ import { Forms } from "@ui/components";
|
||||||
import { showToast } from "@ui/toasts";
|
import { showToast } from "@ui/toasts";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { useProxy } from "@lib/storage";
|
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";
|
import PluginCard from "@ui/settings/components/PluginCard";
|
||||||
|
|
||||||
const { FormInput, FormRow } = Forms;
|
const { FormInput, FormRow } = Forms;
|
||||||
|
|
Loading…
Reference in a new issue