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:
parent
bfb9a4e454
commit
8a51bd5b6d
3 changed files with 95 additions and 30 deletions
|
|
@ -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
|
// Store registered commands for cleanup
|
||||||
let commands: Array<() => void> = [];
|
let commands: Array<() => void> = [];
|
||||||
|
|
||||||
|
|
@ -32,17 +57,12 @@ export default {
|
||||||
onLoad: () => {
|
onLoad: () => {
|
||||||
console.log("[All-In-One Commands] Loading plugin...");
|
console.log("[All-In-One Commands] Loading plugin...");
|
||||||
|
|
||||||
// Register all commands
|
// Register only enabled commands
|
||||||
commands = [
|
for (const [key, command] of Object.entries(commandMap)) {
|
||||||
registerCommand(catFactCommand),
|
if (storage.enabledCommands[key]) {
|
||||||
registerCommand(dogFactCommand),
|
commands.push(registerCommand(command));
|
||||||
registerCommand(uselessFactCommand),
|
}
|
||||||
registerCommand(petPetCommand),
|
}
|
||||||
registerCommand(pluginListCommand),
|
|
||||||
registerCommand(themeListCommand),
|
|
||||||
registerCommand(konoSelfCommand),
|
|
||||||
registerCommand(konoSendCommand),
|
|
||||||
];
|
|
||||||
|
|
||||||
console.log("[All-In-One Commands] Plugin loaded successfully!");
|
console.log("[All-In-One Commands] Plugin loaded successfully!");
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { getAssetIDByName } from "@vendetta/ui/assets";
|
||||||
import { React } from "@vendetta/metro/common";
|
import { React } from "@vendetta/metro/common";
|
||||||
import { findByProps } from "@vendetta/metro";
|
import { findByProps } from "@vendetta/metro";
|
||||||
import { View } from "react-native";
|
import { View } from "react-native";
|
||||||
|
import { alerts } from "@vendetta/ui";
|
||||||
|
|
||||||
const { ScrollView } = findByProps("ScrollView");
|
const { ScrollView } = findByProps("ScrollView");
|
||||||
const { TableRowGroup, TableSwitchRow, Stack } = findByProps(
|
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() {
|
export default function Settings() {
|
||||||
useProxy(storage);
|
useProxy(storage);
|
||||||
const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0);
|
const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0);
|
||||||
|
|
||||||
|
const handleCommandToggle = (commandName: string, value: boolean) => {
|
||||||
|
askForRestart(commandName, value);
|
||||||
|
forceRerender();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<ScrollView style={{ flex: 1 }}>
|
<ScrollView style={{ flex: 1 }}>
|
||||||
<Stack spacing={8}>
|
<Stack spacing={8}>
|
||||||
{/* Facts Commands Settings */}
|
{/* Facts Commands */}
|
||||||
<TableRowGroup title="Facts Commands">
|
<TableRowGroup title="Facts Commands">
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Send as Reply"
|
label="Send as Reply"
|
||||||
|
|
@ -62,22 +98,22 @@ export default function Settings() {
|
||||||
label="/catfact"
|
label="/catfact"
|
||||||
subLabel="Get random cat facts"
|
subLabel="Get random cat facts"
|
||||||
icon={getAssetIDByName("ic_info")}
|
icon={getAssetIDByName("ic_info")}
|
||||||
value={true}
|
value={storage.enabledCommands.catfact}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("catfact", v)}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="/dogfact"
|
label="/dogfact"
|
||||||
subLabel="Get random dog facts"
|
subLabel="Get random dog facts"
|
||||||
icon={getAssetIDByName("ic_info")}
|
icon={getAssetIDByName("ic_info")}
|
||||||
value={true}
|
value={storage.enabledCommands.dogfact}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("dogfact", v)}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="/useless"
|
label="/useless"
|
||||||
subLabel="Get random useless facts"
|
subLabel="Get random useless facts"
|
||||||
icon={getAssetIDByName("ic_info")}
|
icon={getAssetIDByName("ic_info")}
|
||||||
value={true}
|
value={storage.enabledCommands.useless}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("useless", v)}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
@ -107,15 +143,15 @@ export default function Settings() {
|
||||||
label="/plugin-list"
|
label="/plugin-list"
|
||||||
subLabel="List all installed plugins"
|
subLabel="List all installed plugins"
|
||||||
icon={getAssetIDByName("ic_plugins")}
|
icon={getAssetIDByName("ic_plugins")}
|
||||||
value={true}
|
value={storage.enabledCommands.pluginList}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("pluginList", v)}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="/theme-list"
|
label="/theme-list"
|
||||||
subLabel="List all installed themes"
|
subLabel="List all installed themes"
|
||||||
icon={getAssetIDByName("ic_theme")}
|
icon={getAssetIDByName("ic_theme")}
|
||||||
value={true}
|
value={storage.enabledCommands.themeList}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("themeList", v)}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
@ -125,8 +161,8 @@ export default function Settings() {
|
||||||
label="/petpet"
|
label="/petpet"
|
||||||
subLabel="Create pet-pet GIF of a user"
|
subLabel="Create pet-pet GIF of a user"
|
||||||
icon={getAssetIDByName("ic_image")}
|
icon={getAssetIDByName("ic_image")}
|
||||||
value={true}
|
value={storage.enabledCommands.petpet}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("petpet", v)}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
@ -136,15 +172,15 @@ export default function Settings() {
|
||||||
label="/konoself"
|
label="/konoself"
|
||||||
subLabel="Get random image from KonoChan (private)"
|
subLabel="Get random image from KonoChan (private)"
|
||||||
icon={getAssetIDByName("ic_image")}
|
icon={getAssetIDByName("ic_image")}
|
||||||
value={true}
|
value={storage.enabledCommands.konoself}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("konoself", v)}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="/konosend"
|
label="/konosend"
|
||||||
subLabel="Send random image from KonoChan to channel"
|
subLabel="Send random image from KonoChan to channel"
|
||||||
icon={getAssetIDByName("ic_image")}
|
icon={getAssetIDByName("ic_image")}
|
||||||
value={true}
|
value={storage.enabledCommands.konosend}
|
||||||
disabled={true}
|
onValueChange={(v) => handleCommandToggle("konosend", v)}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,19 @@ export const konoSelfCommand = {
|
||||||
const imageUrl = await fetchImage(isNSFW);
|
const imageUrl = await fetchImage(isNSFW);
|
||||||
|
|
||||||
if (!imageUrl) {
|
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",
|
applicationId: "-1",
|
||||||
inputType: 1,
|
inputType: 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue