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.
This commit is contained in:
kmmiio99o 2025-09-27 20:30:21 +02:00
parent bfb9a4e454
commit 8a51bd5b6d
3 changed files with 95 additions and 30 deletions

View file

@ -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!");
},

View file

@ -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 (
<View style={{ flex: 1 }}>
<ScrollView style={{ flex: 1 }}>
<Stack spacing={8}>
{/* Facts Commands Settings */}
{/* Facts Commands */}
<TableRowGroup title="Facts Commands">
<TableSwitchRow
label="Send as Reply"
@ -62,22 +98,22 @@ export default function Settings() {
label="/catfact"
subLabel="Get random cat facts"
icon={getAssetIDByName("ic_info")}
value={true}
disabled={true}
value={storage.enabledCommands.catfact}
onValueChange={(v) => handleCommandToggle("catfact", v)}
/>
<TableSwitchRow
label="/dogfact"
subLabel="Get random dog facts"
icon={getAssetIDByName("ic_info")}
value={true}
disabled={true}
value={storage.enabledCommands.dogfact}
onValueChange={(v) => handleCommandToggle("dogfact", v)}
/>
<TableSwitchRow
label="/useless"
subLabel="Get random useless facts"
icon={getAssetIDByName("ic_info")}
value={true}
disabled={true}
value={storage.enabledCommands.useless}
onValueChange={(v) => handleCommandToggle("useless", v)}
/>
</TableRowGroup>
@ -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)}
/>
<TableSwitchRow
label="/theme-list"
subLabel="List all installed themes"
icon={getAssetIDByName("ic_theme")}
value={true}
disabled={true}
value={storage.enabledCommands.themeList}
onValueChange={(v) => handleCommandToggle("themeList", v)}
/>
</TableRowGroup>
@ -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)}
/>
</TableRowGroup>
@ -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)}
/>
<TableSwitchRow
label="/konosend"
subLabel="Send random image from KonoChan to channel"
icon={getAssetIDByName("ic_image")}
value={true}
disabled={true}
value={storage.enabledCommands.konosend}
onValueChange={(v) => handleCommandToggle("konosend", v)}
/>
</TableRowGroup>

View file

@ -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,