diff --git a/src/core/commands/eval.ts b/src/core/commands/eval.ts index 24f3506..5db6d6c 100644 --- a/src/core/commands/eval.ts +++ b/src/core/commands/eval.ts @@ -1,5 +1,6 @@ import { Strings } from "@core/i18n"; import { ApplicationCommand, ApplicationCommandOptionType } from "@lib/api/commands/types"; +import { settings } from "@lib/settings"; import { messageUtil } from "@metro/common"; import { findByProps } from "@metro/filters"; @@ -15,6 +16,7 @@ function wrapInJSCodeblock(resString: string) { export default () => { name: "eval", description: Strings.COMMAND_EVAL_DESC, + shouldHide: () => settings.enableEvalCommand === true, options: [ { name: "code", diff --git a/src/core/i18n/default.json b/src/core/i18n/default.json index 1c16109..156c86b 100644 --- a/src/core/i18n/default.json +++ b/src/core/i18n/default.json @@ -36,6 +36,8 @@ "DISABLE_THEME": "Disable Theme", "DISABLE_UPDATES": "Disable updates", "DISCORD_SERVER": "Discord Server", + "ENABLE_EVAL_COMMAND": "Enable /eval command", + "ENABLE_EVAL_COMMAND_DESC": "Evaluate JavaScript directly from command. Be cautious when using this command as it may pose a security risk. Make sure to know what you are doing.", "ENABLE_UPDATES": "Enable updates", "ERROR_BOUNDARY_TOOLS_LABEL": "ErrorBoundary Tools", "GENERAL": "General", diff --git a/src/core/ui/settings/pages/Developer.tsx b/src/core/ui/settings/pages/Developer.tsx index 0e51aad..37e290a 100644 --- a/src/core/ui/settings/pages/Developer.tsx +++ b/src/core/ui/settings/pages/Developer.tsx @@ -148,6 +148,15 @@ export default function Developer() { /> } /> + } + value={settings.enableEvalCommand} + onValueChange={(v: boolean) => { + settings.enableEvalCommand = v; + }} + /> diff --git a/src/lib/api/commands/index.ts b/src/lib/api/commands/index.ts index bb84895..59768d5 100644 --- a/src/lib/api/commands/index.ts +++ b/src/lib/api/commands/index.ts @@ -1,4 +1,4 @@ -import { ApplicationCommand, ApplicationCommandInputType, ApplicationCommandType } from "@lib/api/commands/types"; +import { ApplicationCommand, ApplicationCommandInputType, ApplicationCommandType, BunnyApplicationCommand } from "@lib/api/commands/types"; import { after, instead } from "@lib/api/patcher"; import { logger } from "@lib/utils/logger"; import { commands as commandsModule, messageUtil } from "@metro/common"; @@ -10,12 +10,14 @@ let commands: ApplicationCommand[] = []; */ export function patchCommands() { const unpatch = after("getBuiltInCommands", commandsModule, ([type], res: ApplicationCommand[]) => { - if (type === ApplicationCommandType.CHAT) return res.concat(commands); + if (type === ApplicationCommandType.CHAT) { + return res.concat(commands.filter(c => c.__bunny?.shouldHide?.() !== false)); + } }); // Register core commands [ - // require("@core/commands/eval"), + require("@core/commands/eval"), require("@core/commands/debug"), require("@core/commands/plugins") ].forEach(r => registerCommand(r.default())); @@ -26,7 +28,7 @@ export function patchCommands() { }; } -export function registerCommand(command: ApplicationCommand): () => void { +export function registerCommand(command: BunnyApplicationCommand): () => 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!)); @@ -37,7 +39,10 @@ export function registerCommand(command: ApplicationCommand): () => void { command.id = (parseInt(lastCommand.id, 10) - 1).toString(); // Fill optional args - command.__isBunny = true; + command.__bunny = { + shouldHide: command.shouldHide + }; + command.applicationId ??= "-1"; command.type ??= ApplicationCommandType.CHAT; command.inputType = ApplicationCommandInputType.BUILT_IN; diff --git a/src/lib/api/commands/types.ts b/src/lib/api/commands/types.ts index 6dc3971..c50fbf3 100644 --- a/src/lib/api/commands/types.ts +++ b/src/lib/api/commands/types.ts @@ -17,7 +17,13 @@ export interface ApplicationCommand { displayDescription?: string; inputType?: ApplicationCommandInputType; type?: ApplicationCommandType; - __isBunny?: true; + __bunny?: { + shouldHide: () => boolean; + }; +} + +export interface BunnyApplicationCommand extends ApplicationCommand { + shouldHide: () => boolean; } export enum ApplicationCommandInputType { diff --git a/src/lib/settings.ts b/src/lib/settings.ts index 1416d09..369a7a6 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -9,6 +9,7 @@ export interface Settings { enabled: boolean; currentThemeId?: string; }; + enableEvalCommand?: boolean; } export interface LoaderConfig {