diff --git a/src/plugins/fakeNitro/index.ts b/src/plugins/fakeNitro/index.ts index 3441cd4f..efec9a8b 100644 --- a/src/plugins/fakeNitro/index.ts +++ b/src/plugins/fakeNitro/index.ts @@ -24,14 +24,13 @@ import { getCurrentGuild } from "@utils/discord"; import { proxyLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy, findStoreLazy } from "@webpack"; -import { ChannelStore, EmojiStore, FluxDispatcher, lodash, Parser, PermissionStore, UserSettingsActionCreators, UserStore } from "@webpack/common"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { ChannelStore, EmojiStore, FluxDispatcher, lodash, Parser, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common"; import type { Message } from "discord-types/general"; import { applyPalette, GIFEncoder, quantize } from "gifenc"; import type { ReactElement, ReactNode } from "react"; const DRAFT_TYPE = 0; -const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR"); const StickerStore = findStoreLazy("StickersStore") as { getPremiumPacks(): StickerPack[]; getAllGuildStickers(): Map; @@ -756,7 +755,7 @@ export default definePlugin({ gif.finish(); const file = new File([gif.bytesView()], `${stickerId}.gif`, { type: "image/gif" }); - promptToUpload([file], ChannelStore.getChannel(channelId), DRAFT_TYPE); + UploadHandler.promptToUpload([file], ChannelStore.getChannel(channelId), DRAFT_TYPE); }, start() { diff --git a/src/plugins/petpet/index.ts b/src/plugins/petpet/index.ts index 0bfd21af..3f974325 100644 --- a/src/plugins/petpet/index.ts +++ b/src/plugins/petpet/index.ts @@ -20,7 +20,8 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, Co import { Devs } from "@utils/constants"; import { makeLazy } from "@utils/lazy"; import definePlugin from "@utils/types"; -import { findByCodeLazy, findByPropsLazy } from "@webpack"; +import { findByPropsLazy } from "@webpack"; +import { UploadHandler, UserUtils } from "@webpack/common"; import { applyPalette, GIFEncoder, quantize } from "gifenc"; const DRAFT_TYPE = 0; @@ -35,8 +36,6 @@ const getFrames = makeLazy(() => Promise.all( )) ); -const fetchUser = findByCodeLazy(".USER("); -const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR"); const UploadStore = findByPropsLazy("getUploads"); function loadImage(source: File | string) { @@ -70,7 +69,7 @@ async function resolveImage(options: Argument[], ctx: CommandContext, noServerPf return opt.value; case "user": try { - const user = await fetchUser(opt.value); + const user = await UserUtils.getUser(opt.value); return user.getAvatarURL(noServerPfp ? void 0 : ctx.guild?.id, 2048).replace(/\?size=\d+$/, "?size=2048"); } catch (err) { console.error("[petpet] Failed to fetch user\n", err); @@ -175,7 +174,7 @@ export default definePlugin({ const file = new File([gif.bytesView()], "petpet.gif", { type: "image/gif" }); // Immediately after the command finishes, Discord clears all input, including pending attachments. // Thus, setTimeout is needed to make this execute after Discord cleared the input - setTimeout(() => promptToUpload([file], cmdCtx.channel, DRAFT_TYPE), 10); + setTimeout(() => UploadHandler.promptToUpload([file], cmdCtx.channel, DRAFT_TYPE), 10); }, }, ] diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 487a4bc7..6de57c92 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -17,7 +17,7 @@ */ import { proxyLazy } from "@utils/lazy"; -import type { User } from "discord-types/general"; +import type { Channel, User } from "discord-types/general"; // eslint-disable-next-line path-alias/no-relative import { _resolveReady, filters, find, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack"; @@ -94,6 +94,9 @@ export function showToast(message: string, type = ToastType.MESSAGE) { } export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise; }; +export const UploadHandler = findByPropsLazy("showUploadFileSizeExceededError", "promptToUpload") as { + promptToUpload: (files: File[], channel: Channel, draftType: Number) => void; +}; export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetImage") as { fetchAssetIds: (applicationId: string, e: string[]) => Promise;