diff options
author | Vendicated <vendicated@riseup.net> | 2023-03-02 21:16:03 +0100 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2023-03-02 21:17:15 +0100 |
commit | 5e2ec368ad6136b8b6e4d71011e1d4187ea81aa8 (patch) | |
tree | 36373066257469b3eb7788c6c280bcb2f26c6199 /src/utils/patches.ts | |
parent | ab8c93fbacb78d9358dfc5e8f5b2deb75e12d283 (diff) | |
download | Vencord-5e2ec368ad6136b8b6e4d71011e1d4187ea81aa8.tar.gz Vencord-5e2ec368ad6136b8b6e4d71011e1d4187ea81aa8.tar.bz2 Vencord-5e2ec368ad6136b8b6e4d71011e1d4187ea81aa8.zip |
patches: Make $self more robust
Diffstat (limited to 'src/utils/patches.ts')
-rw-r--r-- | src/utils/patches.ts | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/utils/patches.ts b/src/utils/patches.ts index 8ecd68e..0f83d40 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -27,9 +27,13 @@ export function canonicalizeMatch(match: RegExp | string) { return new RegExp(canonSource, match.flags); } -export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string) { - if (typeof replace === "function") return replace; - return replace.replaceAll("$self", `Vencord.Plugins.plugins.${pluginName}`); +export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string): string | ReplaceFn { + const self = `Vencord.Plugins.plugins[${JSON.stringify(pluginName)}]`; + + if (typeof replace !== "function") + return replace.replaceAll("$self", self); + + return (...args) => replace(...args).replaceAll("$self", self); } export function canonicalizeDescriptor<T>(descriptor: TypedPropertyDescriptor<T>, canonicalize: (value: T) => T) { |