From 06824c273fc3eb245fff3567d2c3223340e3729d Mon Sep 17 00:00:00 2001 From: lewisakura Date: Mon, 3 Jun 2024 13:01:34 +0100 Subject: [PATCH 01/25] chore: security advisory link for blank issues [skip ci] (#2542) --- .github/ISSUE_TEMPLATE/blank.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/blank.yml b/.github/ISSUE_TEMPLATE/blank.yml index e8ca246de..2439d86a7 100644 --- a/.github/ISSUE_TEMPLATE/blank.yml +++ b/.github/ISSUE_TEMPLATE/blank.yml @@ -12,7 +12,8 @@ body: DO NOT USE THIS FORM, unless - you are a vencord contributor - you were given explicit permission to use this form by a moderator in our support server - - you are filing a security related report + + DO NOT USE THIS FORM FOR SECURITY RELATED ISSUES. [CREATE A SECURITY ADVISORY INSTEAD.](https://github.com/Vendicated/Vencord/security/advisories/new) - type: textarea id: content From 8fd5d068da549c7e296c31438358061e310a9bea Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 1 Jun 2024 19:13:27 +0200 Subject: [PATCH 02/25] fix(css): brand-experiment is now brand-500 --- src/api/Notifications/NotificationComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/Notifications/NotificationComponent.tsx b/src/api/Notifications/NotificationComponent.tsx index caa4b64ef..d07143c45 100644 --- a/src/api/Notifications/NotificationComponent.tsx +++ b/src/api/Notifications/NotificationComponent.tsx @@ -113,7 +113,7 @@ export default ErrorBoundary.wrap(function NotificationComponent({ {timeout !== 0 && !permanent && (
)} From ed5ae2ba5c92fe24d73d2e7ed8dd4ca30e1a0faf Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:39:01 -0300 Subject: [PATCH 03/25] Add shortcut for lazy loading chunks --- scripts/generateReport.ts | 13 +- src/api/Settings.ts | 2 +- src/debug/loadLazyChunks.ts | 167 ++++++++++++++++++++++++++ src/debug/runReporter.ts | 163 ++----------------------- src/plugins/consoleShortcuts/index.ts | 2 + src/plugins/index.ts | 1 - src/plugins/partyMode/index.ts | 3 +- src/utils/Logger.ts | 2 +- 8 files changed, 191 insertions(+), 162 deletions(-) create mode 100644 src/debug/loadLazyChunks.ts diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 0fde48637..cf4210779 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -241,17 +241,26 @@ page.on("console", async e => { error: await maybeGetError(e.args()[3]) ?? "Unknown error" }); + break; + case "LazyChunkLoader:": + console.error(await getText()); + + switch (message) { + case "A fatal error occurred:": + process.exit(1); + } + break; case "Reporter:": console.error(await getText()); switch (message) { + case "A fatal error occurred:": + process.exit(1); case "Webpack Find Fail:": process.exitCode = 1; report.badWebpackFinds.push(otherMessage); break; - case "A fatal error occurred:": - process.exit(1); case "Finished test": await browser.close(); await printReport(); diff --git a/src/api/Settings.ts b/src/api/Settings.ts index b94e6a3fd..70ba0bd4a 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -129,7 +129,7 @@ export const SettingsStore = new SettingsStoreClass(settings, { if (path === "plugins" && key in plugins) return target[key] = { - enabled: plugins[key].required ?? plugins[key].enabledByDefault ?? false + enabled: IS_REPORTER ?? plugins[key].required ?? plugins[key].enabledByDefault ?? false }; // Since the property is not set, check if this is a plugin's setting and if so, try to resolve diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts new file mode 100644 index 000000000..d8f84335c --- /dev/null +++ b/src/debug/loadLazyChunks.ts @@ -0,0 +1,167 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Logger } from "@utils/Logger"; +import { canonicalizeMatch } from "@utils/patches"; +import * as Webpack from "@webpack"; +import { wreq } from "@webpack"; + +const LazyChunkLoaderLogger = new Logger("LazyChunkLoader"); + +export async function loadLazyChunks() { + try { + LazyChunkLoaderLogger.log("Loading all chunks..."); + + const validChunks = new Set(); + const invalidChunks = new Set(); + const deferredRequires = new Set(); + + let chunksSearchingResolve: (value: void | PromiseLike) => void; + const chunksSearchingDone = new Promise(r => chunksSearchingResolve = r); + + // True if resolved, false otherwise + const chunksSearchPromises = [] as Array<() => boolean>; + + const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); + + async function searchAndLoadLazyChunks(factoryCode: string) { + const lazyChunks = factoryCode.matchAll(LazyChunkRegex); + const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>(); + + // Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before + // the chunk containing the component + const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT"); + + await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { + const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => m[1]) : []; + + if (chunkIds.length === 0) { + return; + } + + let invalidChunkGroup = false; + + for (const id of chunkIds) { + if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; + + const isWasm = await fetch(wreq.p + wreq.u(id)) + .then(r => r.text()) + .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + + if (isWasm && IS_WEB) { + invalidChunks.add(id); + invalidChunkGroup = true; + continue; + } + + validChunks.add(id); + } + + if (!invalidChunkGroup) { + validChunkGroups.add([chunkIds, entryPoint]); + } + })); + + // Loads all found valid chunk groups + await Promise.all( + Array.from(validChunkGroups) + .map(([chunkIds]) => + Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { }))) + ) + ); + + // Requires the entry points for all valid chunk groups + for (const [, entryPoint] of validChunkGroups) { + try { + if (shouldForceDefer) { + deferredRequires.add(entryPoint); + continue; + } + + if (wreq.m[entryPoint]) wreq(entryPoint as any); + } catch (err) { + console.error(err); + } + } + + // setImmediate to only check if all chunks were loaded after this function resolves + // We check if all chunks were loaded every time a factory is loaded + // If we are still looking for chunks in the other factories, the array will have that factory's chunk search promise not resolved + // But, if all chunk search promises are resolved, this means we found every lazy chunk loaded by Discord code and manually loaded them + setTimeout(() => { + let allResolved = true; + + for (let i = 0; i < chunksSearchPromises.length; i++) { + const isResolved = chunksSearchPromises[i](); + + if (isResolved) { + // Remove finished promises to avoid having to iterate through a huge array everytime + chunksSearchPromises.splice(i--, 1); + } else { + allResolved = false; + } + } + + if (allResolved) chunksSearchingResolve(); + }, 0); + } + + Webpack.factoryListeners.add(factory => { + let isResolved = false; + searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true); + + chunksSearchPromises.push(() => isResolved); + }); + + for (const factoryId in wreq.m) { + let isResolved = false; + searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true); + + chunksSearchPromises.push(() => isResolved); + } + + await chunksSearchingDone; + + // Require deferred entry points + for (const deferredRequire of deferredRequires) { + wreq!(deferredRequire as any); + } + + // All chunks Discord has mapped to asset files, even if they are not used anymore + const allChunks = [] as string[]; + + // Matches "id" or id: + for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { + const id = currentMatch[1] ?? currentMatch[2]; + if (id == null) continue; + + allChunks.push(id); + } + + if (allChunks.length === 0) throw new Error("Failed to get all chunks"); + + // Chunks that are not loaded (not used) by Discord code anymore + const chunksLeft = allChunks.filter(id => { + return !(validChunks.has(id) || invalidChunks.has(id)); + }); + + await Promise.all(chunksLeft.map(async id => { + const isWasm = await fetch(wreq.p + wreq.u(id)) + .then(r => r.text()) + .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + + // Loads and requires a chunk + if (!isWasm) { + await wreq.e(id as any); + if (wreq.m[id]) wreq(id as any); + } + })); + + LazyChunkLoaderLogger.log("Finished loading all chunks!"); + } catch (e) { + LazyChunkLoaderLogger.log("A fatal error occurred:", e); + } +} diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 61c9f162b..6c7a2a03f 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -5,171 +5,22 @@ */ import { Logger } from "@utils/Logger"; -import { canonicalizeMatch } from "@utils/patches"; import * as Webpack from "@webpack"; -import { wreq } from "@webpack"; import { patches } from "plugins"; +import { loadLazyChunks } from "./loadLazyChunks"; + const ReporterLogger = new Logger("Reporter"); async function runReporter() { - ReporterLogger.log("Starting test..."); - try { - const validChunks = new Set(); - const invalidChunks = new Set(); - const deferredRequires = new Set(); + ReporterLogger.log("Starting test..."); - let chunksSearchingResolve: (value: void | PromiseLike) => void; - const chunksSearchingDone = new Promise(r => chunksSearchingResolve = r); + let loadLazyChunksResolve: (value: void | PromiseLike) => void; + const loadLazyChunksDone = new Promise(r => loadLazyChunksResolve = r); - // True if resolved, false otherwise - const chunksSearchPromises = [] as Array<() => boolean>; - - const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); - - async function searchAndLoadLazyChunks(factoryCode: string) { - const lazyChunks = factoryCode.matchAll(LazyChunkRegex); - const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>(); - - // Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before - // the chunk containing the component - const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT"); - - await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { - const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => m[1]) : []; - - if (chunkIds.length === 0) { - return; - } - - let invalidChunkGroup = false; - - for (const id of chunkIds) { - if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; - - const isWasm = await fetch(wreq.p + wreq.u(id)) - .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); - - if (isWasm && IS_WEB) { - invalidChunks.add(id); - invalidChunkGroup = true; - continue; - } - - validChunks.add(id); - } - - if (!invalidChunkGroup) { - validChunkGroups.add([chunkIds, entryPoint]); - } - })); - - // Loads all found valid chunk groups - await Promise.all( - Array.from(validChunkGroups) - .map(([chunkIds]) => - Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { }))) - ) - ); - - // Requires the entry points for all valid chunk groups - for (const [, entryPoint] of validChunkGroups) { - try { - if (shouldForceDefer) { - deferredRequires.add(entryPoint); - continue; - } - - if (wreq.m[entryPoint]) wreq(entryPoint as any); - } catch (err) { - console.error(err); - } - } - - // setImmediate to only check if all chunks were loaded after this function resolves - // We check if all chunks were loaded every time a factory is loaded - // If we are still looking for chunks in the other factories, the array will have that factory's chunk search promise not resolved - // But, if all chunk search promises are resolved, this means we found every lazy chunk loaded by Discord code and manually loaded them - setTimeout(() => { - let allResolved = true; - - for (let i = 0; i < chunksSearchPromises.length; i++) { - const isResolved = chunksSearchPromises[i](); - - if (isResolved) { - // Remove finished promises to avoid having to iterate through a huge array everytime - chunksSearchPromises.splice(i--, 1); - } else { - allResolved = false; - } - } - - if (allResolved) chunksSearchingResolve(); - }, 0); - } - - Webpack.beforeInitListeners.add(async () => { - ReporterLogger.log("Loading all chunks..."); - - Webpack.factoryListeners.add(factory => { - let isResolved = false; - searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true); - - chunksSearchPromises.push(() => isResolved); - }); - - // setImmediate to only search the initial factories after Discord initialized the app - // our beforeInitListeners are called before Discord initializes the app - setTimeout(() => { - for (const factoryId in wreq.m) { - let isResolved = false; - searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true); - - chunksSearchPromises.push(() => isResolved); - } - }, 0); - }); - - await chunksSearchingDone; - - // Require deferred entry points - for (const deferredRequire of deferredRequires) { - wreq!(deferredRequire as any); - } - - // All chunks Discord has mapped to asset files, even if they are not used anymore - const allChunks = [] as string[]; - - // Matches "id" or id: - for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { - const id = currentMatch[1] ?? currentMatch[2]; - if (id == null) continue; - - allChunks.push(id); - } - - if (allChunks.length === 0) throw new Error("Failed to get all chunks"); - - // Chunks that are not loaded (not used) by Discord code anymore - const chunksLeft = allChunks.filter(id => { - return !(validChunks.has(id) || invalidChunks.has(id)); - }); - - await Promise.all(chunksLeft.map(async id => { - const isWasm = await fetch(wreq.p + wreq.u(id)) - .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); - - // Loads and requires a chunk - if (!isWasm) { - await wreq.e(id as any); - if (wreq.m[id]) wreq(id as any); - } - })); - - ReporterLogger.log("Finished loading all chunks!"); + Webpack.beforeInitListeners.add(() => loadLazyChunks().then((loadLazyChunksResolve))); + await loadLazyChunksDone; for (const patch of patches) { if (!patch.all) { diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index ee86b5fcf..0a1323e75 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -25,6 +25,7 @@ import definePlugin, { PluginNative, StartAt } from "@utils/types"; import * as Webpack from "@webpack"; import { extract, filters, findAll, findModuleId, search } from "@webpack"; import * as Common from "@webpack/common"; +import { loadLazyChunks } from "debug/loadLazyChunks"; import type { ComponentType } from "react"; const DESKTOP_ONLY = (f: string) => () => { @@ -82,6 +83,7 @@ function makeShortcuts() { wpsearch: search, wpex: extract, wpexs: (code: string) => extract(findModuleId(code)!), + loadLazyChunks: IS_DEV ? loadLazyChunks : () => { throw new Error("loadLazyChunks is dev only."); }, find, findAll: findAll, findByProps, diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 53ab7983a..32bfe7e97 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -44,7 +44,6 @@ const settings = Settings.plugins; export function isPluginEnabled(p: string) { return ( - IS_REPORTER || Plugins[p]?.required || Plugins[p]?.isDependency || settings[p]?.enabled diff --git a/src/plugins/partyMode/index.ts b/src/plugins/partyMode/index.ts index 56c19c02c..c40f2e3c7 100644 --- a/src/plugins/partyMode/index.ts +++ b/src/plugins/partyMode/index.ts @@ -18,7 +18,7 @@ import { definePluginSettings, migratePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { FluxDispatcher } from "@webpack/common"; const enum Intensity { @@ -46,6 +46,7 @@ export default definePlugin({ name: "PartyMode", description: "Allows you to use party mode cause the party never ends ✨", authors: [Devs.UwUDev], + reporterTestable: ReporterTestable.None, settings, start() { diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 5296184d4..22a381360 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -32,7 +32,7 @@ export class Logger { constructor(public name: string, public color: string = "white") { } private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") { - if (IS_REPORTER) { + if (IS_REPORTER && IS_WEB) { console[level]("[Vencord]", this.name + ":", ...args); return; } From 23584393a9b2ebbdb2ff1212fb0dae1300702caf Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:39:58 -0300 Subject: [PATCH 04/25] NoPendingCount: Fix for message requests --- src/plugins/noPendingCount/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/noPendingCount/index.ts b/src/plugins/noPendingCount/index.ts index 29458df9d..57a65f52c 100644 --- a/src/plugins/noPendingCount/index.ts +++ b/src/plugins/noPendingCount/index.ts @@ -62,6 +62,16 @@ export default definePlugin({ replace: "return 0;" } }, + // New message requests hook + { + find: "useNewMessageRequestsCount:", + predicate: () => settings.store.hideMessageRequestsCount, + replacement: { + match: /getNonChannelAckId\(\i\.\i\.MESSAGE_REQUESTS\).+?return /, + replace: "$&0;" + } + }, + // Old message requests hook { find: "getMessageRequestsCount(){", predicate: () => settings.store.hideMessageRequestsCount, From 9ab7b8b9c98b38a7502ee363c7f7c6d697808f72 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 5 Jun 2024 23:45:27 +0200 Subject: [PATCH 05/25] experiments: remove obsolete isStaff patch; rename ServerProfile -> ServerInfo --- src/plugins/experiments/index.tsx | 54 ++++--------------- .../GuildInfoModal.tsx} | 6 +-- src/plugins/serverInfo/README.md | 7 +++ .../{serverProfile => serverInfo}/index.tsx | 14 ++--- .../{serverProfile => serverInfo}/styles.css | 0 src/plugins/serverProfile/README.md | 7 --- 6 files changed, 28 insertions(+), 60 deletions(-) rename src/plugins/{serverProfile/GuildProfileModal.tsx => serverInfo/GuildInfoModal.tsx} (98%) create mode 100644 src/plugins/serverInfo/README.md rename src/plugins/{serverProfile => serverInfo}/index.tsx (65%) rename src/plugins/{serverProfile => serverInfo}/styles.css (100%) delete mode 100644 src/plugins/serverProfile/README.md diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx index 50b9521f9..626e06a99 100644 --- a/src/plugins/experiments/index.tsx +++ b/src/plugins/experiments/index.tsx @@ -16,31 +16,19 @@ * along with this program. If not, see . */ -import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { ErrorCard } from "@components/ErrorCard"; import { Devs } from "@utils/constants"; -import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin from "@utils/types"; import { findByPropsLazy } from "@webpack"; -import { Forms, React, UserStore } from "@webpack/common"; -import { User } from "discord-types/general"; +import { Forms, React } from "@webpack/common"; const KbdStyles = findByPropsLazy("key", "removeBuildOverride"); -const settings = definePluginSettings({ - enableIsStaff: { - description: "Enable isStaff", - type: OptionType.BOOLEAN, - default: false, - restartNeeded: true - } -}); - export default definePlugin({ name: "Experiments", - description: "Enable Access to Experiments in Discord!", + description: "Enable Access to Experiments & other dev-only features in Discord!", authors: [ Devs.Megu, Devs.Ven, @@ -48,7 +36,6 @@ export default definePlugin({ Devs.BanTheNons, Devs.Nuckyz ], - settings, patches: [ { @@ -65,20 +52,6 @@ export default definePlugin({ replace: "$1=!0;" } }, - { - find: '"isStaff",', - predicate: () => settings.store.enableIsStaff, - replacement: [ - { - match: /(?<=>)(\i)\.hasFlag\((\i\.\i)\.STAFF\)(?=})/, - replace: (_, user, flags) => `$self.isStaff(${user},${flags})` - }, - { - match: /hasFreePremium\(\){return this.isStaff\(\)\s*?\|\|/, - replace: "hasFreePremium(){return ", - } - ] - }, { find: 'H1,title:"Experiments"', replacement: { @@ -88,15 +61,6 @@ export default definePlugin({ } ], - isStaff(user: User, flags: any) { - try { - return UserStore.getCurrentUser()?.id === user.id || user.hasFlag(flags.STAFF); - } catch (err) { - new Logger("Experiments").error(err); - return user.hasFlag(flags.STAFF); - } - }, - settingsAboutComponent: () => { const isMacOS = navigator.platform.includes("Mac"); const modKey = isMacOS ? "cmd" : "ctrl"; @@ -105,14 +69,10 @@ export default definePlugin({ More Information - You can enable client DevTools{" "} + You can open Discord's DevTools via {" "} {modKey} +{" "} {altKey} +{" "} O{" "} - after enabling isStaff below - - - and then toggling Enable DevTools in the Developer Options tab in settings. ); @@ -128,6 +88,12 @@ export default definePlugin({ Only use experiments if you know what you're doing. Vencord is not responsible for any damage caused by enabling experiments. + + If you don't know what an experiment does, ignore it. Do not ask us what experiments do either, we probably don't know. + + + + No, you cannot use server-side features like checking the "Send to Client" box. ), { noop: true }) diff --git a/src/plugins/serverProfile/GuildProfileModal.tsx b/src/plugins/serverInfo/GuildInfoModal.tsx similarity index 98% rename from src/plugins/serverProfile/GuildProfileModal.tsx rename to src/plugins/serverInfo/GuildInfoModal.tsx index 8e6f60518..bed520b67 100644 --- a/src/plugins/serverProfile/GuildProfileModal.tsx +++ b/src/plugins/serverInfo/GuildInfoModal.tsx @@ -20,10 +20,10 @@ const FriendRow = findExportedComponentLazy("FriendRow"); const cl = classNameFactory("vc-gp-"); -export function openGuildProfileModal(guild: Guild) { +export function openGuildInfoModal(guild: Guild) { openModal(props => - + ); } @@ -53,7 +53,7 @@ function renderTimestamp(timestamp: number) { ); } -function GuildProfileModal({ guild }: GuildProps) { +function GuildInfoModal({ guild }: GuildProps) { const [friendCount, setFriendCount] = useState(); const [blockedCount, setBlockedCount] = useState(); diff --git a/src/plugins/serverInfo/README.md b/src/plugins/serverInfo/README.md new file mode 100644 index 000000000..98c9013e0 --- /dev/null +++ b/src/plugins/serverInfo/README.md @@ -0,0 +1,7 @@ +# ServerInfo + +Allows you to view info about servers and see friends and blocked users + +![](https://github.com/Vendicated/Vencord/assets/45497981/a49783b5-e8fc-41d8-968f-58600e9f6580) +![](https://github.com/Vendicated/Vencord/assets/45497981/5efc158a-e671-4196-a15a-77edf79a2630) +![Available as "Server Profile" option in the server context menu](https://github.com/Vendicated/Vencord/assets/45497981/f43be943-6dc4-4232-9709-fbeb382d8e54) diff --git a/src/plugins/serverProfile/index.tsx b/src/plugins/serverInfo/index.tsx similarity index 65% rename from src/plugins/serverProfile/index.tsx rename to src/plugins/serverInfo/index.tsx index 9d495c9d3..be3172f01 100644 --- a/src/plugins/serverProfile/index.tsx +++ b/src/plugins/serverInfo/index.tsx @@ -5,30 +5,32 @@ */ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { migratePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; import { Menu } from "@webpack/common"; import { Guild } from "discord-types/general"; -import { openGuildProfileModal } from "./GuildProfileModal"; +import { openGuildInfoModal } from "./GuildInfoModal"; const Patch: NavContextMenuPatchCallback = (children, { guild }: { guild: Guild; }) => { const group = findGroupChildrenByChildId("privacy", children); group?.push( openGuildProfileModal(guild)} + action={() => openGuildInfoModal(guild)} /> ); }; +migratePluginSettings("ServerInfo", "ServerProfile"); // what was I thinking with this name lmao export default definePlugin({ - name: "ServerProfile", - description: "Allows you to view info about a server by right clicking it in the server list", + name: "ServerInfo", + description: "Allows you to view info about a server", authors: [Devs.Ven, Devs.Nuckyz], - tags: ["guild", "info"], + tags: ["guild", "info", "ServerProfile"], contextMenus: { "guild-context": Patch, "guild-header-popout": Patch diff --git a/src/plugins/serverProfile/styles.css b/src/plugins/serverInfo/styles.css similarity index 100% rename from src/plugins/serverProfile/styles.css rename to src/plugins/serverInfo/styles.css diff --git a/src/plugins/serverProfile/README.md b/src/plugins/serverProfile/README.md deleted file mode 100644 index 9da70e74e..000000000 --- a/src/plugins/serverProfile/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# ServerProfile - -Allows you to view info about servers and see friends and blocked users - -![image](https://github.com/Vendicated/Vencord/assets/45497981/a49783b5-e8fc-41d8-968f-58600e9f6580) -![image](https://github.com/Vendicated/Vencord/assets/45497981/5efc158a-e671-4196-a15a-77edf79a2630) -![image](https://github.com/Vendicated/Vencord/assets/45497981/f43be943-6dc4-4232-9709-fbeb382d8e54) From 0aa7bef9fa86258f0b89afbc7a3e9a979d460044 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Thu, 6 Jun 2024 07:19:53 +0800 Subject: [PATCH 06/25] new plugin AppleMusicRichPresence (#2455) Co-authored-by: Vendicated --- .vscode/settings.json | 2 + src/components/PluginSettings/index.tsx | 3 +- src/plugins/appleMusic.desktop/README.md | 9 + src/plugins/appleMusic.desktop/index.tsx | 253 +++++++++++++++++++++++ src/plugins/appleMusic.desktop/native.ts | 120 +++++++++++ src/utils/types.ts | 4 + 6 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 src/plugins/appleMusic.desktop/README.md create mode 100644 src/plugins/appleMusic.desktop/index.tsx create mode 100644 src/plugins/appleMusic.desktop/native.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index fa543b38c..8be0795f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,8 @@ "typescript.preferences.quoteStyle": "double", "javascript.preferences.quoteStyle": "double", + "eslint.experimental.useFlatConfig": false, + "gitlens.remotes": [ { "domain": "codeberg.org", diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index e6b2cf1fb..9c26a9cf1 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -261,8 +261,9 @@ export default function PluginSettings() { plugins = []; requiredPlugins = []; + const showApi = searchValue.value === "API"; for (const p of sortedPlugins) { - if (!p.options && p.name.endsWith("API") && searchValue.value !== "API") + if (p.hidden || (!p.options && p.name.endsWith("API") && !showApi)) continue; if (!pluginFilter(p)) continue; diff --git a/src/plugins/appleMusic.desktop/README.md b/src/plugins/appleMusic.desktop/README.md new file mode 100644 index 000000000..52ab93bfd --- /dev/null +++ b/src/plugins/appleMusic.desktop/README.md @@ -0,0 +1,9 @@ +# AppleMusicRichPresence + +This plugin enables Discord rich presence for your Apple Music! (This only works on macOS with the Music app.) + +![Screenshot of the activity in Discord](https://github.com/Vendicated/Vencord/assets/70191398/1f811090-ab5f-4060-a9ee-d0ac44a1d3c0) + +## Configuration + +For the customizable activity format strings, you can use several special strings to include track data in activities! `{name}` is replaced with the track name; `{artist}` is replaced with the artist(s)' name(s); and `{album}` is replaced with the album name. diff --git a/src/plugins/appleMusic.desktop/index.tsx b/src/plugins/appleMusic.desktop/index.tsx new file mode 100644 index 000000000..16591028d --- /dev/null +++ b/src/plugins/appleMusic.desktop/index.tsx @@ -0,0 +1,253 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType, PluginNative } from "@utils/types"; +import { ApplicationAssetUtils, FluxDispatcher, Forms } from "@webpack/common"; + +const Native = VencordNative.pluginHelpers.AppleMusic as PluginNative; + +interface ActivityAssets { + large_image?: string; + large_text?: string; + small_image?: string; + small_text?: string; +} + +interface ActivityButton { + label: string; + url: string; +} + +interface Activity { + state: string; + details?: string; + timestamps?: { + start?: number; + end?: number; + }; + assets?: ActivityAssets; + buttons?: Array; + name: string; + application_id: string; + metadata?: { + button_urls?: Array; + }; + type: number; + flags: number; +} + +const enum ActivityType { + PLAYING = 0, + LISTENING = 2, +} + +const enum ActivityFlag { + INSTANCE = 1 << 0, +} + +export interface TrackData { + name: string; + album: string; + artist: string; + + appleMusicLink?: string; + songLink?: string; + + albumArtwork?: string; + artistArtwork?: string; + + playerPosition: number; + duration: number; +} + +const enum AssetImageType { + Album = "Album", + Artist = "Artist", +} + +const applicationId = "1239490006054207550"; + +function setActivity(activity: Activity | null) { + FluxDispatcher.dispatch({ + type: "LOCAL_ACTIVITY_UPDATE", + activity, + socketId: "AppleMusic", + }); +} + +const settings = definePluginSettings({ + activityType: { + type: OptionType.SELECT, + description: "Which type of activity", + options: [ + { label: "Playing", value: ActivityType.PLAYING, default: true }, + { label: "Listening", value: ActivityType.LISTENING } + ], + }, + refreshInterval: { + type: OptionType.SLIDER, + description: "The interval between activity refreshes (seconds)", + markers: [1, 2, 2.5, 3, 5, 10, 15], + default: 5, + restartNeeded: true, + }, + enableTimestamps: { + type: OptionType.BOOLEAN, + description: "Whether or not to enable timestamps", + default: true, + }, + enableButtons: { + type: OptionType.BOOLEAN, + description: "Whether or not to enable buttons", + default: true, + }, + nameString: { + type: OptionType.STRING, + description: "Activity name format string", + default: "Apple Music" + }, + detailsString: { + type: OptionType.STRING, + description: "Activity details format string", + default: "{name}" + }, + stateString: { + type: OptionType.STRING, + description: "Activity state format string", + default: "{artist}" + }, + largeImageType: { + type: OptionType.SELECT, + description: "Activity assets large image type", + options: [ + { label: "Album artwork", value: AssetImageType.Album, default: true }, + { label: "Artist artwork", value: AssetImageType.Artist } + ], + }, + largeTextString: { + type: OptionType.STRING, + description: "Activity assets large text format string", + default: "{album}" + }, + smallImageType: { + type: OptionType.SELECT, + description: "Activity assets small image type", + options: [ + { label: "Album artwork", value: AssetImageType.Album }, + { label: "Artist artwork", value: AssetImageType.Artist, default: true } + ], + }, + smallTextString: { + type: OptionType.STRING, + description: "Activity assets small text format string", + default: "{artist}" + }, +}); + +function customFormat(formatStr: string, data: TrackData) { + return formatStr + .replaceAll("{name}", data.name) + .replaceAll("{album}", data.album) + .replaceAll("{artist}", data.artist); +} + +function getImageAsset(type: AssetImageType, data: TrackData) { + const source = type === AssetImageType.Album + ? data.albumArtwork + : data.artistArtwork; + + if (!source) return undefined; + + return ApplicationAssetUtils.fetchAssetIds(applicationId, [source]).then(ids => ids[0]); +} + +export default definePlugin({ + name: "AppleMusicRichPresence", + description: "Discord rich presence for your Apple Music!", + authors: [Devs.RyanCaoDev], + hidden: !navigator.platform.startsWith("Mac"), + + settingsAboutComponent() { + return <> + + For the customizable activity format strings, you can use several special strings to include track data in activities!{" "} + {"{name}"} is replaced with the track name; {"{artist}"} is replaced with the artist(s)' name(s); and {"{album}"} is replaced with the album name. + + ; + }, + + settings, + + start() { + this.updatePresence(); + this.updateInterval = setInterval(() => { this.updatePresence(); }, settings.store.refreshInterval * 1000); + }, + + stop() { + clearInterval(this.updateInterval); + FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", activity: null }); + }, + + updatePresence() { + this.getActivity().then(activity => { setActivity(activity); }); + }, + + async getActivity(): Promise { + const trackData = await Native.fetchTrackData(); + if (!trackData) return null; + + const [largeImageAsset, smallImageAsset] = await Promise.all([ + getImageAsset(settings.store.largeImageType, trackData), + getImageAsset(settings.store.smallImageType, trackData) + ]); + + const assets: ActivityAssets = { + large_image: largeImageAsset, + large_text: customFormat(settings.store.largeTextString, trackData), + small_image: smallImageAsset, + small_text: customFormat(settings.store.smallTextString, trackData), + }; + + const buttons: ActivityButton[] = []; + + if (settings.store.enableButtons) { + if (trackData.appleMusicLink) + buttons.push({ + label: "Listen on Apple Music", + url: trackData.appleMusicLink, + }); + + if (trackData.songLink) + buttons.push({ + label: "View on SongLink", + url: trackData.songLink, + }); + } + + return { + application_id: applicationId, + + name: customFormat(settings.store.nameString, trackData), + details: customFormat(settings.store.detailsString, trackData), + state: customFormat(settings.store.stateString, trackData), + + timestamps: (settings.store.enableTimestamps ? { + start: Date.now() - (trackData.playerPosition * 1000), + end: Date.now() - (trackData.playerPosition * 1000) + (trackData.duration * 1000), + } : undefined), + + assets, + + buttons: buttons.length ? buttons.map(v => v.label) : undefined, + metadata: { button_urls: buttons.map(v => v.url) || undefined, }, + + type: settings.store.activityType, + flags: ActivityFlag.INSTANCE, + }; + } +}); diff --git a/src/plugins/appleMusic.desktop/native.ts b/src/plugins/appleMusic.desktop/native.ts new file mode 100644 index 000000000..2eb2a0757 --- /dev/null +++ b/src/plugins/appleMusic.desktop/native.ts @@ -0,0 +1,120 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { execFile } from "child_process"; +import { promisify } from "util"; + +import type { TrackData } from "."; + +const exec = promisify(execFile); + +// function exec(file: string, args: string[] = []) { +// return new Promise<{ code: number | null, stdout: string | null, stderr: string | null; }>((resolve, reject) => { +// const process = spawn(file, args, { stdio: [null, "pipe", "pipe"] }); + +// let stdout: string | null = null; +// process.stdout.on("data", (chunk: string) => { stdout ??= ""; stdout += chunk; }); +// let stderr: string | null = null; +// process.stderr.on("data", (chunk: string) => { stdout ??= ""; stderr += chunk; }); + +// process.on("exit", code => { resolve({ code, stdout, stderr }); }); +// process.on("error", err => reject(err)); +// }); +// } + +async function applescript(cmds: string[]) { + const { stdout } = await exec("osascript", cmds.map(c => ["-e", c]).flat()); + return stdout; +} + +function makeSearchUrl(type: string, query: string) { + const url = new URL("https://tools.applemediaservices.com/api/apple-media/music/US/search.json"); + url.searchParams.set("types", type); + url.searchParams.set("limit", "1"); + url.searchParams.set("term", query); + return url; +} + +const requestOptions: RequestInit = { + headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" }, +}; + +interface RemoteData { + appleMusicLink?: string, + songLink?: string, + albumArtwork?: string, + artistArtwork?: string; +} + +let cachedRemoteData: { id: string, data: RemoteData; } | { id: string, failures: number; } | null = null; + +async function fetchRemoteData({ id, name, artist, album }: { id: string, name: string, artist: string, album: string; }) { + if (id === cachedRemoteData?.id) { + if ("data" in cachedRemoteData) return cachedRemoteData.data; + if ("failures" in cachedRemoteData && cachedRemoteData.failures >= 5) return null; + } + + try { + const [songData, artistData] = await Promise.all([ + fetch(makeSearchUrl("songs", artist + " " + album + " " + name), requestOptions).then(r => r.json()), + fetch(makeSearchUrl("artists", artist.split(/ *[,&] */)[0]), requestOptions).then(r => r.json()) + ]); + + const appleMusicLink = songData?.songs?.data[0]?.attributes.url; + const songLink = songData?.songs?.data[0]?.id ? `https://song.link/i/${songData?.songs?.data[0]?.id}` : undefined; + + const albumArtwork = songData?.songs?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512"); + const artistArtwork = artistData?.artists?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512"); + + cachedRemoteData = { + id, + data: { appleMusicLink, songLink, albumArtwork, artistArtwork } + }; + return cachedRemoteData.data; + } catch (e) { + console.error("[AppleMusicRichPresence] Failed to fetch remote data:", e); + cachedRemoteData = { + id, + failures: (id === cachedRemoteData?.id && "failures" in cachedRemoteData ? cachedRemoteData.failures : 0) + 1 + }; + return null; + } +} + +export async function fetchTrackData(): Promise { + try { + await exec("pgrep", ["^Music$"]); + } catch (error) { + return null; + } + + const playerState = await applescript(['tell application "Music"', "get player state", "end tell"]) + .then(out => out.trim()); + if (playerState !== "playing") return null; + + const playerPosition = await applescript(['tell application "Music"', "get player position", "end tell"]) + .then(text => Number.parseFloat(text.trim())); + + const stdout = await applescript([ + 'set output to ""', + 'tell application "Music"', + "set t_id to database id of current track", + "set t_name to name of current track", + "set t_album to album of current track", + "set t_artist to artist of current track", + "set t_duration to duration of current track", + 'set output to "" & t_id & "\\n" & t_name & "\\n" & t_album & "\\n" & t_artist & "\\n" & t_duration', + "end tell", + "return output" + ]); + + const [id, name, album, artist, durationStr] = stdout.split("\n").filter(k => !!k); + const duration = Number.parseFloat(durationStr); + + const remoteData = await fetchRemoteData({ id, name, artist, album }); + + return { name, album, artist, playerPosition, duration, ...remoteData }; +} diff --git a/src/utils/types.ts b/src/utils/types.ts index fe19a1093..2fa4a826e 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -85,6 +85,10 @@ export interface PluginDef { * Whether this plugin is required and forcefully enabled */ required?: boolean; + /** + * Whether this plugin should be hidden from the user + */ + hidden?: boolean; /** * Whether this plugin should be enabled by default, but can be disabled */ From e5e8b9ba0143608752577dc277ab5d340c99382a Mon Sep 17 00:00:00 2001 From: vishnyanetchereshnya <151846235+vishnyanetchereshnya@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:40:02 +0300 Subject: [PATCH 07/25] new plugin CopyEmojiMarkdown ~ more easily copy emoji formatting (#2266) Co-authored-by: Happy enderman <66224387+happyendermangit@users.noreply.github.com> Co-authored-by: vee --- src/plugins/copyEmojiMarkdown/README.md | 5 ++ src/plugins/copyEmojiMarkdown/index.tsx | 75 +++++++++++++++++++++++++ src/utils/constants.ts | 8 +++ 3 files changed, 88 insertions(+) create mode 100644 src/plugins/copyEmojiMarkdown/README.md create mode 100644 src/plugins/copyEmojiMarkdown/index.tsx diff --git a/src/plugins/copyEmojiMarkdown/README.md b/src/plugins/copyEmojiMarkdown/README.md new file mode 100644 index 000000000..9e62e6635 --- /dev/null +++ b/src/plugins/copyEmojiMarkdown/README.md @@ -0,0 +1,5 @@ +# CopyEmojiMarkdown + +Allows you to copy emojis as formatted string. Custom emojis will be copied as `<:trolley:1024751352028602449>`, default emojis as `🛒` + +![](https://github.com/Vendicated/Vencord/assets/45497981/417f345a-7031-4fe7-8e42-e238870cd547) diff --git a/src/plugins/copyEmojiMarkdown/index.tsx b/src/plugins/copyEmojiMarkdown/index.tsx new file mode 100644 index 000000000..a9c018a91 --- /dev/null +++ b/src/plugins/copyEmojiMarkdown/index.tsx @@ -0,0 +1,75 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import { copyWithToast } from "@utils/misc"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { Menu } from "@webpack/common"; + +const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate"); + +interface Emoji { + type: string; + id: string; + name: string; +} + +interface Target { + dataset: Emoji; + firstChild: HTMLImageElement; +} + +function getEmojiMarkdown(target: Target, copyUnicode: boolean): string { + const { id: emojiId, name: emojiName } = target.dataset; + + if (!emojiId) { + return copyUnicode + ? convertNameToSurrogate(emojiName) + : `:${emojiName}:`; + } + + const extension = target?.firstChild.src.match( + /https:\/\/cdn\.discordapp\.com\/emojis\/\d+\.(\w+)/ + )?.[1]; + + return `<${extension === "gif" ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`; +} + +const settings = definePluginSettings({ + copyUnicode: { + type: OptionType.BOOLEAN, + description: "Copy the raw unicode character instead of :name: for default emojis (👽)", + default: true, + }, +}); + +export default definePlugin({ + name: "CopyEmojiMarkdown", + description: "Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)", + authors: [Devs.HappyEnderman, Devs.Vishnya], + settings, + + contextMenus: { + "expression-picker"(children, { target }: { target: Target }) { + if (target.dataset.type !== "emoji") return; + + children.push( + { + copyWithToast( + getEmojiMarkdown(target, settings.store.copyUnicode), + "Success! Copied emoji markdown." + ); + }} + /> + ); + }, + }, +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 4e3422526..7f172395b 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -442,6 +442,14 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Elvyra", id: 708275751816003615n, }, + HappyEnderman: { + name: "Happy enderman", + id: 1083437693347827764n + }, + Vishnya: { + name: "Vishnya", + id: 282541644484575233n + }, Inbestigator: { name: "Inbestigator", id: 761777382041714690n From b88be8014e3fd2e76df7ac6a2be63ce821d2071a Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 6 Jun 2024 02:55:18 +0200 Subject: [PATCH 08/25] experiments: change toolbar help button -> dev menu --- src/plugins/experiments/hideBugReport.css | 3 +++ src/plugins/experiments/index.tsx | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/plugins/experiments/hideBugReport.css diff --git a/src/plugins/experiments/hideBugReport.css b/src/plugins/experiments/hideBugReport.css new file mode 100644 index 000000000..ff78555d7 --- /dev/null +++ b/src/plugins/experiments/hideBugReport.css @@ -0,0 +1,3 @@ +#staff-help-popout-staff-help-bug-reporter { + display: none; +} diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx index 626e06a99..cf4dbf249 100644 --- a/src/plugins/experiments/index.tsx +++ b/src/plugins/experiments/index.tsx @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import { disableStyle, enableStyle } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { ErrorCard } from "@components/ErrorCard"; import { Devs } from "@utils/constants"; @@ -24,6 +25,8 @@ import definePlugin from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { Forms, React } from "@webpack/common"; +import hideBugReport from "./hideBugReport.css?managed"; + const KbdStyles = findByPropsLazy("key", "removeBuildOverride"); export default definePlugin({ @@ -58,9 +61,20 @@ export default definePlugin({ match: 'title:"Experiments",children:[', replace: "$&$self.WarningCard()," } + }, + // change top right chat toolbar button from the help one to the dev one + { + find: "toolbar:function", + replacement: { + match: /\i\.isStaff\(\)/, + replace: "true" + } } ], + start: () => enableStyle(hideBugReport), + stop: () => disableStyle(hideBugReport), + settingsAboutComponent: () => { const isMacOS = navigator.platform.includes("Mac"); const modKey = isMacOS ? "cmd" : "ctrl"; From 0dac08c17df154b6e2f6d3d79ab82fd79aaada1f Mon Sep 17 00:00:00 2001 From: nyx <60797172+verticalsync@users.noreply.github.com> Date: Thu, 6 Jun 2024 04:39:18 +0300 Subject: [PATCH 09/25] PlatformIndicators: fix embedded (console) devices (#2546) Co-authored-by: Vendicated Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> --- src/plugins/platformIndicators/index.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/platformIndicators/index.tsx b/src/plugins/platformIndicators/index.tsx index 9fae9adfa..ea2ae125c 100644 --- a/src/plugins/platformIndicators/index.tsx +++ b/src/plugins/platformIndicators/index.tsx @@ -51,14 +51,17 @@ const Icons = { desktop: Icon("M4 2.5c-1.103 0-2 .897-2 2v11c0 1.104.897 2 2 2h7v2H7v2h10v-2h-4v-2h7c1.103 0 2-.896 2-2v-11c0-1.103-.897-2-2-2H4Zm16 2v9H4v-9h16Z"), web: Icon("M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93Zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39Z"), mobile: Icon("M 187 0 L 813 0 C 916.277 0 1000 83.723 1000 187 L 1000 1313 C 1000 1416.277 916.277 1500 813 1500 L 187 1500 C 83.723 1500 0 1416.277 0 1313 L 0 187 C 0 83.723 83.723 0 187 0 Z M 125 1000 L 875 1000 L 875 250 L 125 250 Z M 500 1125 C 430.964 1125 375 1180.964 375 1250 C 375 1319.036 430.964 1375 500 1375 C 569.036 1375 625 1319.036 625 1250 C 625 1180.964 569.036 1125 500 1125 Z", { viewBox: "0 0 1000 1500", height: 17, width: 17 }), - console: Icon("M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z", { viewBox: "0 0 50 50" }), + embedded: Icon("M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z", { viewBox: "0 0 50 50" }), }; type Platform = keyof typeof Icons; const StatusUtils = findByPropsLazy("useStatusFillColor", "StatusTypes"); const PlatformIcon = ({ platform, status, small }: { platform: Platform, status: string; small: boolean; }) => { - const tooltip = platform[0].toUpperCase() + platform.slice(1); + const tooltip = platform === "embedded" + ? "Console" + : platform[0].toUpperCase() + platform.slice(1); + const Icon = Icons[platform] ?? Icons.desktop; return ; From 67b709a7962afd370a2708e4e3252a58841a28c5 Mon Sep 17 00:00:00 2001 From: nekohaxx <151578517+nekohaxx@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:01:44 +0800 Subject: [PATCH 10/25] new plugin NoOnboardingDelay: skip long onboarding animations (#2533) Co-authored-by: Vendicated --- src/plugins/noOnboardingDelay/index.ts | 35 ++++++++++++++++++++++++++ src/utils/constants.ts | 4 +++ 2 files changed, 39 insertions(+) create mode 100644 src/plugins/noOnboardingDelay/index.ts diff --git a/src/plugins/noOnboardingDelay/index.ts b/src/plugins/noOnboardingDelay/index.ts new file mode 100644 index 000000000..6211e97c2 --- /dev/null +++ b/src/plugins/noOnboardingDelay/index.ts @@ -0,0 +1,35 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; + +export default definePlugin({ + name: "NoOnboardingDelay", + description: "Skips the slow and annoying onboarding delay", + authors: [Devs.nekohaxx], + patches: [ + { + find: "Messages.ONBOARDING_COVER_WELCOME_SUBTITLE", + replacement: { + match: "3e3", + replace: "0" + }, + }, + ], +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 7f172395b..ff754d5c2 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -526,6 +526,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "verticalsync", id: 328165170536775680n }, + nekohaxx: { + name: "nekohaxx", + id: 1176270221628153886n + } } satisfies Record); // iife so #__PURE__ works correctly From 9cafe8084cf4850db777c6389dd403a535751da5 Mon Sep 17 00:00:00 2001 From: notsu Date: Thu, 6 Jun 2024 07:17:47 +0500 Subject: [PATCH 11/25] SpotifyControls: fix no artists on local files (#2543) Co-authored-by: vee --- src/plugins/spotifyControls/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/spotifyControls/index.tsx b/src/plugins/spotifyControls/index.tsx index 06595892f..f7972aa36 100644 --- a/src/plugins/spotifyControls/index.tsx +++ b/src/plugins/spotifyControls/index.tsx @@ -77,6 +77,13 @@ export default definePlugin({ match: /repeat:"off"!==(.{1,3}),/, replace: "actual_repeat:$1,$&" } + }, + { + find: "artists.filter", + replacement: { + match: /\(0,(\i)\.isNotNullish\)\((\i)\.id\)&&/, + replace: "" + } } ], From 5976d52cbc24785a02588833decc859c93294ade Mon Sep 17 00:00:00 2001 From: AutumnVN Date: Thu, 6 Jun 2024 10:05:53 +0700 Subject: [PATCH 12/25] viewIcons: support new simplified profile (#2535) Co-authored-by: Sqaaakoi --- src/plugins/viewIcons/index.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugins/viewIcons/index.tsx b/src/plugins/viewIcons/index.tsx index 09254d511..a94689689 100644 --- a/src/plugins/viewIcons/index.tsx +++ b/src/plugins/viewIcons/index.tsx @@ -184,16 +184,16 @@ export default definePlugin({ patches: [ // Profiles Modal pfp - { - find: "User Profile Modal - Context Menu", + ...["User Profile Modal - Context Menu", ".UserProfileTypes.FULL_SIZE,hasProfileEffect:"].map(find => ({ + find, replacement: { match: /\{src:(\i)(?=,avatarDecoration)/, replace: "{src:$1,onClick:()=>$self.openImage($1)" } - }, + })), // Banners - { - find: ".NITRO_BANNER,", + ...[".NITRO_BANNER,", /overrideBannerSrc:\i,overrideBannerWidth:/].map(find => ({ + find, replacement: { // style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl, match: /style:\{(?=backgroundImage:(null!=\i)\?"url\("\.concat\((\i),)/, @@ -201,7 +201,7 @@ export default definePlugin({ // onClick: () => shouldShowBanner && ev.target.style.backgroundImage && openImage(bannerUrl), style: { cursor: shouldShowBanner ? "pointer" : void 0, 'onClick:ev=>$1&&ev.target.style.backgroundImage&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,' } - }, + })), // User DMs "User Profile" popup in the right { find: ".avatarPositionPanel", @@ -210,6 +210,14 @@ export default definePlugin({ replace: "$1style:($2)?{cursor:\"pointer\"}:{},onClick:$2?()=>{$self.openImage($3)}" } }, + { + find: ".canUsePremiumProfileCustomization,{avatarSrc:", + replacement: { + match: /children:\(0,\i\.jsx\)\(\i,{src:(\i)/, + replace: "style:{cursor:\"pointer\"},onClick:()=>{$self.openImage($1)},$&" + + } + }, // Group DMs top small & large icon { find: /\.recipients\.length>=2(?! Date: Thu, 6 Jun 2024 10:07:20 +0700 Subject: [PATCH 13/25] USRBG: fix in simplified profile (#2549) --- src/plugins/usrbg/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/usrbg/index.tsx b/src/plugins/usrbg/index.tsx index 1221cb9c5..b8e9f14b3 100644 --- a/src/plugins/usrbg/index.tsx +++ b/src/plugins/usrbg/index.tsx @@ -74,15 +74,15 @@ export default definePlugin({ ] }, { - find: /overrideBannerSrc:\i,profileType:/, + find: /overrideBannerSrc:\i,overrideBannerWidth:/, replacement: [ { match: /(\i)\.premiumType/, replace: "$self.premiumHook($1)||$&" }, { - match: /(?<=function \i\((\i)\)\{)(?=var.{30,50},overrideBannerSrc:)/, - replace: "$1.overrideBannerSrc=$self.useBannerHook($1);" + match: /function \i\((\i)\)\{/, + replace: "$&$1.overrideBannerSrc=$self.useBannerHook($1);" } ] }, From 43b6933fe69fbf30f542c7da41d0e812150f8447 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 6 Jun 2024 00:47:57 -0300 Subject: [PATCH 14/25] Reporter: Include page errors; load wasm chunks --- scripts/generateReport.ts | 9 ++++++++- src/debug/loadLazyChunks.ts | 14 ++++++++------ src/plugins/appleMusic.desktop/index.tsx | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index cf4210779..2a802da8c 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -286,7 +286,14 @@ page.on("console", async e => { }); page.on("error", e => console.error("[Error]", e.message)); -page.on("pageerror", e => console.error("[Page Error]", e.message)); +page.on("pageerror", e => { + if (!e.message.startsWith("Object") && !e.message.includes("Cannot find module")) { + console.error("[Page Error]", e.message); + report.otherErrors.push(e.message); + } else { + report.ignoredErrors.push(e.message); + } +}); async function reporterRuntime(token: string) { Vencord.Webpack.waitFor( diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index d8f84335c..0aeae732b 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -47,11 +47,11 @@ export async function loadLazyChunks() { for (const id of chunkIds) { if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; - const isWasm = await fetch(wreq.p + wreq.u(id)) + const isWorkerAsset = await fetch(wreq.p + wreq.u(id)) .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + .then(t => t.includes("importScripts(")); - if (isWasm && IS_WEB) { + if (isWorkerAsset) { invalidChunks.add(id); invalidChunkGroup = true; continue; @@ -149,13 +149,15 @@ export async function loadLazyChunks() { }); await Promise.all(chunksLeft.map(async id => { - const isWasm = await fetch(wreq.p + wreq.u(id)) + const isWorkerAsset = await fetch(wreq.p + wreq.u(id)) .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + .then(t => t.includes("importScripts(")); // Loads and requires a chunk - if (!isWasm) { + if (!isWorkerAsset) { await wreq.e(id as any); + // Technically, the id of the chunk does not match the entry point + // But, still try it because we have no way to get the actual entry point if (wreq.m[id]) wreq(id as any); } })); diff --git a/src/plugins/appleMusic.desktop/index.tsx b/src/plugins/appleMusic.desktop/index.tsx index 16591028d..ef3ee3efc 100644 --- a/src/plugins/appleMusic.desktop/index.tsx +++ b/src/plugins/appleMusic.desktop/index.tsx @@ -6,7 +6,7 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; -import definePlugin, { OptionType, PluginNative } from "@utils/types"; +import definePlugin, { OptionType, PluginNative, ReporterTestable } from "@utils/types"; import { ApplicationAssetUtils, FluxDispatcher, Forms } from "@webpack/common"; const Native = VencordNative.pluginHelpers.AppleMusic as PluginNative; @@ -171,6 +171,7 @@ export default definePlugin({ description: "Discord rich presence for your Apple Music!", authors: [Devs.RyanCaoDev], hidden: !navigator.platform.startsWith("Mac"), + reporterTestable: ReporterTestable.None, settingsAboutComponent() { return <> From c54650b29a4af243aa7f79d01340235bedc3172b Mon Sep 17 00:00:00 2001 From: NuclideK <88620225+NuclideK@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:24:49 +0300 Subject: [PATCH 15/25] customRPC: fix typos in settings descriptions (#2559) --- src/plugins/customRPC/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/customRPC/index.tsx b/src/plugins/customRPC/index.tsx index f1b2fbf53..ed354cba4 100644 --- a/src/plugins/customRPC/index.tsx +++ b/src/plugins/customRPC/index.tsx @@ -178,7 +178,7 @@ const settings = definePluginSettings({ }, startTime: { type: OptionType.NUMBER, - description: "Start timestamp in milisecond (only for custom timestamp mode)", + description: "Start timestamp in milliseconds (only for custom timestamp mode)", onChange: onChange, disabled: isTimestampDisabled, isValid: (value: number) => { @@ -188,7 +188,7 @@ const settings = definePluginSettings({ }, endTime: { type: OptionType.NUMBER, - description: "End timestamp in milisecond (only for custom timestamp mode)", + description: "End timestamp in milliseconds (only for custom timestamp mode)", onChange: onChange, disabled: isTimestampDisabled, isValid: (value: number) => { From 40db2f507808d200c8a4037d047ffc4db942a11c Mon Sep 17 00:00:00 2001 From: Lumap Date: Fri, 7 Jun 2024 23:04:40 +0200 Subject: [PATCH 16/25] AppleMusicRichPresence: add option to disable large/small image (#2562) --- src/plugins/appleMusic.desktop/index.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/plugins/appleMusic.desktop/index.tsx b/src/plugins/appleMusic.desktop/index.tsx index ef3ee3efc..0d81204e9 100644 --- a/src/plugins/appleMusic.desktop/index.tsx +++ b/src/plugins/appleMusic.desktop/index.tsx @@ -68,6 +68,7 @@ export interface TrackData { const enum AssetImageType { Album = "Album", Artist = "Artist", + Disabled = "Disabled" } const applicationId = "1239490006054207550"; @@ -126,7 +127,8 @@ const settings = definePluginSettings({ description: "Activity assets large image type", options: [ { label: "Album artwork", value: AssetImageType.Album, default: true }, - { label: "Artist artwork", value: AssetImageType.Artist } + { label: "Artist artwork", value: AssetImageType.Artist }, + { label: "Disabled", value: AssetImageType.Disabled } ], }, largeTextString: { @@ -139,7 +141,8 @@ const settings = definePluginSettings({ description: "Activity assets small image type", options: [ { label: "Album artwork", value: AssetImageType.Album }, - { label: "Artist artwork", value: AssetImageType.Artist, default: true } + { label: "Artist artwork", value: AssetImageType.Artist, default: true }, + { label: "Disabled", value: AssetImageType.Disabled } ], }, smallTextString: { @@ -207,12 +210,17 @@ export default definePlugin({ getImageAsset(settings.store.smallImageType, trackData) ]); - const assets: ActivityAssets = { - large_image: largeImageAsset, - large_text: customFormat(settings.store.largeTextString, trackData), - small_image: smallImageAsset, - small_text: customFormat(settings.store.smallTextString, trackData), - }; + const assets: ActivityAssets = {}; + + if (settings.store.largeImageType !== AssetImageType.Disabled) { + assets.large_image = largeImageAsset; + assets.large_text = customFormat(settings.store.largeTextString, trackData); + } + + if (settings.store.smallImageType !== AssetImageType.Disabled) { + assets.small_image = smallImageAsset; + assets.small_text = customFormat(settings.store.smallTextString, trackData); + } const buttons: ActivityButton[] = []; From 1bc9a800a66e3cef6ef8d8cd54c4db6db7a73007 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EdVraz@users.noreply.github.com> Date: Fri, 7 Jun 2024 23:05:14 +0200 Subject: [PATCH 17/25] fix moreUserTags (#2563) --- src/plugins/moreUserTags/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index 9c848df6d..9d2790d0e 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -200,7 +200,7 @@ export default definePlugin({ } }, { - find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,", + find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP_OFFICIAL,", replacement: [ // make the tag show the right text { From 29c65948b43df64c9d8f527bb0967ad05685221c Mon Sep 17 00:00:00 2001 From: Nickyux <30734036+nmsturcke@users.noreply.github.com> Date: Fri, 7 Jun 2024 23:28:17 +0200 Subject: [PATCH 18/25] MessageLogger: add context menu option to clear channel history (#2008) Co-authored-by: vee --- src/api/MessageUpdater.ts | 2 +- src/plugins/messageLogger/index.tsx | 121 ++++++++++++++++------------ 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/api/MessageUpdater.ts b/src/api/MessageUpdater.ts index 5cac80528..284a20886 100644 --- a/src/api/MessageUpdater.ts +++ b/src/api/MessageUpdater.ts @@ -14,7 +14,7 @@ import { Message } from "discord-types/general"; * @param messageId The message id * @param fields The fields of the message to change. Leave empty if you just want to re-render */ -export function updateMessage(channelId: string, messageId: string, fields?: Partial) { +export function updateMessage(channelId: string, messageId: string, fields?: Partial>) { const channelMessageCache = MessageCache.getOrCreate(channelId); if (!channelMessageCache.has(messageId)) return; diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index 892c819b7..daafeb2dc 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -18,7 +18,8 @@ import "./messageLogger.css"; -import { NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { updateMessage } from "@api/MessageUpdater"; import { Settings } from "@api/Settings"; import { disableStyle, enableStyle } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; @@ -26,11 +27,17 @@ import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; -import { ChannelStore, FluxDispatcher, i18n, Menu, Parser, Timestamp, UserStore } from "@webpack/common"; +import { ChannelStore, FluxDispatcher, i18n, Menu, MessageStore, Parser, Timestamp, UserStore, useStateFromStores } from "@webpack/common"; +import { Message } from "discord-types/general"; import overlayStyle from "./deleteStyleOverlay.css?managed"; import textStyle from "./deleteStyleText.css?managed"; +interface MLMessage extends Message { + deleted?: boolean; + editHistory?: { timestamp: Date; content: string; }[]; +} + const styles = findByPropsLazy("edited", "communicationDisabled", "isSystemMessage"); function addDeleteStyle() { @@ -89,35 +96,77 @@ const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) = )); }; +const patchChannelContextMenu: NavContextMenuPatchCallback = (children, { channel }) => { + const messages = MessageStore.getMessages(channel?.id) as MLMessage[]; + if (!messages?.some(msg => msg.deleted || msg.editHistory?.length)) return; + + const group = findGroupChildrenByChildId("mark-channel-read", children) ?? children; + group.push( + { + messages.forEach(msg => { + if (msg.deleted) + FluxDispatcher.dispatch({ + type: "MESSAGE_DELETE", + channelId: channel.id, + id: msg.id, + mlDeleted: true + }); + else + updateMessage(channel.id, msg.id, { + editHistory: [] + }); + }); + }} + /> + ); +}; + export default definePlugin({ name: "MessageLogger", description: "Temporarily logs deleted and edited messages.", - authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN], + authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN, Devs.Nickyux], + dependencies: ["MessageUpdaterAPI"], contextMenus: { - "message": patchMessageContextMenu + "message": patchMessageContextMenu, + "channel-context": patchChannelContextMenu, + "user-context": patchChannelContextMenu, + "gdm-context": patchChannelContextMenu }, start() { addDeleteStyle(); }, - renderEdit(edit: { timestamp: any, content: string; }) { - return ( - -
- {Parser.parse(edit.content)} - - {" "}({i18n.Messages.MESSAGE_EDITED}) - -
-
+ renderEdits: ErrorBoundary.wrap(({ message: { id: messageId, channel_id: channelId } }: { message: Message; }) => { + const message = useStateFromStores( + [MessageStore], + () => MessageStore.getMessage(channelId, messageId) as MLMessage, + null, + (oldMsg, newMsg) => oldMsg.editHistory === newMsg.editHistory ); - }, + + return ( + <> + {message.editHistory?.map(edit => ( +
+ {Parser.parse(edit.content)} + + {" "}({i18n.Messages.MESSAGE_EDITED}) + +
+ ))} + + ); + }, { noop: true }), makeEdit(newMessage: any, oldMessage: any): any { return { @@ -222,11 +271,9 @@ export default definePlugin({ (message.channel_id === "1026515880080842772" && message.author?.id === "1017176847865352332"); }, - // Based on canary 63b8f1b4f2025213c5cf62f0966625bee3d53136 patches: [ { // MessageStore - // Module 171447 find: '"MessageStore"', replacement: [ { @@ -271,7 +318,6 @@ export default definePlugin({ { // Message domain model - // Module 451 find: "}addReaction(", replacement: [ { @@ -285,14 +331,8 @@ export default definePlugin({ { // Updated message transformer(?) - // Module 819525 find: "THREAD_STARTER_MESSAGE?null===", replacement: [ - // { - // // DEBUG: Log the params of the target function to the patch below - // match: /function N\(e,t\){/, - // replace: "function L(e,t){console.log('pre-transform', e, t);" - // }, { // Pass through editHistory & deleted & original attachments to the "edited message" transformer match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/, @@ -300,11 +340,6 @@ export default definePlugin({ "Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, attachments:$1.attachments })" }, - // { - // // DEBUG: Log the params of the target function to the patch below - // match: /function R\(e\){/, - // replace: "function R(e){console.log('after-edit-transform', arguments);" - // }, { // Construct new edited message and add editHistory & deleted (ref above) // Pass in custom data to attachment parser to mark attachments deleted as well @@ -335,7 +370,6 @@ export default definePlugin({ { // Attachment renderer - // Module 96063 find: ".removeMosaicItemHoverButton", group: true, replacement: [ @@ -352,7 +386,6 @@ export default definePlugin({ { // Base message component renderer - // Module 748241 find: "Message must not be a thread starter message", replacement: [ { @@ -365,20 +398,18 @@ export default definePlugin({ { // Message content renderer - // Module 43016 find: "Messages.MESSAGE_EDITED,\")\"", replacement: [ { // Render editHistory in the deepest div for message content match: /(\)\("div",\{id:.+?children:\[)/, - replace: "$1 (arguments[0].message.editHistory?.length > 0 ? arguments[0].message.editHistory.map(edit => $self.renderEdit(edit)) : null), " + replace: "$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0]))," } ] }, { // ReferencedMessageStore - // Module 778667 find: '"ReferencedMessageStore"', replacement: [ { @@ -394,7 +425,6 @@ export default definePlugin({ { // Message context base menu - // Module 600300 find: "useMessageMenu:", replacement: [ { @@ -404,18 +434,5 @@ export default definePlugin({ } ] } - - // { - // // MessageStore caching internals - // // Module 819525 - // find: "e.getOrCreate=function(t)", - // replacement: [ - // // { - // // // DEBUG: log getOrCreate return values from MessageStore caching internals - // // match: /getOrCreate=function(.+?)return/, - // // replace: "getOrCreate=function$1console.log('getOrCreate',n);return" - // // } - // ] - // } ] }); From 5996e67c7d9d6512f734592f1e44e72897d37797 Mon Sep 17 00:00:00 2001 From: AutumnVN Date: Sat, 8 Jun 2024 04:42:12 +0700 Subject: [PATCH 19/25] fix USRBG & ViewIcons in new profiles (#2557) Co-authored-by: Vendicated --- src/plugins/usrbg/index.tsx | 40 ++++++++++++++++----------------- src/plugins/viewIcons/index.tsx | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/plugins/usrbg/index.tsx b/src/plugins/usrbg/index.tsx index b8e9f14b3..32da95af6 100644 --- a/src/plugins/usrbg/index.tsx +++ b/src/plugins/usrbg/index.tsx @@ -61,11 +61,7 @@ export default definePlugin({ replacement: [ { match: /(\i)\.premiumType/, - replace: "$self.premiumHook($1)||$&" - }, - { - match: /(?<=function \i\((\i)\)\{)(?=var.{30,50},bannerSrc:)/, - replace: "$1.bannerSrc=$self.useBannerHook($1);" + replace: "$self.patchPremiumType($1)||$&" }, { match: /\?\(0,\i\.jsx\)\(\i,{type:\i,shown/, @@ -74,17 +70,19 @@ export default definePlugin({ ] }, { - find: /overrideBannerSrc:\i,overrideBannerWidth:/, - replacement: [ - { - match: /(\i)\.premiumType/, - replace: "$self.premiumHook($1)||$&" - }, - { - match: /function \i\((\i)\)\{/, - replace: "$&$1.overrideBannerSrc=$self.useBannerHook($1);" - } - ] + find: "=!1,canUsePremiumCustomization:", + replacement: { + match: /(\i)\.premiumType/, + replace: "$self.patchPremiumType($1)||$&" + } + }, + { + find: "BannerLoadingStatus:function", + replacement: { + match: /(?<=void 0:)\i.getPreviewBanner\(\i,\i,\i\)/, + replace: "$self.patchBannerUrl(arguments[0])||$&" + + } }, { find: "\"data-selenium-video-tile\":", @@ -92,7 +90,7 @@ export default definePlugin({ replacement: [ { match: /(?<=function\((\i),\i\)\{)(?=let.{20,40},style:)/, - replace: "$1.style=$self.voiceBackgroundHook($1);" + replace: "$1.style=$self.getVoiceBackgroundStyles($1);" } ] } @@ -106,7 +104,7 @@ export default definePlugin({ ); }, - voiceBackgroundHook({ className, participantUserId }: any) { + getVoiceBackgroundStyles({ className, participantUserId }: any) { if (className.includes("tile_")) { if (this.userHasBackground(participantUserId)) { return { @@ -119,12 +117,12 @@ export default definePlugin({ } }, - useBannerHook({ displayProfile, user }: any) { + patchBannerUrl({ displayProfile }: any) { if (displayProfile?.banner && settings.store.nitroFirst) return; - if (this.userHasBackground(user.id)) return this.getImageUrl(user.id); + if (this.userHasBackground(displayProfile?.userId)) return this.getImageUrl(displayProfile?.userId); }, - premiumHook({ userId }: any) { + patchPremiumType({ userId }: any) { if (this.userHasBackground(userId)) return 2; }, diff --git a/src/plugins/viewIcons/index.tsx b/src/plugins/viewIcons/index.tsx index a94689689..9d1745116 100644 --- a/src/plugins/viewIcons/index.tsx +++ b/src/plugins/viewIcons/index.tsx @@ -192,7 +192,7 @@ export default definePlugin({ } })), // Banners - ...[".NITRO_BANNER,", /overrideBannerSrc:\i,overrideBannerWidth:/].map(find => ({ + ...[".NITRO_BANNER,", "=!1,canUsePremiumCustomization:"].map(find => ({ find, replacement: { // style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl, From 239da032ecf3136da5f9eade7ecb8321b971ef93 Mon Sep 17 00:00:00 2001 From: vee Date: Sat, 8 Jun 2024 00:48:17 +0200 Subject: [PATCH 20/25] README: add shiggy background on github --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a43c9f834..e67db93a2 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ The cutest Discord client mod | ![image](https://github.com/Vendicated/Vencord/assets/45497981/706722b1-32de-4d99-bee9-93993b504334) | -|:--:| -| A screenshot of vencord showcasing the [vencord-theme](https://github.com/synqat/vencord-theme) | +| :--------------------------------------------------------------------------------------------------: | +| A screenshot of vencord showcasing the [vencord-theme](https://github.com/synqat/vencord-theme) | ## Features @@ -32,9 +32,9 @@ https://discord.gg/D9uwnFnqmd ## Sponsors -| **Thanks a lot to all Vencord [sponsors](https://github.com/sponsors/Vendicated)!!** | -|:--:| -| [![](https://meow.vendicated.dev/sponsors.png)](https://github.com/sponsors/Vendicated) | +| **Thanks a lot to all Vencord [sponsors](https://github.com/sponsors/Vendicated)!!** | +| :------------------------------------------------------------------------------------------: | +| [![](https://meow.vendicated.dev/sponsors.png)](https://github.com/sponsors/Vendicated) | | *generated using [github-sponsor-graph](https://github.com/Vendicated/github-sponsor-graph)* | @@ -65,3 +65,8 @@ Regardless, if your account is very important to you and it getting disabled wou Additionally, make sure not to post screenshots with Vencord in a server where you might get banned for it + +```math +\ce{$\unicode[goombafont; color:red; z-index: -10; position: fixed; top: 0; left: 0; height: 100%; object-fit: cover; width: 100%; opacity: 1; background: url('https://github.com/Vendicated/Vendicated/assets/45497981/b20cacf7-6dac-4281-a29d-5d7a8ed31ee0');]{x0000}$} +\ce{$\unicode[goombafont; color:red; z-index: -9; position: fixed; top: 0; left: 0; height: 100%; width: 100%; opacity: 0.9; background: var(--bgColor-default);]{x0000}$} +``` From 2c5079b49fb3731acaa73ada69ec282a1eeb4428 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 04:15:29 +0200 Subject: [PATCH 21/25] MessageLogger: fix potential error --- src/plugins/messageLogger/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index daafeb2dc..39a059b8c 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -147,7 +147,7 @@ export default definePlugin({ [MessageStore], () => MessageStore.getMessage(channelId, messageId) as MLMessage, null, - (oldMsg, newMsg) => oldMsg.editHistory === newMsg.editHistory + (oldMsg, newMsg) => oldMsg?.editHistory === newMsg?.editHistory ); return ( From 914b211a91f21e827ffe9d333f19c1d8d31cb193 Mon Sep 17 00:00:00 2001 From: AutumnVN Date: Sat, 8 Jun 2024 09:21:01 +0700 Subject: [PATCH 22/25] betterRoleDot: fix click to copy role color in profile (#2551) Co-authored-by: vee --- src/plugins/betterRoleDot/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/betterRoleDot/index.ts b/src/plugins/betterRoleDot/index.ts index 3886de3f7..a8cadd8b0 100644 --- a/src/plugins/betterRoleDot/index.ts +++ b/src/plugins/betterRoleDot/index.ts @@ -48,6 +48,7 @@ export default definePlugin({ { find: ".ADD_ROLE_A11Y_LABEL", + all: true, predicate: () => Settings.plugins.BetterRoleDot.copyRoleColorInProfilePopout && !Settings.plugins.BetterRoleDot.bothStyles, noWarn: true, replacement: { @@ -57,6 +58,7 @@ export default definePlugin({ }, { find: ".roleVerifiedIcon", + all: true, predicate: () => Settings.plugins.BetterRoleDot.copyRoleColorInProfilePopout && !Settings.plugins.BetterRoleDot.bothStyles, noWarn: true, replacement: { From 810ff894dc9cb5ec5d62d16851b705cb0e88ef31 Mon Sep 17 00:00:00 2001 From: AutumnVN Date: Sat, 8 Jun 2024 09:21:27 +0700 Subject: [PATCH 23/25] ui(RestartCard): fix yellow button now being blue (#2550) --- src/components/PluginSettings/index.tsx | 2 +- src/components/PluginSettings/styles.css | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index 9c26a9cf1..978d2e85a 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -69,7 +69,7 @@ function ReloadRequiredCard({ required }: { required: boolean; }) { Restart now to apply new plugins and their settings - diff --git a/src/components/PluginSettings/styles.css b/src/components/PluginSettings/styles.css index 66b2a2158..d3d182e58 100644 --- a/src/components/PluginSettings/styles.css +++ b/src/components/PluginSettings/styles.css @@ -78,6 +78,7 @@ .vc-plugins-restart-card button { margin-top: 0.5em; + background: var(--info-warning-foreground) !important; } .vc-plugins-info-button svg:not(:hover, :focus) { From 65970618d89d4c7383fc88dde8380423e67cd5e5 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Jun 2024 05:26:03 +0200 Subject: [PATCH 24/25] fix badges in new profiles --- src/api/Badges.ts | 5 +- src/plugins/_api/badges/index.tsx | 58 +++++++++++++++++++++--- src/plugins/platformIndicators/index.tsx | 4 +- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/api/Badges.ts b/src/api/Badges.ts index 061bdeb8a..24c68c4ed 100644 --- a/src/api/Badges.ts +++ b/src/api/Badges.ts @@ -17,7 +17,6 @@ */ import ErrorBoundary from "@components/ErrorBoundary"; -import { User } from "discord-types/general"; import { ComponentType, HTMLProps } from "react"; import Plugins from "~plugins"; @@ -79,14 +78,14 @@ export function _getBadges(args: BadgeUserArgs) { : badges.push({ ...badge, ...args }); } } - const donorBadges = (Plugins.BadgeAPI as unknown as typeof import("../plugins/_api/badges").default).getDonorBadges(args.user.id); + const donorBadges = (Plugins.BadgeAPI as unknown as typeof import("../plugins/_api/badges").default).getDonorBadges(args.userId); if (donorBadges) badges.unshift(...donorBadges); return badges; } export interface BadgeUserArgs { - user: User; + userId: string; guildId: string; } diff --git a/src/plugins/_api/badges/index.tsx b/src/plugins/_api/badges/index.tsx index bbccf0a11..b4ee45a1d 100644 --- a/src/plugins/_api/badges/index.tsx +++ b/src/plugins/_api/badges/index.tsx @@ -18,18 +18,20 @@ import "./fixBadgeOverflow.css"; -import { BadgePosition, BadgeUserArgs, ProfileBadge } from "@api/Badges"; +import { _getBadges, BadgePosition, BadgeUserArgs, ProfileBadge } from "@api/Badges"; import DonateButton from "@components/DonateButton"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { Heart } from "@components/Heart"; import { openContributorModal } from "@components/PluginSettings/ContributorModal"; import { Devs } from "@utils/constants"; +import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; import { isPluginDev } from "@utils/misc"; import { closeModal, Modals, openModal } from "@utils/modal"; import definePlugin from "@utils/types"; -import { Forms, Toasts } from "@webpack/common"; +import { Forms, Toasts, UserStore } from "@webpack/common"; +import { User } from "discord-types/general"; const CONTRIBUTOR_BADGE = "https://vencord.dev/assets/favicon.png"; @@ -37,8 +39,8 @@ const ContributorBadge: ProfileBadge = { description: "Vencord Contributor", image: CONTRIBUTOR_BADGE, position: BadgePosition.START, - shouldShow: ({ user }) => isPluginDev(user.id), - onClick: (_, { user }) => openContributorModal(user) + shouldShow: ({ userId }) => isPluginDev(userId), + onClick: (_, { userId }) => openContributorModal(UserStore.getUser(userId)) }; let DonorBadges = {} as Record>>; @@ -66,7 +68,7 @@ export default definePlugin({ replacement: [ { match: /&&(\i)\.push\(\{id:"premium".+?\}\);/, - replace: "$&$1.unshift(...Vencord.Api.Badges._getBadges(arguments[0]));", + replace: "$&$1.unshift(...$self.getBadges(arguments[0]));", }, { // alt: "", aria-hidden: false, src: originalSrc @@ -82,7 +84,40 @@ export default definePlugin({ // conditionally override their onClick with badge.onClick if it exists { match: /href:(\i)\.link/, - replace: "...($1.onClick && { onClick: vcE => $1.onClick(vcE, arguments[0]) }),$&" + replace: "...($1.onClick && { onClick: vcE => $1.onClick(vcE, $1) }),$&" + } + ] + }, + + /* new profiles */ + { + find: ".PANEL]:14", + replacement: { + match: /(?<=\i=\(0,\i\.default\)\(\i\);)return 0===\i.length/, + replace: "$& && $self.getBadges(arguments[0]?.displayProfile).length===0" + } + }, + { + find: ".description,delay:", + replacement: [ + { + match: /...(\i)\}=\(0,\i\.useUserProfileAnalyticsContext\)\(\);/, + replace: "$&arguments[0].badges?.unshift(...$self.getBadges($1));" + }, + { + // alt: "", aria-hidden: false, src: originalSrc + match: /alt:" ","aria-hidden":!0,src:(?=.{0,20}(\i)\.icon)/, + // ...badge.props, ..., src: badge.image ?? ... + replace: "...$1.props,$& $1.image??" + }, + { + match: /(?<=text:(\i)\.description,.{0,50})children:/, + replace: "children:$1.component ? $self.renderBadgeComponent({ ...$1 }) :" + }, + // conditionally override their onClick with badge.onClick if it exists + { + match: /href:(\i)\.link/, + replace: "...($1.onClick && { onClick: vcE => $1.onClick(vcE, $1) }),$&" } ] } @@ -104,6 +139,17 @@ export default definePlugin({ await loadBadges(); }, + getBadges(props: { userId: string; user?: User; guildId: string; }) { + try { + props.userId ??= props.user?.id!; + + return _getBadges(props); + } catch (e) { + new Logger("BadgeAPI#hasBadges").error(e); + return []; + } + }, + renderBadgeComponent: ErrorBoundary.wrap((badge: ProfileBadge & BadgeUserArgs) => { const Component = badge.component!; return ; diff --git a/src/plugins/platformIndicators/index.tsx b/src/plugins/platformIndicators/index.tsx index ea2ae125c..eef74d65e 100644 --- a/src/plugins/platformIndicators/index.tsx +++ b/src/plugins/platformIndicators/index.tsx @@ -130,9 +130,9 @@ const PlatformIndicator = ({ user, wantMargin = true, wantTopMargin = false, sma }; const badge: ProfileBadge = { - component: p => , + component: p => , position: BadgePosition.START, - shouldShow: userInfo => !!Object.keys(getStatus(userInfo.user.id) ?? {}).length, + shouldShow: userInfo => !!Object.keys(getStatus(userInfo.userId) ?? {}).length, key: "indicator" }; From caf1779be3dd9d43f67cb255942264a279db018c Mon Sep 17 00:00:00 2001 From: Masterjoona <69722179+Masterjoona@users.noreply.github.com> Date: Sat, 8 Jun 2024 19:33:58 +0300 Subject: [PATCH 25/25] fix showconnections in new profiles (#2567) Co-authored-by: Vendicated --- src/plugins/showConnections/index.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/plugins/showConnections/index.tsx b/src/plugins/showConnections/index.tsx index a78e4c418..505f696d8 100644 --- a/src/plugins/showConnections/index.tsx +++ b/src/plugins/showConnections/index.tsx @@ -74,15 +74,15 @@ interface ConnectionPlatform { icon: { lightSVG: string, darkSVG: string; }; } -const profilePopoutComponent = ErrorBoundary.wrap((props: { user: User, displayProfile; }) => - +const profilePopoutComponent = ErrorBoundary.wrap((props: { user: User, displayProfile, compactSpacing; }) => + ); const profilePanelComponent = ErrorBoundary.wrap(({ id }: { id: string; }) => ); -function ConnectionsComponent({ id, theme }: { id: string, theme: string; }) { +function ConnectionsComponent({ id, theme, compactSpacing }: { id: string, theme: string, compactSpacing?: boolean; }) { const profile = UserProfileStore.getUserProfile(id); if (!profile) return null; @@ -91,8 +91,10 @@ function ConnectionsComponent({ id, theme }: { id: string, theme: string; }) { if (!connections?.length) return null; + const Container = compactSpacing ? "div" : Section; + return ( -
+ {connections.map(connection => )} -
+ ); } @@ -178,7 +180,7 @@ export default definePlugin({ find: "{isUsingGuildBio:null!==(", replacement: { match: /,theme:\i\}\)(?=,.{0,150}setNote:)/, - replace: "$&,$self.profilePopoutComponent({ user: arguments[0].user, displayProfile: arguments[0].displayProfile })" + replace: "$&,$self.profilePopoutComponent({ user: arguments[0].user, displayProfile: arguments[0].displayProfile, compactSpacing: false })" } }, { @@ -188,6 +190,13 @@ export default definePlugin({ match: /\(0,\i\.jsx\)\(\i\.\i,\{\}\).{0,100}setNote:(?=.+?channelId:(\i).id)/, replace: "$self.profilePanelComponent({ id: $1.recipients[0] }),$&" } + }, + { + find: "autoFocusNote:!0})", + replacement: { + match: /{autoFocusNote:!1}\)}\)(?<=user:(\i),bio:null==(\i)\?.+?)/, + replace: "$&,$self.profilePopoutComponent({ user: $1, displayProfile: $2, compactSpacing: true })" + } } ], settings,