Merge branch 'dev' into immediate-finds

This commit is contained in:
Nuckyz 2024-05-14 22:54:51 -03:00
commit 7c8c2ff5b8
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
6 changed files with 86 additions and 81 deletions

View file

@ -1,11 +1,9 @@
{ {
"recommendations": [ "recommendations": [
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"eamodio.gitlens",
"EditorConfig.EditorConfig", "EditorConfig.EditorConfig",
"ExodiusStudios.comment-anchors",
"formulahendry.auto-rename-tag",
"GregorBiswanger.json2ts", "GregorBiswanger.json2ts",
"stylelint.vscode-stylelint" "stylelint.vscode-stylelint",
"Vendicated.vencord-companion"
] ]
} }

View file

@ -30,6 +30,9 @@ import { i18n, React } from "@webpack/common";
import gitHash from "~git-hash"; import gitHash from "~git-hash";
type SectionType = "HEADER" | "DIVIDER" | "CUSTOM";
type SectionTypes = Record<SectionType, SectionType>;
export default definePlugin({ export default definePlugin({
name: "Settings", name: "Settings",
description: "Adds Settings UI and debug info", description: "Adds Settings UI and debug info",
@ -41,34 +44,18 @@ export default definePlugin({
find: ".versionHash", find: ".versionHash",
replacement: [ replacement: [
{ {
match: /\[\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/, match: /\[\(0,\i\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/,
replace: (m, component, props) => { replace: (m, component, props) => {
props = props.replace(/children:\[.+\]/, ""); props = props.replace(/children:\[.+\]/, "");
return `${m},$self.makeInfoElements(${component}, ${props})`; return `${m},$self.makeInfoElements(${component}, ${props})`;
} }
},
{
match: /copyValue:\i\.join\(" "\)/,
replace: "$& + $self.getInfoString()"
} }
] ]
}, },
// Discord Stable
// FIXME: remove once change merged to stable
{
find: "Messages.ACTIVITY_SETTINGS",
replacement: {
get match() {
switch (Settings.plugins.Settings.settingsLocation) {
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS/;
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS/;
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS/;
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/;
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/;
case "aboveActivity":
default:
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS/;
}
},
replace: "...$self.makeSettingsCategories($1),$&"
}
},
// Discord Canary // Discord Canary
{ {
find: "Messages.ACTIVITY_SETTINGS", find: "Messages.ACTIVITY_SETTINGS",
@ -77,6 +64,13 @@ export default definePlugin({
replace: (_, sectionTypes, commaOrSemi, elements, element) => `${commaOrSemi} $self.addSettings(${elements}, ${element}, ${sectionTypes}) ${commaOrSemi}` replace: (_, sectionTypes, commaOrSemi, elements, element) => `${commaOrSemi} $self.addSettings(${elements}, ${element}, ${sectionTypes}) ${commaOrSemi}`
} }
}, },
{
find: "useDefaultUserSettingsSections:function",
replacement: {
match: /(?<=useDefaultUserSettingsSections:function\(\){return )(\i)\}/,
replace: "$self.wrapSettingsHook($1)}"
}
},
{ {
find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL", find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL",
replacement: { replacement: {
@ -86,9 +80,9 @@ export default definePlugin({
} }
], ],
customSections: [] as ((SectionTypes: Record<string, unknown>) => any)[], customSections: [] as ((SectionTypes: SectionTypes) => any)[],
makeSettingsCategories(SectionTypes: Record<string, unknown>) { makeSettingsCategories(SectionTypes: SectionTypes) {
return [ return [
{ {
section: SectionTypes.HEADER, section: SectionTypes.HEADER,
@ -167,7 +161,7 @@ export default definePlugin({
patchedSettings: new WeakSet(), patchedSettings: new WeakSet(),
addSettings(elements: any[], element: { header?: string; settings: string[]; }, sectionTypes: Record<string, unknown>) { addSettings(elements: any[], element: { header?: string; settings: string[]; }, sectionTypes: SectionTypes) {
if (this.patchedSettings.has(elements) || !this.isRightSpot(element)) return; if (this.patchedSettings.has(elements) || !this.isRightSpot(element)) return;
this.patchedSettings.add(elements); this.patchedSettings.add(elements);
@ -175,6 +169,20 @@ export default definePlugin({
elements.push(...this.makeSettingsCategories(sectionTypes)); elements.push(...this.makeSettingsCategories(sectionTypes));
}, },
wrapSettingsHook(originalHook: (...args: any[]) => Record<string, unknown>[]) {
return (...args: any[]) => {
const elements = originalHook(...args);
if (!this.patchedSettings.has(elements))
elements.unshift(...this.makeSettingsCategories({
HEADER: "HEADER",
DIVIDER: "DIVIDER",
CUSTOM: "CUSTOM"
}));
return elements;
};
},
options: { options: {
settingsLocation: { settingsLocation: {
type: OptionType.SELECT, type: OptionType.SELECT,
@ -213,15 +221,24 @@ export default definePlugin({
return ""; return "";
}, },
makeInfoElements(Component: React.ComponentType<React.PropsWithChildren>, props: React.PropsWithChildren) { getInfoRows() {
const { electronVersion, chromiumVersion, additionalInfo } = this; const { electronVersion, chromiumVersion, additionalInfo } = this;
return ( const rows = [`Vencord ${gitHash}${additionalInfo}`];
<>
<Component {...props}>Vencord {gitHash}{additionalInfo}</Component> if (electronVersion) rows.push(`Electron ${electronVersion}`);
{electronVersion && <Component {...props}>Electron {electronVersion}</Component>} if (chromiumVersion) rows.push(`Chromium ${chromiumVersion}`);
{chromiumVersion && <Component {...props}>Chromium {chromiumVersion}</Component>}
</> return rows;
},
getInfoString() {
return "\n" + this.getInfoRows().join("\n");
},
makeInfoElements(Component: React.ComponentType<React.PropsWithChildren>, props: React.PropsWithChildren) {
return this.getInfoRows().map((text, i) =>
<Component key={i} {...props}>{text}</Component>
); );
} }
}); });

View file

@ -20,7 +20,7 @@ import { definePluginSettings } 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 { findByProps, findStore } from "@webpack"; import { findByProps, findStore } from "@webpack";
import { FluxDispatcher, i18n } from "@webpack/common"; import { FluxDispatcher, i18n, useMemo } from "@webpack/common";
import FolderSideBar from "./FolderSideBar"; import FolderSideBar from "./FolderSideBar";
@ -117,8 +117,8 @@ export default definePlugin({
}, },
// If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders // If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders
{ {
match: /(useStateFromStoresArray\).{0,25}let \i)=(\i\.\i.getGuildsTree\(\))/, match: /\[(\i)\]=(\(0,\i\.useStateFromStoresArray\).{0,40}getGuildsTree\(\).+?}\))(?=,)/,
replace: (_, rest, guildsTree) => `${rest}=$self.getGuildTree(!!arguments[0].isBetterFolders,${guildsTree},arguments[0].betterFoldersExpandedIds)` replace: (_, originalTreeVar, rest) => `[betterFoldersOriginalTree]=${rest},${originalTreeVar}=$self.getGuildTree(!!arguments[0].isBetterFolders,betterFoldersOriginalTree,arguments[0].betterFoldersExpandedIds)`
}, },
// If we are rendering the Better Folders sidebar, we filter out everything but the servers and folders from the GuildsBar Guild List children // If we are rendering the Better Folders sidebar, we filter out everything but the servers and folders from the GuildsBar Guild List children
{ {
@ -252,19 +252,21 @@ export default definePlugin({
} }
}, },
getGuildTree(isBetterFolders: boolean, oldTree: any, expandedFolderIds?: Set<any>) { getGuildTree(isBetterFolders: boolean, originalTree: any, expandedFolderIds?: Set<any>) {
if (!isBetterFolders || expandedFolderIds == null) return oldTree; return useMemo(() => {
if (!isBetterFolders || expandedFolderIds == null) return originalTree;
const newTree = new GuildsTree(); const newTree = new GuildsTree();
// Children is every folder and guild which is not in a folder, this filters out only the expanded folders // Children is every folder and guild which is not in a folder, this filters out only the expanded folders
newTree.root.children = oldTree.root.children.filter(guildOrFolder => expandedFolderIds.has(guildOrFolder.id)); newTree.root.children = originalTree.root.children.filter(guildOrFolder => expandedFolderIds.has(guildOrFolder.id));
// Nodes is every folder and guild, even if it's in a folder, this filters out only the expanded folders and guilds inside them // Nodes is every folder and guild, even if it's in a folder, this filters out only the expanded folders and guilds inside them
newTree.nodes = Object.fromEntries( newTree.nodes = Object.fromEntries(
Object.entries(oldTree.nodes) Object.entries(originalTree.nodes)
.filter(([_, guildOrFolder]: any[]) => expandedFolderIds.has(guildOrFolder.id) || expandedFolderIds.has(guildOrFolder.parentId)) .filter(([_, guildOrFolder]: any[]) => expandedFolderIds.has(guildOrFolder.id) || expandedFolderIds.has(guildOrFolder.parentId))
); );
return newTree; return newTree;
}, [isBetterFolders, originalTree, expandedFolderIds]);
}, },
makeGuildsBarGuildListFilter(isBetterFolders: boolean) { makeGuildsBarGuildListFilter(isBetterFolders: boolean) {

View file

@ -120,7 +120,7 @@ export default definePlugin({
{ // Settings cog context menu { // Settings cog context menu
find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL", find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL",
replacement: { replacement: {
match: /\(0,\i.default\)\(\)(?=\.filter\(\i=>\{let\{section:\i\}=)/, match: /\(0,\i.useDefaultUserSettingsSections\)\(\)(?=\.filter\(\i=>\{let\{section:\i\}=)/,
replace: "$self.wrapMenu($&)" replace: "$self.wrapMenu($&)"
} }
} }

View file

@ -47,6 +47,7 @@ interface TagSettings {
MODERATOR_STAFF: TagSetting, MODERATOR_STAFF: TagSetting,
MODERATOR: TagSetting, MODERATOR: TagSetting,
VOICE_MODERATOR: TagSetting, VOICE_MODERATOR: TagSetting,
TRIAL_MODERATOR: TagSetting,
[k: string]: TagSetting; [k: string]: TagSetting;
} }
@ -91,6 +92,11 @@ const tags: Tag[] = [
displayName: "VC Mod", displayName: "VC Mod",
description: "Can manage voice chats", description: "Can manage voice chats",
permissions: ["MOVE_MEMBERS", "MUTE_MEMBERS", "DEAFEN_MEMBERS"] permissions: ["MOVE_MEMBERS", "MUTE_MEMBERS", "DEAFEN_MEMBERS"]
}, {
name: "CHAT_MODERATOR",
displayName: "Chat Mod",
description: "Can timeout people",
permissions: ["MODERATE_MEMBERS"]
} }
]; ];
const defaultSettings = Object.fromEntries( const defaultSettings = Object.fromEntries(
@ -261,34 +267,14 @@ export default definePlugin({
], ],
start() { start() {
if (settings.store.tagSettings) return; settings.store.tagSettings ??= defaultSettings;
// @ts-ignore
if (!settings.store.visibility_WEBHOOK) settings.store.tagSettings = defaultSettings; // newly added field might be missing from old users
else { settings.store.tagSettings.CHAT_MODERATOR ??= {
const newSettings = { ...defaultSettings }; text: "Chat Mod",
Object.entries(Vencord.PlainSettings.plugins.MoreUserTags).forEach(([name, value]) => { showInChat: true,
const [setting, tag] = name.split("_"); showInNotChat: true
if (setting === "visibility") { };
switch (value) {
case "always":
// its the default
break;
case "chat":
newSettings[tag].showInNotChat = false;
break;
case "not-chat":
newSettings[tag].showInChat = false;
break;
case "never":
newSettings[tag].showInChat = false;
newSettings[tag].showInNotChat = false;
break;
}
}
settings.store.tagSettings = newSettings;
delete Vencord.Settings.plugins.MoreUserTags[name];
});
}
}, },
getPermissions(user: User, channel: Channel): string[] { getPermissions(user: User, channel: Channel): string[] {

View file

@ -26,10 +26,12 @@ export default definePlugin({
description: "Adds Startup Timings to the Settings menu", description: "Adds Startup Timings to the Settings menu",
authors: [Devs.Megu], authors: [Devs.Megu],
patches: [{ patches: [{
find: "UserSettingsSections.PAYMENT_FLOW_MODAL_TEST_PAGE,", find: "Messages.ACTIVITY_SETTINGS",
replacement: { replacement: {
match: /{section:\i\.UserSettingsSections\.PAYMENT_FLOW_MODAL_TEST_PAGE/, match: /(?<=}\)([,;])(\i\.settings)\.forEach.+?(\i)\.push.+}\))/,
replace: '{section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage},$&' replace: (_, commaOrSemi, settings, elements) => "" +
`${commaOrSemi}${settings}?.[0]==="CHANGELOG"` +
`&&${elements}.push({section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage})`
} }
}], }],
StartupTimingPage StartupTimingPage