diff --git a/src/def.d.ts b/src/def.d.ts index 44671df..7bd1aa6 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -63,6 +63,66 @@ interface Settings { developerSettings: boolean; } +export interface ApplicationCommand { + description: string; + name: string; + options: ApplicationCommandOption[]; + execute: (args: any[], ctx: CommandContext) => CommandResult | void | Promise | Promise; + id?: string; + applicationId: string; + displayName: string; + displayDescription: string; + inputType: ApplicationCommandInputType; + type: ApplicationCommandType; +} + +export enum ApplicationCommandInputType { + BUILT_IN, + BUILT_IN_TEXT, + BUILT_IN_INTEGRATION, + BOT, + PLACEHOLDER, +} + +export interface ApplicationCommandOption { + name: string; + description: string; + required?: boolean; + type: ApplicationCommandOptionType; + displayName: string; + displayDescription: string; +} + +export enum ApplicationCommandOptionType { + SUB_COMMAND = 1, + SUB_COMMAND_GROUP, + STRING, + INTEGER, + BOOLEAN, + USER, + CHANNEL, + ROLE, + MENTIONABLE, + NUMBER, + ATTACHMENT, +} + +export enum ApplicationCommandType { + CHAT = 1, + USER, + MESSAGE, +} + +export interface CommandContext { + channel: any; + guild: any; +} + +export interface CommandResult { + content: string; + tts?: boolean; +} + interface RNConstants extends _RN.PlatformConstants { // Android Version: number; @@ -174,7 +234,10 @@ interface VendettaObject { stopPlugin: (id: string) => void; removePlugin: (id: string) => void; getSettings: (id: string) => JSX.Element; - } + }; + commands: { + registerCommand: (command: ApplicationCommand) => () => void; + }; settings: Settings; logger: Logger; version: string; diff --git a/src/index.ts b/src/index.ts index f3eb61d..a7df50f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import { fixTheme } from "@ui/fixTheme"; import { connectToDebugger, patchLogHook, versionHash } from "@lib/debug"; import { plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings } from "@lib/plugins"; import settings from "@lib/settings"; +import { registerCommand } from "./lib/commands"; console.log("Hello from Vendetta!"); @@ -50,7 +51,10 @@ async function init() { evalPlugin: evalPlugin, stopPlugin: stopPlugin, removePlugin: removePlugin, - getSettings: getSettings + getSettings: getSettings, + }, + commands: { + registerCommand: registerCommand, }, settings: settings, logger: logger, @@ -65,7 +69,7 @@ async function init() { erroredOnLoad = true; alert(`Vendetta failed to initialize... ${e.stack || e.toString()}`); } - + if (!erroredOnLoad) logger.log("Vendetta is ready!"); }; diff --git a/src/lib/commands.ts b/src/lib/commands.ts new file mode 100644 index 0000000..9a12346 --- /dev/null +++ b/src/lib/commands.ts @@ -0,0 +1,26 @@ +import { ApplicationCommand } from "@types"; +import { findByProps } from "@metro/filters"; +import { after } from "@lib/patcher"; + +const commandsModule = findByProps("getBuiltInCommands") + +let commands: ApplicationCommand[] = []; + +after("getBuiltInCommands", commandsModule, (args, res) => res.concat(commands)); + +export function registerCommand(command: ApplicationCommand): () => void { + // Get built in commands + const builtInCommands = commandsModule.getBuiltInCommands(1, true, false); + builtInCommands.sort(function (a: ApplicationCommand, b: ApplicationCommand) { return parseInt(b.id!) - parseInt(a.id!) }); + + const lastCommand = builtInCommands[builtInCommands.length - 1]; + + // Override the new command's id to the last command id - 1 + command.id = (parseInt(lastCommand.id, 10) - 1).toString(); + + // Add it to the commands array + commands.push(command); + + // Return command id so it can be unregistered + return () => commands = commands.filter(({ id }) => id !== command.id); +} \ No newline at end of file