Compare commits

..

1 commit

Author SHA1 Message Date
f5ac9304ae
owo 2023-10-14 14:30:56 +09:00
30 changed files with 107 additions and 253 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.5.8", "version": "1.5.6",
"description": "The cutest Discord client mod", "description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme", "homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": { "bugs": {

View file

@ -43,7 +43,7 @@ const nodeCommonOpts = {
format: "cjs", format: "cjs",
platform: "node", platform: "node",
target: ["esnext"], target: ["esnext"],
external: ["electron", "original-fs", ...commonOpts.external], external: ["electron", ...commonOpts.external],
define: defines, define: defines,
}; };

View file

@ -61,13 +61,6 @@ const report = {
otherErrors: [] as string[] otherErrors: [] as string[]
}; };
const IGNORED_DISCORD_ERRORS = [
"KeybindStore: Looking for callback action",
"Unable to process domain list delta: Client revision number is null",
"Downloading the full bad domains file",
/\[GatewaySocket\].{0,110}Cannot access '/
] as Array<string | RegExp>;
function toCodeBlock(s: string) { function toCodeBlock(s: string) {
s = s.replace(/```/g, "`\u200B`\u200B`"); s = s.replace(/```/g, "`\u200B`\u200B`");
return "```" + s + " ```"; return "```" + s + " ```";
@ -93,8 +86,6 @@ async function printReport() {
console.log(` - Error: ${toCodeBlock(p.error)}`); console.log(` - Error: ${toCodeBlock(p.error)}`);
}); });
report.otherErrors = report.otherErrors.filter(e => !IGNORED_DISCORD_ERRORS.some(regex => e.match(regex)));
console.log("## Discord Errors"); console.log("## Discord Errors");
report.otherErrors.forEach(e => { report.otherErrors.forEach(e => {
console.log(`- ${toCodeBlock(e)}`); console.log(`- ${toCodeBlock(e)}`);

View file

@ -17,7 +17,6 @@
font-size: 20px; font-size: 20px;
height: 20px; height: 20px;
position: relative; position: relative;
text-wrap: nowrap;
} }
.vc-author-modal-name::before { .vc-author-modal-name::before {

View file

@ -25,7 +25,7 @@ import { Margins } from "@utils/margins";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { showItemInFolder } from "@utils/native"; import { showItemInFolder } from "@utils/native";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
import { findByPropsLazy, findLazy } from "@webpack"; import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack";
import { Button, Card, FluxDispatcher, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common"; import { Button, Card, FluxDispatcher, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common";
import { UserThemeHeader } from "main/themes"; import { UserThemeHeader } from "main/themes";
import type { ComponentType, Ref, SyntheticEvent } from "react"; import type { ComponentType, Ref, SyntheticEvent } from "react";
@ -41,7 +41,7 @@ type FileInput = ComponentType<{
}>; }>;
const InviteActions = findByPropsLazy("resolveInvite"); const InviteActions = findByPropsLazy("resolveInvite");
const FileInput: FileInput = findLazy(m => m.prototype?.activateUploadDialogue && m.prototype.setRef); const FileInput: FileInput = findByCodeLazy("activateUploadDialogue=");
const TextAreaProps = findLazy(m => typeof m.textarea === "string"); const TextAreaProps = findLazy(m => typeof m.textarea === "string");
const cl = classNameFactory("vc-settings-theme-"); const cl = classNameFactory("vc-settings-theme-");

View file

@ -62,10 +62,6 @@ if (IS_VESKTOP || !IS_VANILLA) {
} catch { } } catch { }
const findHeader = (headers: Record<string, string[]>, headerName: Lowercase<string>) => {
return Object.keys(headers).find(h => h.toLowerCase() === headerName);
};
// Remove CSP // Remove CSP
type PolicyResult = Record<string, string[]>; type PolicyResult = Record<string, string[]>;
@ -77,7 +73,6 @@ if (IS_VESKTOP || !IS_VANILLA) {
result[directiveKey] = directiveValue; result[directiveKey] = directiveValue;
} }
}); });
return result; return result;
}; };
const stringifyPolicy = (policy: PolicyResult): string => const stringifyPolicy = (policy: PolicyResult): string =>
@ -86,39 +81,31 @@ if (IS_VESKTOP || !IS_VANILLA) {
.map(directive => directive.flat().join(" ")) .map(directive => directive.flat().join(" "))
.join("; "); .join("; ");
const patchCsp = (headers: Record<string, string[]>) => { function patchCsp(headers: Record<string, string[]>, header: string) {
const header = findHeader(headers, "content-security-policy"); if (header in headers) {
if (header) {
const csp = parsePolicy(headers[header][0]); const csp = parsePolicy(headers[header][0]);
for (const directive of ["style-src", "connect-src", "img-src", "font-src", "media-src", "worker-src"]) { for (const directive of ["style-src", "connect-src", "img-src", "font-src", "media-src", "worker-src"]) {
csp[directive] ??= []; csp[directive] = ["*", "blob:", "data:", "vencord:", "'unsafe-inline'"];
csp[directive].push("*", "blob:", "data:", "vencord:", "'unsafe-inline'");
} }
// TODO: Restrict this to only imported packages with fixed version. // TODO: Restrict this to only imported packages with fixed version.
// Perhaps auto generate with esbuild // Perhaps auto generate with esbuild
csp["script-src"] ??= []; csp["script-src"] ??= [];
csp["script-src"].push("'unsafe-eval'", "https://unpkg.com", "https://cdnjs.cloudflare.com"); csp["script-src"].push("'unsafe-eval'", "https://unpkg.com", "https://cdnjs.cloudflare.com");
headers[header] = [stringifyPolicy(csp)]; headers[header] = [stringifyPolicy(csp)];
} }
}; }
session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => { session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
if (responseHeaders) { if (responseHeaders) {
if (resourceType === "mainFrame") if (resourceType === "mainFrame")
patchCsp(responseHeaders); patchCsp(responseHeaders, "content-security-policy");
// Fix hosts that don't properly set the css content type, such as // Fix hosts that don't properly set the css content type, such as
// raw.githubusercontent.com // raw.githubusercontent.com
if (resourceType === "stylesheet") { if (resourceType === "stylesheet")
const header = findHeader(responseHeaders, "content-type"); responseHeaders["content-type"] = ["text/css"];
if (header)
responseHeaders[header] = ["text/css"];
}
} }
cb({ cancel: false, responseHeaders }); cb({ cancel: false, responseHeaders });
}); });

View file

@ -17,7 +17,7 @@
*/ */
import { app } from "electron"; import { app } from "electron";
import { existsSync, mkdirSync, readdirSync, renameSync, statSync, writeFileSync } from "original-fs"; import { existsSync, mkdirSync, readdirSync, renameSync, statSync, writeFileSync } from "fs";
import { basename, dirname, join } from "path"; import { basename, dirname, join } from "path";
function isNewer($new: string, old: string) { function isNewer($new: string, old: string) {

View file

@ -27,8 +27,8 @@ export default definePlugin({
{ {
find: ".withMentionPrefix", find: ".withMentionPrefix",
replacement: { replacement: {
match: /currentUserIsPremium:.{0,70}{children:\i(?=}\))/, match: /(.roleDot.{10,50}{children:.{1,2})}\)/,
replace: "$&.concat(Vencord.Api.MessageDecorations.__addDecorationsToMessage(arguments[0]))" replace: "$1.concat(Vencord.Api.MessageDecorations.__addDecorationsToMessage(arguments[0]))})"
} }
} }
], ],

View file

@ -63,26 +63,26 @@ export default definePlugin({
replacement: { replacement: {
get match() { get match() {
switch (Settings.plugins.Settings.settingsLocation) { switch (Settings.plugins.Settings.settingsLocation) {
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS\}/; case "top": return /\{section:(\i)\.ID\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS\}/;
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS\}/; case "aboveNitro": return /\{section:(\i)\.ID\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS\}/;
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS\}/; case "belowNitro": return /\{section:(\i)\.ID\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS\}/;
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/; case "belowActivity": return /(?<=\{section:(\i)\.ID\.DIVIDER},)\{section:"changelog"/;
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/; case "bottom": return /\{section:(\i)\.ID\.CUSTOM,\s*element:.+?}/;
case "aboveActivity": case "aboveActivity":
default: default:
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS\}/; return /\{section:(\i)\.ID\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS\}/;
} }
}, },
replace: "...$self.makeSettingsCategories($1),$&" replace: "...$self.makeSettingsCategories($1),$&"
} }
}], }],
customSections: [] as ((SectionTypes: Record<string, unknown>) => any)[], customSections: [] as ((ID: Record<string, unknown>) => any)[],
makeSettingsCategories(SectionTypes: Record<string, unknown>) { makeSettingsCategories({ ID }: { ID: Record<string, unknown>; }) {
return [ return [
{ {
section: SectionTypes.HEADER, section: ID.HEADER,
label: "Vencord", label: "Vencord",
className: "vc-settings-header" className: "vc-settings-header"
}, },
@ -128,9 +128,9 @@ export default definePlugin({
element: require("@components/VencordSettings/PatchHelperTab").default, element: require("@components/VencordSettings/PatchHelperTab").default,
className: "vc-patch-helper" className: "vc-patch-helper"
}, },
...this.customSections.map(func => func(SectionTypes)), ...this.customSections.map(func => func(ID)),
{ {
section: SectionTypes.DIVIDER section: ID.DIVIDER
} }
].filter(Boolean); ].filter(Boolean);
}, },

View file

@ -19,9 +19,6 @@
import { Settings } from "@api/Settings"; import { Settings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
const UserPopoutSectionCssClasses = findByPropsLazy("section", "lastSection");
export default definePlugin({ export default definePlugin({
name: "BetterNotesBox", name: "BetterNotesBox",
@ -37,20 +34,12 @@ export default definePlugin({
match: /hideNote:.+?(?=[,}])/g, match: /hideNote:.+?(?=[,}])/g,
replace: "hideNote:true", replace: "hideNote:true",
} }
}, }, {
{
find: "Messages.NOTE_PLACEHOLDER", find: "Messages.NOTE_PLACEHOLDER",
replacement: { replacement: {
match: /\.NOTE_PLACEHOLDER,/, match: /\.NOTE_PLACEHOLDER,/,
replace: "$&spellCheck:!Vencord.Settings.plugins.BetterNotesBox.noSpellCheck," replace: "$&spellCheck:!Vencord.Settings.plugins.BetterNotesBox.noSpellCheck,"
} }
},
{
find: ".Messages.NOTE}",
replacement: {
match: /(\i)\.hideNote\?null/,
replace: "$1.hideNote?$self.patchPadding($1)"
}
} }
], ],
@ -67,12 +56,5 @@ export default definePlugin({
disabled: () => Settings.plugins.BetterNotesBox.hide, disabled: () => Settings.plugins.BetterNotesBox.hide,
default: false default: false
} }
},
patchPadding(e: any) {
if (!e.lastSection) return;
return (
<div className={UserPopoutSectionCssClasses.lastSection}></div>
);
} }
}); });

View file

@ -77,6 +77,15 @@ export default definePlugin({
} }
] ]
}, },
// Fix search history being disabled / broken with isStaff
{
find: 'get("disable_new_search")',
predicate: () => settings.store.enableIsStaff,
replacement: {
match: /(?<=showNewSearch"\);return)\s?!/,
replace: "!1&&!"
}
},
{ {
find: 'H1,title:"Experiments"', find: 'H1,title:"Experiments"',
replacement: { replacement: {

View file

@ -295,7 +295,7 @@ export default definePlugin({
}, },
{ {
predicate: () => settings.store.transformStickers, predicate: () => settings.store.transformStickers,
match: /renderAttachments=function\(\i\){var \i=this,(\i)=\i.attachments.+?;/, match: /renderAttachments=function\(\i\){var (\i)=\i.attachments.+?;/,
replace: (m, attachments) => `${m}${attachments}=$self.filterAttachments(${attachments});` replace: (m, attachments) => `${m}${attachments}=$self.filterAttachments(${attachments});`
} }
] ]
@ -329,20 +329,6 @@ export default definePlugin({
match: /(?<=\.Messages\.EMOJI_POPOUT_ADDED_PACK_DESCRIPTION.+?return ).{0,1200}\.Messages\.EMOJI_POPOUT_UNJOINED_DISCOVERABLE_GUILD_DESCRIPTION.+?(?=}\()/, match: /(?<=\.Messages\.EMOJI_POPOUT_ADDED_PACK_DESCRIPTION.+?return ).{0,1200}\.Messages\.EMOJI_POPOUT_UNJOINED_DISCOVERABLE_GUILD_DESCRIPTION.+?(?=}\()/,
replace: reactNode => `$self.addFakeNotice(${FakeNoticeType.Emoji},${reactNode},!!arguments[0]?.fakeNitroNode?.fake)` replace: reactNode => `$self.addFakeNotice(${FakeNoticeType.Emoji},${reactNode},!!arguments[0]?.fakeNitroNode?.fake)`
} }
},
{
find: "canUsePremiumAppIcons:function",
replacement: {
match: /canUsePremiumAppIcons:function\(\i\){/,
replace: "$&return true;"
}
},
{
find: "location:\"AppIconHome\"",
replacement: {
match: /\i\.\i\.isPremium\(\i\.\i\.getCurrentUser\(\)\)/,
replace: "true"
}
} }
], ],

View file

@ -19,7 +19,6 @@
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { GuildStore } from "@webpack/common"; import { GuildStore } from "@webpack/common";
import { Channel, User } from "discord-types/general";
export default definePlugin({ export default definePlugin({
name: "ForceOwnerCrown", name: "ForceOwnerCrown",
@ -35,15 +34,25 @@ export default definePlugin({
} }
} }
], ],
isGuildOwner(props: { user: User, channel: Channel, guildId?: string; }) { isGuildOwner(props) {
if (!props?.user?.id) return false; // Check if channel is a Group DM, if so return false
if (props.channel?.type === 3 /* GROUP_DM */) if (props?.channel?.type === 3) {
return false; return false;
}
// guild id is in props twice, fallback if the first is undefined // guild id is in props twice, fallback if the first is undefined
const guildId = props.guildId ?? props.channel?.guild_id; const guildId = props?.guildId ?? props?.channel?.guild_id;
const userId = props.user.id; const userId = props?.user?.id;
return GuildStore.getGuild(guildId)?.ownerId === userId; if (guildId && userId) {
const guild = GuildStore.getGuild(guildId);
if (guild) {
return guild.ownerId === userId;
}
console.error("[ForceOwnerCrown] failed to get guild", { guildId, guild, props });
} else {
console.error("[ForceOwnerCrown] no guildId or userId", { guildId, userId, props });
}
return false;
}, },
}); });

View file

@ -106,7 +106,7 @@ export default definePlugin({
} }
}, },
{ {
find: ".Messages.EMBEDDED_ACTIVITIES_DEVELOPER_SHELF_SUBTITLE", find: ".Messages.EMBEDDED_ACTIVITIES_HAVE_PLAYED_ONE_KNOWN",
replacement: [ replacement: [
{ {
match: /(?<=\(\)\.activityTitleText.+?children:(\i)\.name.*?}\),)/, match: /(?<=\(\)\.activityTitleText.+?children:(\i)\.name.*?}\),)/,

View file

@ -360,7 +360,7 @@ export default definePlugin({
{ {
// Render editHistory in the deepest div for message content // Render editHistory in the deepest div for message content
match: /(\)\("div",\{id:.+?children:\[)/, 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 > 0 ? arguments[0].message.editHistory.map(edit => $self.renderEdit(edit)) : null), "
} }
] ]
}, },

View file

@ -84,8 +84,8 @@ export default definePlugin({
find: "showProgressBadge:", find: "showProgressBadge:",
predicate: () => settings.store.hidePremiumOffersCount, predicate: () => settings.store.hidePremiumOffersCount,
replacement: { replacement: {
match: /=\i\.unviewedTrialCount\+\i\.unviewedDiscountCount/, match: /\(function\(\){return \i\.\i\.getUnacknowledgedOffers\(\i\)\.length}\)/,
replace: "=0" replace: "(function(){return 0})"
} }
} }
], ],

View file

@ -1,21 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
export default definePlugin({
name: "NoTypingAnimation",
authors: [Devs.AutumnVN],
description: "Disables the CPU-intensive typing dots animation",
patches: [{
find: "dotCycle",
replacement: {
match: /document.hasFocus\(\)/,
replace: "false"
}
}]
});

View file

@ -4,44 +4,20 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin from "@utils/types";
import { ChannelStore, ReadStateStore, UserStore } from "@webpack/common"; import { ChannelStore, ReadStateStore } from "@webpack/common";
import { MessageJSON } from "discord-types/general"; import { Message } from "discord-types/general";
const enum ChannelType { const enum ChannelType {
DM = 1, DM = 1,
GROUP_DM = 3 GROUP_DM = 3
} }
const settings = definePluginSettings({
channelToAffect: {
type: OptionType.SELECT,
description: "Select the type of DM for the plugin to affect",
options: [
{ label: "Both", value: "both_dms", default: true },
{ label: "User DMs", value: "user_dm" },
{ label: "Group DMs", value: "group_dm" },
]
},
allowMentions: {
type: OptionType.BOOLEAN,
description: "Receive audio pings for @mentions",
default: false,
},
allowEveryone: {
type: OptionType.BOOLEAN,
description: "Receive audio pings for @everyone and @here in group DMs",
default: false,
},
});
export default definePlugin({ export default definePlugin({
name: "OnePingPerDM", name: "OnePingPerDM",
description: "If unread messages are sent by a user in DMs multiple times, you'll only receive one audio ping. Read the messages to reset the limit", description: "If unread messages are sent by a user in DMs multiple times, you'll only receive one audio ping. Read the messages to reset the limit",
authors: [Devs.ProffDea], authors: [Devs.ProffDea],
settings,
patches: [{ patches: [{
find: ".getDesktopType()===", find: ".getDesktopType()===",
replacement: [{ replacement: [{
@ -53,19 +29,11 @@ export default definePlugin({
replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1" replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1"
}] }]
}], }],
isPrivateChannelRead(message: MessageJSON) { isPrivateChannelRead(message: Message) {
const channelType = ChannelStore.getChannel(message.channel_id)?.type; const channelType = ChannelStore.getChannel(message.channel_id)?.type;
if (channelType !== ChannelType.DM && channelType !== ChannelType.GROUP_DM) { if (channelType !== ChannelType.DM && channelType !== ChannelType.GROUP_DM) {
return false; return false;
} }
if (
(channelType === ChannelType.DM && settings.store.channelToAffect === "group_dm") ||
(channelType === ChannelType.GROUP_DM && settings.store.channelToAffect === "user_dm") ||
(settings.store.allowMentions && message.mentions.some(m => m.id === UserStore.getCurrentUser().id)) ||
(settings.store.allowEveryone && message.mention_everyone)
) {
return true;
}
return ReadStateStore.getOldestUnreadMessageId(message.channel_id) === message.id; return ReadStateStore.getOldestUnreadMessageId(message.channel_id) === message.id;
}, },
}); });

View file

@ -81,7 +81,7 @@ export default definePlugin({
// array with the count, or an empty array. Due to spreading, only in the former // array with the count, or an empty array. Due to spreading, only in the former
// case will an element be added to the outer array // case will an element be added to the outer array
// Thanks for the fix, Strencher! // Thanks for the fix, Strencher!
replace: "$&...($1.props.pinCount ?? [])," replace: "$&...$1.props.pinCount,"
}, },
{ {
// Patch renderSection (renders the header) to set the text to "Pinned DMs" instead of "Direct Messages" // Patch renderSection (renders the header) to set the text to "Pinned DMs" instead of "Direct Messages"

View file

@ -30,13 +30,13 @@ import { User } from "discord-types/general";
const SessionsStore = findStoreLazy("SessionsStore"); const SessionsStore = findStoreLazy("SessionsStore");
function Icon(path: string, opts?: { viewBox?: string; width?: number; height?: number; }) { function Icon(path: string, opts?: { viewBox?: string; width?: number; height?: number; }) {
return ({ color, tooltip, small }: { color: string; tooltip: string; small: boolean; }) => ( return ({ color, tooltip }: { color: string; tooltip: string; }) => (
<Tooltip text={tooltip} > <Tooltip text={tooltip} >
{(tooltipProps: any) => ( {(tooltipProps: any) => (
<svg <svg
{...tooltipProps} {...tooltipProps}
height={(opts?.height ?? 20) - (small ? 3 : 0)} height={opts?.height ?? 20}
width={(opts?.width ?? 20) - (small ? 3 : 0)} width={opts?.width ?? 20}
viewBox={opts?.viewBox ?? "0 0 24 24"} viewBox={opts?.viewBox ?? "0 0 24 24"}
fill={color} fill={color}
> >
@ -57,16 +57,16 @@ type Platform = keyof typeof Icons;
const getStatusColor = findByCodeLazy(".TWITCH", ".STREAMING", ".INVISIBLE"); const getStatusColor = findByCodeLazy(".TWITCH", ".STREAMING", ".INVISIBLE");
const PlatformIcon = ({ platform, status, small }: { platform: Platform, status: string; small: boolean; }) => { const PlatformIcon = ({ platform, status }: { platform: Platform, status: string; }) => {
const tooltip = platform[0].toUpperCase() + platform.slice(1); const tooltip = platform[0].toUpperCase() + platform.slice(1);
const Icon = Icons[platform] ?? Icons.desktop; const Icon = Icons[platform] ?? Icons.desktop;
return <Icon color={`var(--${getStatusColor(status)}`} tooltip={tooltip} small={small} />; return <Icon color={`var(--${getStatusColor(status)}`} tooltip={tooltip} />;
}; };
const getStatus = (id: string): Record<Platform, string> => PresenceStore.getState()?.clientStatuses?.[id]; const getStatus = (id: string): Record<Platform, string> => PresenceStore.getState()?.clientStatuses?.[id];
const PlatformIndicator = ({ user, wantMargin = true, wantTopMargin = false, small = false }: { user: User; wantMargin?: boolean; wantTopMargin?: boolean; small?: boolean; }) => { const PlatformIndicator = ({ user, wantMargin = true, wantTopMargin = false }: { user: User; wantMargin?: boolean; wantTopMargin?: boolean; }) => {
if (!user || user.bot) return null; if (!user || user.bot) return null;
if (user.id === UserStore.getCurrentUser().id) { if (user.id === UserStore.getCurrentUser().id) {
@ -99,7 +99,6 @@ const PlatformIndicator = ({ user, wantMargin = true, wantTopMargin = false, sma
key={platform} key={platform}
platform={platform as Platform} platform={platform as Platform}
status={status} status={status}
small={small}
/> />
)); ));
@ -138,7 +137,7 @@ const indicatorLocations = {
description: "In the member list", description: "In the member list",
onEnable: () => addDecorator("platform-indicator", props => onEnable: () => addDecorator("platform-indicator", props =>
<ErrorBoundary noop> <ErrorBoundary noop>
<PlatformIndicator user={props.user} small={true} /> <PlatformIndicator user={props.user} />
</ErrorBoundary> </ErrorBoundary>
), ),
onDisable: () => removeDecorator("platform-indicator") onDisable: () => removeDecorator("platform-indicator")

View file

@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { UserStore } from "@webpack/common"; import { UserStore } from "@webpack/common";
@ -40,17 +39,17 @@ function shouldShow(message: Message): boolean {
return true; return true;
} }
export const PronounsChatComponentWrapper = ErrorBoundary.wrap(({ message }: { message: Message; }) => { export function PronounsChatComponentWrapper({ message }: { message: Message; }) {
return shouldShow(message) return shouldShow(message)
? <PronounsChatComponent message={message} /> ? <PronounsChatComponent message={message} />
: null; : null;
}, { noop: true }); }
export const CompactPronounsChatComponentWrapper = ErrorBoundary.wrap(({ message }: { message: Message; }) => { export function CompactPronounsChatComponentWrapper({ message }: { message: Message; }) {
return shouldShow(message) return shouldShow(message)
? <CompactPronounsChatComponent message={message} /> ? <CompactPronounsChatComponent message={message} />
: null; : null;
}, { noop: true }); }
function PronounsChatComponent({ message }: { message: Message; }) { function PronounsChatComponent({ message }: { message: Message; }) {
const [result] = useFormattedPronouns(message.author.id); const [result] = useFormattedPronouns(message.author.id);
@ -64,7 +63,7 @@ function PronounsChatComponent({ message }: { message: Message; }) {
: null; : null;
} }
export const CompactPronounsChatComponent = ErrorBoundary.wrap(({ message }: { message: Message; }) => { export function CompactPronounsChatComponent({ message }: { message: Message; }) {
const [result] = useFormattedPronouns(message.author.id); const [result] = useFormattedPronouns(message.author.id);
return result return result
@ -74,4 +73,4 @@ export const CompactPronounsChatComponent = ErrorBoundary.wrap(({ message }: { m
> {result}</span> > {result}</span>
) )
: null; : null;
}, { noop: true }); }

View file

@ -41,7 +41,7 @@ export default definePlugin({
find: "showCommunicationDisabledStyles", find: "showCommunicationDisabledStyles",
replacement: { replacement: {
match: /("span",{id:\i,className:\i,children:\i}\))/, match: /("span",{id:\i,className:\i,children:\i}\))/,
replace: "$1, $self.CompactPronounsChatComponentWrapper(arguments[0])" replace: "$1, $self.CompactPronounsChatComponentWrapper(e)"
} }
}, },
// Patch the chat timestamp element (normal mode) // Patch the chat timestamp element (normal mode)
@ -49,7 +49,7 @@ export default definePlugin({
find: "showCommunicationDisabledStyles", find: "showCommunicationDisabledStyles",
replacement: { replacement: {
match: /(?<=return\s*\(0,\i\.jsxs?\)\(.+!\i&&)(\(0,\i.jsxs?\)\(.+?\{.+?\}\))/, match: /(?<=return\s*\(0,\i\.jsxs?\)\(.+!\i&&)(\(0,\i.jsxs?\)\(.+?\{.+?\}\))/,
replace: "[$1, $self.PronounsChatComponentWrapper(arguments[0])]" replace: "[$1, $self.PronounsChatComponentWrapper(e)]"
} }
}, },
// Patch the profile popout username header to use our pronoun hook instead of Discord's pronouns // Patch the profile popout username header to use our pronoun hook instead of Discord's pronouns

View file

@ -1,4 +1,4 @@
.vc-uvs-button>div { .vc-uvs-button > div {
white-space: normal !important; white-space: normal !important;
} }
@ -21,7 +21,6 @@
margin-bottom: 0 !important; margin-bottom: 0 !important;
} }
.vc-uvs-popout-margin-self>[class^="section"] { .vc-uvs-popout-margin > [class^="section"] {
padding-top: 0; margin-top: -12px;
padding-bottom: 12px;
} }

View file

@ -20,13 +20,14 @@ import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findStoreLazy } from "@webpack"; import { findByPropsLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildStore, UserStore } from "@webpack/common"; import { ChannelStore, GuildStore, UserStore } from "@webpack/common";
import { User } from "discord-types/general"; import { User } from "discord-types/general";
import { VoiceChannelSection } from "./components/VoiceChannelSection"; import { VoiceChannelSection } from "./components/VoiceChannelSection";
const VoiceStateStore = findStoreLazy("VoiceStateStore"); const VoiceStateStore = findStoreLazy("VoiceStateStore");
const UserPopoutSectionCssClasses = findByPropsLazy("section", "lastSection");
const settings = definePluginSettings({ const settings = definePluginSettings({
showInUserProfileModal: { showInUserProfileModal: {
@ -87,7 +88,7 @@ export default definePlugin({
patchPopout: ({ user }: UserProps) => { patchPopout: ({ user }: UserProps) => {
const isSelfUser = user.id === UserStore.getCurrentUser().id; const isSelfUser = user.id === UserStore.getCurrentUser().id;
return ( return (
<div className={isSelfUser ? "vc-uvs-popout-margin-self" : ""}> <div className={isSelfUser ? `vc-uvs-popout-margin ${UserPopoutSectionCssClasses.lastSection}` : ""}>
<VoiceChannelField user={user} /> <VoiceChannelField user={user} />
</div> </div>
); );

View file

@ -24,7 +24,7 @@ import { Margins } from "@utils/margins";
import { wordsToTitle } from "@utils/text"; import { wordsToTitle } from "@utils/text";
import definePlugin, { OptionType, PluginOptionsItem } from "@utils/types"; import definePlugin, { OptionType, PluginOptionsItem } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { Button, ChannelStore, Forms, GuildMemberStore, SelectedChannelStore, SelectedGuildStore, useMemo, UserStore } from "@webpack/common"; import { Button, ChannelStore, Forms, SelectedChannelStore, useMemo, UserStore } from "@webpack/common";
interface VoiceState { interface VoiceState {
userId: string; userId: string;
@ -70,12 +70,11 @@ function clean(str: string) {
.trim(); .trim();
} }
function formatText(str: string, user: string, channel: string, displayName: string, nickname: string) { function formatText(str: string, user: string, channel: string, displayName: string) {
return str return str
.replaceAll("{{USER}}", clean(user) || (user ? "Someone" : "")) .replaceAll("{{USER}}", clean(user) || (user ? "Someone" : ""))
.replaceAll("{{CHANNEL}}", clean(channel) || "channel") .replaceAll("{{CHANNEL}}", clean(channel) || "channel")
.replaceAll("{{DISPLAY_NAME}}", clean(displayName) || (displayName ? "Someone" : "")) .replaceAll("{{DISPLAY_NAME}}", clean(displayName) || (displayName ? "Someone" : ""));
.replaceAll("{{NICKNAME}}", clean(nickname) || (nickname ? "Someone" : ""));
} }
/* /*
@ -146,9 +145,8 @@ function updateStatuses(type: string, { deaf, mute, selfDeaf, selfMute, userId,
function playSample(tempSettings: any, type: string) { function playSample(tempSettings: any, type: string) {
const settings = Object.assign({}, Settings.plugins.VcNarrator, tempSettings); const settings = Object.assign({}, Settings.plugins.VcNarrator, tempSettings);
const currentUser = UserStore.getCurrentUser(); const currentUser = UserStore.getCurrentUser();
const myGuildId = SelectedGuildStore.getGuildId();
speak(formatText(settings[type + "Message"], currentUser.username, "general", (currentUser as any).globalName ?? currentUser.username, GuildMemberStore.getNick(myGuildId, currentUser.id) ?? currentUser.username), settings); speak(formatText(settings[type + "Message"], currentUser.username, "general", (currentUser as any).globalName ?? currentUser.username), settings);
} }
export default definePlugin({ export default definePlugin({
@ -158,7 +156,6 @@ export default definePlugin({
flux: { flux: {
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) { VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) {
const myGuildId = SelectedGuildStore.getGuildId();
const myChanId = SelectedChannelStore.getVoiceChannelId(); const myChanId = SelectedChannelStore.getVoiceChannelId();
const myId = UserStore.getCurrentUser().id; const myId = UserStore.getCurrentUser().id;
@ -178,10 +175,9 @@ export default definePlugin({
const template = Settings.plugins.VcNarrator[type + "Message"]; const template = Settings.plugins.VcNarrator[type + "Message"];
const user = isMe && !Settings.plugins.VcNarrator.sayOwnName ? "" : UserStore.getUser(userId).username; const user = isMe && !Settings.plugins.VcNarrator.sayOwnName ? "" : UserStore.getUser(userId).username;
const displayName = user && ((UserStore.getUser(userId) as any).globalName ?? user); const displayName = user && ((UserStore.getUser(userId) as any).globalName ?? user);
const nickname = user && (GuildMemberStore.getNick(myGuildId, userId) ?? user);
const channel = ChannelStore.getChannel(id).name; const channel = ChannelStore.getChannel(id).name;
speak(formatText(template, user, channel, displayName, nickname)); speak(formatText(template, user, channel, displayName));
// updateStatuses(type, state, isMe); // updateStatuses(type, state, isMe);
} }
@ -193,7 +189,7 @@ export default definePlugin({
if (!s) return; if (!s) return;
const event = s.mute || s.selfMute ? "unmute" : "mute"; const event = s.mute || s.selfMute ? "unmute" : "mute";
speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name, "", "")); speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name, ""));
}, },
AUDIO_TOGGLE_SELF_DEAF() { AUDIO_TOGGLE_SELF_DEAF() {
@ -202,7 +198,7 @@ export default definePlugin({
if (!s) return; if (!s) return;
const event = s.deaf || s.selfDeaf ? "undeafen" : "deafen"; const event = s.deaf || s.selfDeaf ? "undeafen" : "deafen";
speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name, "", "")); speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name, ""));
} }
}, },
@ -319,8 +315,8 @@ export default definePlugin({
You can customise the spoken messages below. You can disable specific messages by setting them to nothing You can customise the spoken messages below. You can disable specific messages by setting them to nothing
</Forms.FormText> </Forms.FormText>
<Forms.FormText> <Forms.FormText>
The special placeholders <code>{"{{USER}}"}</code>, <code>{"{{DISPLAY_NAME}}"}</code>, <code>{"{{NICKNAME}}"}</code> and <code>{"{{CHANNEL}}"}</code>{" "} The special placeholders <code>{"{{USER}}"}</code>, <code>{"{{DISPLAY_NAME}}"}</code> and <code>{"{{CHANNEL}}"}</code>{" "}
will be replaced with the user's name (nothing if it's yourself), the user's display name, the user's nickname on current server and the channel's name respectively will be replaced with the user's name (nothing if it's yourself), the user's display name and the channel's name respectively
</Forms.FormText> </Forms.FormText>
{hasEnglishVoices && ( {hasEnglishVoices && (
<> <>

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { filters, findByCode, findByPropsLazy, mapMangledModuleLazy } from "@webpack"; import { filters, findByCode, mapMangledModuleLazy } from "@webpack";
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react"; import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
import { LazyComponent } from "./react"; import { LazyComponent } from "./react";
@ -132,7 +132,12 @@ export const ModalContent = LazyComponent(() => Modals.ModalContent);
export const ModalFooter = LazyComponent(() => Modals.ModalFooter); export const ModalFooter = LazyComponent(() => Modals.ModalFooter);
export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton); export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton);
const ModalAPI = findByPropsLazy("openModalLazy"); const ModalAPI = mapMangledModuleLazy("onCloseRequest:null!=", {
openModal: filters.byCode("onCloseRequest:null!="),
closeModal: filters.byCode("onCloseCallback&&"),
openModalLazy: m => m?.length === 1 && filters.byCode(".apply(this,arguments)")(m),
closeAllModals: filters.byCode(".value.key,")
});
/** /**
* Wait for the render promise to resolve, then open a modal with it. * Wait for the render promise to resolve, then open a modal with it.

View file

@ -16,11 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { proxyLazy } from "@utils/lazy";
import type * as Stores from "discord-types/stores"; import type * as Stores from "discord-types/stores";
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { filters, findByCode, findByProps, findByPropsLazy, mapMangledModuleLazy } from "../webpack"; import { filters, findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "../webpack";
import { waitForStore } from "./internal"; import { waitForStore } from "./internal";
import * as t from "./types/stores"; import * as t from "./types/stores";
@ -84,14 +83,7 @@ export const useStateFromStores: <T>(
idk?: any, idk?: any,
isEqual?: (old: T, newer: T) => boolean isEqual?: (old: T, newer: T) => boolean
) => T ) => T
// FIXME: hack to support old stable and new canary = findByCodeLazy("useStateFromStores");
= proxyLazy(() => {
try {
return findByProps("useStateFromStores").useStateFromStores;
} catch {
return findByCode('("useStateFromStores")');
}
});
waitForStore("DraftStore", s => DraftStore = s); waitForStore("DraftStore", s => DraftStore = s);
waitForStore("UserStore", s => UserStore = s); waitForStore("UserStore", s => UserStore = s);

View file

@ -16,11 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { proxyLazy } from "@utils/lazy";
import type { User } from "discord-types/general"; import type { User } from "discord-types/general";
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { _resolveReady, filters, find, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack"; import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
import type * as t from "./types/utils"; import type * as t from "./types/utils";
export let FluxDispatcher: t.FluxDispatcher; export let FluxDispatcher: t.FluxDispatcher;
@ -127,11 +126,4 @@ waitFor("parseTopic", m => Parser = m);
export let SettingsRouter: any; export let SettingsRouter: any;
waitFor(["open", "saveAccountChanges"], m => SettingsRouter = m); waitFor(["open", "saveAccountChanges"], m => SettingsRouter = m);
// FIXME: hack to support old stable and new canary export const PermissionsBits: t.PermissionsBits = findLazy(m => typeof m.ADMINISTRATOR === "bigint");
export const PermissionsBits: t.PermissionsBits = proxyLazy(() => {
try {
return find(m => m.Permissions?.ADMINISTRATOR).Permissions;
} catch {
return find(m => typeof m.ADMINISTRATOR === "bigint");
}
});

View file

@ -36,8 +36,9 @@ if (window[WEBPACK_CHUNK]) {
Object.defineProperty(window, WEBPACK_CHUNK, { Object.defineProperty(window, WEBPACK_CHUNK, {
get: () => webpackChunk, get: () => webpackChunk,
set: v => { set: v => {
if (v?.push !== Array.prototype.push && _initWebpack(v)) { if (v?.push !== Array.prototype.push) {
logger.info(`Patching ${WEBPACK_CHUNK}.push`); logger.info(`Patching ${WEBPACK_CHUNK}.push`);
_initWebpack(v);
patchPush(); patchPush();
// @ts-ignore // @ts-ignore
delete window[WEBPACK_CHUNK]; delete window[WEBPACK_CHUNK];
@ -84,9 +85,10 @@ function patchPush() {
logger.error("Error in patched chunk", err); logger.error("Error in patched chunk", err);
return void originalMod(module, exports, require); return void originalMod(module, exports, require);
} }
// There are (at the time of writing) 11 modules exporting the window // There are (at the time of writing) 11 modules exporting the window
// Make these non enumerable to improve webpack search performance // Make these non enumerable to improve webpack search performance
if (exports === window) { if (module.exports === window) {
Object.defineProperty(require.c, id, { Object.defineProperty(require.c, id, {
value: require.c[id], value: require.c[id],
enumerable: false, enumerable: false,

View file

@ -62,50 +62,9 @@ export type CallbackFn = (mod: any, id: number) => void;
export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) { export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) {
if (cache !== void 0) throw "no."; if (cache !== void 0) throw "no.";
instance.push([[Symbol("Vencord")], {}, r => wreq = r]); wreq = instance.push([[Symbol("Vencord")], {}, r => r]);
if (!wreq) return false;
cache = wreq.c; cache = wreq.c;
instance.pop(); instance.pop();
for (const id in cache) {
const { exports } = cache[id];
if (!exports) continue;
const numberId = Number(id);
for (const callback of listeners) {
try {
callback(exports, numberId);
} catch (err) {
logger.error("Error in webpack listener", err);
}
}
for (const [filter, callback] of subscriptions) {
try {
if (filter(exports)) {
subscriptions.delete(filter);
callback(exports, numberId);
} else if (typeof exports === "object") {
if (exports.default && filter(exports.default)) {
subscriptions.delete(filter);
callback(exports.default, numberId);
}
for (const nested in exports) if (nested.length <= 3) {
if (exports[nested] && filter(exports[nested])) {
subscriptions.delete(filter);
callback(exports[nested], numberId);
}
}
}
} catch (err) {
logger.error("Error while firing callback for webpack chunk", err);
}
}
}
return true;
} }
if (IS_DEV && IS_DISCORD_DESKTOP) { if (IS_DEV && IS_DISCORD_DESKTOP) {