Skip to content

Commit

Permalink
use getFunctionKeyBySource for sticker-related modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cafeed28 committed Sep 27, 2024
1 parent 258001f commit 259ee30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { Injector, common } from "replugged";
import { config, logger, userChanged, userInit } from "./misc";

import {
addStickerPreview,
emojiInfo,
isSendableSticker,
messageParser,
premiumInfo,
shouldAttachSticker,
stickerInfo,
stickerPreview,
stickerSendability,
Expand All @@ -23,12 +26,19 @@ export function start(): void {
logger.log("messageParser:", messageParser);
logger.log("emojiInfo:", emojiInfo);
logger.log("stickerInfo:", stickerInfo);
logger.log("shouldAttachSticker:", shouldAttachSticker);
logger.log("stickerSendability:", stickerSendability);
logger.log("isSendableSticker:", isSendableSticker);
logger.log("stickerPreview:", stickerPreview);
logger.log("addStickerPreview:", addStickerPreview);
logger.log("premiumInfo:", premiumInfo);
logger.log("users:", users);
}

if (!shouldAttachSticker || !isSendableSticker || !addStickerPreview) {
throw new Error("Failed to find function keys");
}

userInit();

users.addChangeListener(userChanged);
Expand Down Expand Up @@ -61,12 +71,12 @@ export function start(): void {
});

// Stickers
injector.instead(stickerInfo, "Hc", (args, orig) => {
injector.instead(stickerInfo, shouldAttachSticker, (args, orig) => {
if (!config.get("stickerSpoof")) return orig(...args);
return true;
});

injector.instead(stickerSendability, "kl", (args, orig) => {
injector.instead(stickerSendability, isSendableSticker, (args, orig) => {
if (!config.get("stickerSpoof")) return orig(...args);
const sticker = args[0] as Sticker;

Expand All @@ -76,7 +86,7 @@ export function start(): void {
return false;
});

injector.instead(stickerPreview, "eu", async (args, orig) => {
injector.instead(stickerPreview, addStickerPreview, async (args, orig) => {
if (!config.get("stickerSpoof")) return orig(...args);

const [channelId, sticker, d] = args;
Expand Down
24 changes: 9 additions & 15 deletions src/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { webpack } from "replugged";
const { filters, waitForModule, waitForProps } = webpack;
const { filters, getFunctionKeyBySource, waitForModule, waitForProps } = webpack;

import type { AnyFunction } from "replugged/dist/types";
import type { Attachment, OutgoingMessage } from "./types";
Expand Down Expand Up @@ -37,23 +37,17 @@ export const files = await waitForModule<AttachmentUploader>(
filters.bySource('"UPLOAD_ATTACHMENT_ADD_FILES"'),
);

interface StickerInfo {
Hc: AnyFunction; // shouldAttachSticker
}
export const stickerInfo = await waitForModule<StickerInfo>(
type AnyModule = Record<string, AnyFunction>;

export const stickerInfo = await waitForModule<AnyModule>(
filters.bySource(".ANIMATE_ON_INTERACTION?"),
);
export const shouldAttachSticker = getFunctionKeyBySource(stickerInfo, ".getStickerPreview(");

interface StickerSendability {
kl: AnyFunction; // isSendableSticker
}
export const stickerSendability = await waitForModule<StickerSendability>(
filters.bySource(".SENDABLE=0"),
);
export const stickerSendability = await waitForModule<AnyModule>(filters.bySource(".SENDABLE=0"));
export const isSendableSticker = getFunctionKeyBySource(stickerSendability, "0===");

interface StickerPreview {
eu: AnyFunction; // addStickerPreview
}
export const stickerPreview = await waitForModule<StickerPreview>(
export const stickerPreview = await waitForModule<AnyModule>(
filters.bySource('"ADD_STICKER_PREVIEW"'),
);
export const addStickerPreview = getFunctionKeyBySource(stickerPreview, '"ADD_STICKER_PREVIEW"');

0 comments on commit 259ee30

Please sign in to comment.