Skip to content

Commit

Permalink
if this doesnt break i will be SHOCKED.
Browse files Browse the repository at this point in the history
  • Loading branch information
byeoon committed Apr 19, 2024
1 parent 7cb70e9 commit 843e53b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
16 changes: 8 additions & 8 deletions dist/vendetta.js

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ApplicationCommand, ApplicationCommandType } from "@types";
import { ApplicationCommand, ApplicationCommandInputType, ApplicationCommandType } from "@types";
import { commands as commandsModule } from "@metro/common";
import { after } from "@lib/patcher";
import { findByProps } from "./metro/filters";

const Commands = findByProps('getBuiltInCommands');
let commands: ApplicationCommand[] = [];

export function patchCommands() {
Expand All @@ -15,19 +17,19 @@ export function patchCommands() {
};
}

export function registerCommand(command: ApplicationCommand): () => 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!));
export function registerCommand(command: ApplicationCommand[]): void {
for(const commandE in command) {
const builtInCommands = commandsModule.getBuiltInCommands(ApplicationCommandType.CHAT, true, false);
builtInCommands.sort((a: ApplicationCommand, b: ApplicationCommand) => parseInt(b.id!) - parseInt(a.id!));
const lastCommand = builtInCommands[builtInCommands.length - 1];
const cmd = command[commandE];

const lastCommand = builtInCommands[builtInCommands.length - 1];
command[commandE] = {
id: (parseInt(lastCommand.id, 10) - 1).toString(),
...cmd,
};
}

// 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));
commands.push(...command);
}

17 changes: 15 additions & 2 deletions src/lib/commands/debug.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import { ApplicationCommand } from "@/def";
import { ApplicationCommand, ApplicationCommandOptionType } from "@/def";
import { Messages, clipboard, toasts } from "../metro/common";
import { getAssetIDByName } from "@/ui/assets";

// wip.
export default [
{
name: 'debug',
description: 'info'
}
] as ApplicationCommand[]

execute: {
const msg = [];
msg.push("This is a test command");
Messages.sendBotMessage("hi world!");
}
12 changes: 12 additions & 0 deletions src/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { registerCommand } from "../commands";
import debug from "./debug";
import reload from "./reload";

export function initCustomCommands(): void {
const customCommands = [
...debug,
...reload,
];

registerCommand(customCommands);
}
15 changes: 15 additions & 0 deletions src/lib/commands/reload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApplicationCommand, ApplicationCommandOptionType } from "@/def";
import { clipboard, toasts } from "../metro/common";
import { getAssetIDByName } from "@/ui/assets";
import { BundleUpdaterManager } from "../native";

export default [
{
name: 'reload',
description: 'Restarts discord.'
}
] as ApplicationCommand[]

execute: {
BundleUpdaterManager.reload()
}
2 changes: 1 addition & 1 deletion src/lib/metro/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const commands = findByProps("getBuiltInCommands");
export const navigation = findByProps("pushLazy");
export const navigationStack = findByProps("createStackNavigator");
export const NavigationNative = findByProps("NavigationContainer");

export const Messages = findByProps("sendBotMessage");
// Flux
export const Flux = findByProps("connectStores");
export const FluxDispatcher = findByProps("_currentDispatchActionType");
Expand Down

0 comments on commit 843e53b

Please sign in to comment.