From fe3777b1b014080f2f6518e2f32522b106648b67 Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Fri, 25 Apr 2025 14:52:29 -0400 Subject: [PATCH] update companion (#243) --- src/plugins/devCompanion.dev/index.tsx | 5 +++-- src/plugins/devCompanion.dev/initWs.tsx | 17 +++++++++++++++-- src/plugins/devCompanion.dev/types/index.ts | 1 - src/plugins/devCompanion.dev/types/recieve.ts | 9 ++++++++- src/plugins/devCompanion.dev/types/send.ts | 9 ++++++++- src/plugins/devCompanion.dev/util.tsx | 3 ++- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/plugins/devCompanion.dev/index.tsx b/src/plugins/devCompanion.dev/index.tsx index 50afbb0f..23d4c6a3 100644 --- a/src/plugins/devCompanion.dev/index.tsx +++ b/src/plugins/devCompanion.dev/index.tsx @@ -61,9 +61,10 @@ export default definePlugin({ start() { // if we're running the reporter, we need to initws in the reporter file to avoid a race condition - if (!IS_COMPANION_TEST) - initWs(); + if (!IS_DEV) throw new Error("This plugin requires dev mode to run, please build with pnpm build --dev"); + initWs(); }, stop: stopWs, }); + diff --git a/src/plugins/devCompanion.dev/initWs.tsx b/src/plugins/devCompanion.dev/initWs.tsx index 36ee4778..c264338e 100644 --- a/src/plugins/devCompanion.dev/initWs.tsx +++ b/src/plugins/devCompanion.dev/initWs.tsx @@ -6,6 +6,7 @@ import { popNotice, showNotice } from "@api/Notices"; import ErrorBoundary from "@components/ErrorBoundary"; +import { getIntlMessageFromHash } from "@utils/discord"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; import { filters, findAll, search, wreq } from "@webpack"; import { React, Toasts, useState } from "@webpack/common"; @@ -125,7 +126,7 @@ export function initWs(isManual = false) { function reply(error?: string) { const toSend = { nonce: d.nonce, ok: !error } as Record; if (error) toSend.error = error; - logger.debug("Replying with:", toSend); + logger.debug(`Replying with:`, toSend); ws.send(JSON.stringify(toSend)); } function replyData(data: OutgoingMessage) { @@ -437,8 +438,20 @@ export function initWs(isManual = false) { }); break; } + case "i18n": { + const { hashedKey } = d.data; + replyData({ + type: "i18n", + ok: true, + data: { + value: getIntlMessageFromHash(hashedKey) + } + }); + break; + } default: - reply("Unknown Type " + (d as any).type); + // @ts-expect-error should be never + reply("Unknown Type " + d?.type); break; } }); diff --git a/src/plugins/devCompanion.dev/types/index.ts b/src/plugins/devCompanion.dev/types/index.ts index 532843e1..18bc6854 100644 --- a/src/plugins/devCompanion.dev/types/index.ts +++ b/src/plugins/devCompanion.dev/types/index.ts @@ -5,4 +5,3 @@ */ export * as Recieve from "./recieve"; -export * as Send from "./send"; diff --git a/src/plugins/devCompanion.dev/types/recieve.ts b/src/plugins/devCompanion.dev/types/recieve.ts index f14c5db2..8539461a 100644 --- a/src/plugins/devCompanion.dev/types/recieve.ts +++ b/src/plugins/devCompanion.dev/types/recieve.ts @@ -62,7 +62,7 @@ export type FindData = { args: FindNode[]; }; -export type IncomingMessage = DisablePlugin | RawId | DiffPatch | Reload | ExtractModule | TestPatch | TestFind | AllModules; +export type IncomingMessage = DisablePlugin | RawId | DiffPatch | Reload | ExtractModule | TestPatch | TestFind | AllModules | I18nLookup; export type FullIncomingMessage = IncomingMessage & { nonce: number; }; export type DisablePlugin = { @@ -73,6 +73,13 @@ export type DisablePlugin = { }; }; +export type I18nLookup = { + type: "i18n"; + data: { + hashedKey: string; + }; +}; + /** * @deprecated use {@link ExtractModule} instead */ diff --git a/src/plugins/devCompanion.dev/types/send.ts b/src/plugins/devCompanion.dev/types/send.ts index 0f1594f3..9daf1418 100644 --- a/src/plugins/devCompanion.dev/types/send.ts +++ b/src/plugins/devCompanion.dev/types/send.ts @@ -8,7 +8,7 @@ import { ReporterData as IReporterData } from "debug/reporterData"; export type ReporterData = IReporterData; -export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId) & Base; +export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId | I18nValue) & Base; export type FullOutgoingMessage = OutgoingMessage & Nonce; export type Base = { @@ -34,6 +34,13 @@ export type ModuleResult = { }; // #region valid payloads +export type I18nValue = { + type: "i18n"; + data: { + value: string; + }; +}; + export type Report = { type: "report"; data: ReporterData; diff --git a/src/plugins/devCompanion.dev/util.tsx b/src/plugins/devCompanion.dev/util.tsx index ca6304ed..436856f1 100644 --- a/src/plugins/devCompanion.dev/util.tsx +++ b/src/plugins/devCompanion.dev/util.tsx @@ -9,11 +9,12 @@ import { Settings } from "@api/Settings"; import { canonicalizeMatch } from "@utils/patches"; import { CodeFilter, stringMatches, wreq } from "@webpack"; import { Toasts } from "@webpack/common"; +import { WebpackPatcher } from "Vencord"; import { logger, settings as companionSettings } from "."; import { FindNode } from "./types/recieve"; -const { WebpackPatcher: { getFactoryPatchedBy, getFactoryPatchedSource } } = require("Vencord") as typeof import("Vencord"); +const { getFactoryPatchedBy, getFactoryPatchedSource } = WebpackPatcher; /** * extracts the patched module, if there is no patched module, throws an error