From 8a51bd5b6d3cf439b796ce8b8d25988eda272aec Mon Sep 17 00:00:00 2001 From: kmmiio99o <164557248+kmmiio99o@users.noreply.github.com> Date: Sat, 27 Sep 2025 20:30:21 +0200 Subject: [PATCH] Add per-command enable toggles with restart prompt Users can now enable or disable individual commands in settings. Toggling a command prompts for a Discord restart to apply changes. --- plugins/all-in-one/index.ts | 42 +++++++++---- plugins/all-in-one/settings.tsx | 70 ++++++++++++++++----- plugins/all-in-one/src/commands/konochan.ts | 13 +++- 3 files changed, 95 insertions(+), 30 deletions(-) diff --git a/plugins/all-in-one/index.ts b/plugins/all-in-one/index.ts index 6fe79b7..06c36c7 100644 --- a/plugins/all-in-one/index.ts +++ b/plugins/all-in-one/index.ts @@ -25,6 +25,31 @@ if (!storage.listSettings) { }; } +if (!storage.enabledCommands) { + storage.enabledCommands = { + catfact: true, + dogfact: true, + useless: true, + petpet: true, + pluginList: true, + themeList: true, + konoself: true, + konosend: true, + }; +} + +// Map commands to their storage keys +const commandMap = { + catfact: catFactCommand, + dogfact: dogFactCommand, + useless: uselessFactCommand, + petpet: petPetCommand, + pluginList: pluginListCommand, + themeList: themeListCommand, + konoself: konoSelfCommand, + konosend: konoSendCommand, +}; + // Store registered commands for cleanup let commands: Array<() => void> = []; @@ -32,17 +57,12 @@ export default { onLoad: () => { console.log("[All-In-One Commands] Loading plugin..."); - // Register all commands - commands = [ - registerCommand(catFactCommand), - registerCommand(dogFactCommand), - registerCommand(uselessFactCommand), - registerCommand(petPetCommand), - registerCommand(pluginListCommand), - registerCommand(themeListCommand), - registerCommand(konoSelfCommand), - registerCommand(konoSendCommand), - ]; + // Register only enabled commands + for (const [key, command] of Object.entries(commandMap)) { + if (storage.enabledCommands[key]) { + commands.push(registerCommand(command)); + } + } console.log("[All-In-One Commands] Plugin loaded successfully!"); }, diff --git a/plugins/all-in-one/settings.tsx b/plugins/all-in-one/settings.tsx index dd16964..1e1d9cd 100644 --- a/plugins/all-in-one/settings.tsx +++ b/plugins/all-in-one/settings.tsx @@ -5,6 +5,7 @@ import { getAssetIDByName } from "@vendetta/ui/assets"; import { React } from "@vendetta/metro/common"; import { findByProps } from "@vendetta/metro"; import { View } from "react-native"; +import { alerts } from "@vendetta/ui"; const { ScrollView } = findByProps("ScrollView"); const { TableRowGroup, TableSwitchRow, Stack } = findByProps( @@ -28,15 +29,50 @@ if (!storage.listSettings) { }; } +if (!storage.enabledCommands) { + storage.enabledCommands = { + catfact: true, + dogfact: true, + useless: true, + petpet: true, + pluginList: true, + themeList: true, + konoself: true, + konosend: true, + }; +} + +const askForRestart = (commandName: string, enabled: boolean) => { + return alerts.showConfirmationAlert({ + title: "Restart Required", + content: `${enabled ? "Enabling" : "Disabling"} the ${commandName} command requires a Discord restart to take effect. Would you like to restart now?`, + confirmText: "Restart", + cancelText: "Later", + confirmColor: "brand", + onConfirm: () => { + storage.enabledCommands[commandName] = enabled; + window.enmity.plugins.reload("vendetta"); + }, + onCancel: () => { + storage.enabledCommands[commandName] = !enabled; // Revert change if user doesn't want to restart + }, + }); +}; + export default function Settings() { useProxy(storage); const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0); + const handleCommandToggle = (commandName: string, value: boolean) => { + askForRestart(commandName, value); + forceRerender(); + }; + return ( - {/* Facts Commands Settings */} + {/* Facts Commands */} handleCommandToggle("catfact", v)} /> handleCommandToggle("dogfact", v)} /> handleCommandToggle("useless", v)} /> @@ -107,15 +143,15 @@ export default function Settings() { label="/plugin-list" subLabel="List all installed plugins" icon={getAssetIDByName("ic_plugins")} - value={true} - disabled={true} + value={storage.enabledCommands.pluginList} + onValueChange={(v) => handleCommandToggle("pluginList", v)} /> handleCommandToggle("themeList", v)} /> @@ -125,8 +161,8 @@ export default function Settings() { label="/petpet" subLabel="Create pet-pet GIF of a user" icon={getAssetIDByName("ic_image")} - value={true} - disabled={true} + value={storage.enabledCommands.petpet} + onValueChange={(v) => handleCommandToggle("petpet", v)} /> @@ -136,15 +172,15 @@ export default function Settings() { label="/konoself" subLabel="Get random image from KonoChan (private)" icon={getAssetIDByName("ic_image")} - value={true} - disabled={true} + value={storage.enabledCommands.konoself} + onValueChange={(v) => handleCommandToggle("konoself", v)} /> handleCommandToggle("konosend", v)} /> diff --git a/plugins/all-in-one/src/commands/konochan.ts b/plugins/all-in-one/src/commands/konochan.ts index 4e0b12a..35a5fcb 100644 --- a/plugins/all-in-one/src/commands/konochan.ts +++ b/plugins/all-in-one/src/commands/konochan.ts @@ -68,10 +68,19 @@ export const konoSelfCommand = { const imageUrl = await fetchImage(isNSFW); if (!imageUrl) { - return sendMessage(ctx.channel.id, "No image found. Try again later."); + return { + type: 4, + data: { content: "No image found. Try again later.", flags: 64 }, + }; } - return sendMessage(ctx.channel.id, `Here's your random image: ${imageUrl}`); + return { + type: 4, + data: { + content: `Here's your random image: ${imageUrl}`, + flags: 64, // This makes the message ephemeral (only visible to you) + }, + }; }, applicationId: "-1", inputType: 1,