Skip to content

Commit

Permalink
feat: plugin stuff + etc
Browse files Browse the repository at this point in the history
  • Loading branch information
byeoon committed Oct 17, 2024
1 parent dd4aba4 commit fe523a4
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function patchCommands() {

export function registerCommand(command: ApplicationCommand): () => void {
// Get built in commands

const builtInCommands = commandsModule.getBuiltInCommands(ApplicationCommandType.CHAT, true, false);
builtInCommands.sort((a: ApplicationCommand, b: ApplicationCommand) => parseInt(b.id!) - parseInt(a.id!));

Expand Down
20 changes: 20 additions & 0 deletions src/lib/commands/debug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ApplicationCommand, ApplicationCommandInputType } from "@types";
import { Messages } from "../metro/common";
import { getDebugInfo } from "../debug";

const debugInfo = getDebugInfo();
export default [
{
name: 'debug',
description: 'Prints Optis debug information to chat.',
inputType: ApplicationCommandInputType.BUILT_IN,
execute(_, ctx) {
const content = `**Opti Debug Info**
> **Opti Version**: ${debugInfo.vendetta.version}
> **Discord Version**: ${debugInfo.discord.version} (Build ${debugInfo.discord.build})
> **Device**: ${debugInfo.device.brand} (${debugInfo.os.name} ${debugInfo.os.version})
> **Codename/Machine ID**: ${debugInfo.device.codename}`
Messages.sendMessage(ctx.channel.id, { content: content });
},
},
] as ApplicationCommand[]
13 changes: 13 additions & 0 deletions src/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { registerCommand } from "../commands";
import debug from "./debug";
import pluginslist from "./pluginslist";

export function initCustomCommands(): void {
const customCommands = [
...debug,
...pluginslist
];
// registerCommand(customCommands);
}

export default { initCustomCommands };
17 changes: 17 additions & 0 deletions src/lib/commands/pluginslist.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApplicationCommand } from "@/def";
import { Messages } from "../metro/common";
import { getDebugInfo } from "../debug";
import { getDisabledPlugins, getPluginList, getPlugins } from "../plugins";
export default [
{
name: 'plugins list',
description: 'Lists all Opti plugins.',
execute(_, ctx) {
const content = `**Enabled Plugins (${getPlugins()}):**
> ${getPluginList()}
**Disabled Plugins:**
> ${getDisabledPlugins()}`
Messages.sendMessage(ctx.channel.id, { content: content });
},
},
] as ApplicationCommand[]
1 change: 1 addition & 0 deletions src/lib/metro/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const commands = findByProps("getBuiltInCommands");
export const navigation = findByProps("pushLazy");
export const navigationStack = findByProps("createStackNavigator");
export const NavigationNative = findByProps("NavigationContainer");
export const Messages = findByProps("sendBotMessage");

// Flux
export const Flux = findByProps("connectStores");
Expand Down
19 changes: 19 additions & 0 deletions src/lib/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type EvaledPlugin = {
// going to touch the plugin function without a 50 foot pole, you can't stop me!!!!
export const plugins = wrapSync(createStorage<Record<string, Plugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
const loadedPlugins: Record<string, EvaledPlugin> = {};
export let pluginsList = new Array<string>();
export let stoppedPlugins = new Array<string>();


export async function fetchPlugin(id: string) {
if (!id.endsWith("/")) id += "/";
Expand Down Expand Up @@ -83,8 +86,10 @@ export async function startPlugin(id: string) {
loadedPlugins[id] = pluginRet;
pluginRet.onLoad?.();
}
pluginsList.push(" " + plugin.manifest.name);
plugin.enabled = true;
} catch (e) {
stoppedPlugins.push(" " + plugin.id);
logger.error(`Plugin ${plugin.id} errored whilst loading, and will be unloaded`, e);

try {
Expand Down Expand Up @@ -140,6 +145,20 @@ export async function initPlugins() {
return stopAllPlugins;
}

export function getPlugins() {
var num = 0;
Object.keys(loadedPlugins).forEach(p => num++);
return num;
}

export function getPluginList() {
return pluginsList.sort();
}

export function getDisabledPlugins() {
return stoppedPlugins.sort();
}

const stopAllPlugins = () => Object.keys(loadedPlugins).forEach(p => stopPlugin(p, false));

export const getSettings = (id: string) => loadedPlugins[id]?.settings;
5 changes: 5 additions & 0 deletions src/ui/settings/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const styles = stylesheet.createThemedStyleSheet({
marginLeft: 5,
tintColor: semanticColors?.INTERACTIVE_NORMAL,
},
authors: {
color: semanticColors.HEADER_SECONDARY,
fontSize: 14,
},
})

interface Action {
Expand Down Expand Up @@ -65,6 +69,7 @@ interface CardProps {
export default function Card(props: CardProps) {
let pressableState = props.toggleValue ?? false;

// TODO: re-position the '...' icon to next to the switch
return (
<RN.View style={[styles.card, { marginTop: props.index !== 0 ? 10 : 0 }]}>
<FormRow
Expand Down
2 changes: 1 addition & 1 deletion src/ui/settings/components/PluginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function PluginCard({ item: plugin, index }: CardWrapper<Plugin>)
try {
if (v) startPlugin(plugin.id); else stopPlugin(plugin.id);
} catch (e) {
showToast((e as Error).message, getAssetIDByName("Small"));
showToast((e as Error).message);
}
}}
descriptionLabel={`${plugin.manifest.description} \n\nAuthors: ${authors.map(i => i.name).join(", ")}`}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/settings/components/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Version({ label, version, icon }: VersionProps) {
trailing={<FormText>{version}</FormText>}
onPress={() => {
clipboard.setString(`${label} - ${version}`);
showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link"));
showToast("Copied to clipboard.", getAssetIDByName("toast_copy_link"));
}}
/>
)
Expand Down

0 comments on commit fe523a4

Please sign in to comment.