Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EditUsers #2657

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/VencordSettings/ThemesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { useSettings } from "@api/Settings";
import { Settings, useSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles";
import { Flex } from "@components/Flex";
import { DeleteIcon, FolderIcon, PaintbrushIcon, PencilIcon, PlusIcon, RestartIcon } from "@components/Icons";
Expand All @@ -32,6 +32,8 @@ import { findByPropsLazy, findLazy } from "@webpack";
import { Card, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common";
import type { ComponentType, Ref, SyntheticEvent } from "react";

import Plugins from "~plugins";

import { AddonCard } from "./AddonCard";
import { QuickAction, QuickActionCard } from "./quickActions";
import { SettingsTab, wrapTab } from "./shared";
Expand Down Expand Up @@ -250,10 +252,10 @@ function ThemesTab() {
Icon={PaintbrushIcon}
/>

{Vencord.Settings.plugins.ClientTheme.enabled && (
{Settings.plugins.ClientTheme.enabled && (
<QuickAction
text="Edit ClientTheme"
action={() => openPluginModal(Vencord.Plugins.plugins.ClientTheme)}
action={() => openPluginModal(Plugins.ClientTheme)}
Icon={PencilIcon}
/>
)}
Expand Down
22 changes: 14 additions & 8 deletions src/plugins/banger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";

const settings = definePluginSettings({
source: {
description: "Source to replace ban GIF with (Video or Gif)",
type: OptionType.STRING,
default: "https://i.imgur.com/wp5q52C.mp4",
restartNeeded: true,
}
});

export default definePlugin({
name: "BANger",
description: "Replaces the GIF in the ban dialogue with a custom one.",
authors: [Devs.Xinto, Devs.Glitch],
settings,
patches: [
{
find: "BAN_CONFIRM_TITLE.",
replacement: {
match: /src:\i\("?\d+"?\)/g,
replace: "src: Vencord.Settings.plugins.BANger.source"
replace: "src:$self.source"
}
}
],
options: {
source: {
description: "Source to replace ban GIF with (Video or Gif)",
type: OptionType.STRING,
default: "https://i.imgur.com/wp5q52C.mp4",
restartNeeded: true,
}
get source() {
return settings.store.source;
}
});
43 changes: 24 additions & 19 deletions src/plugins/betterNotes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Settings } from "@api/Settings";
import { definePluginSettings, Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { canonicalizeMatch } from "@utils/patches";
Expand All @@ -25,18 +25,34 @@ import { findByPropsLazy } from "@webpack";

const UserPopoutSectionCssClasses = findByPropsLazy("section", "lastSection");

const settings = definePluginSettings({
hide: {
type: OptionType.BOOLEAN,
description: "Hide notes",
default: false,
restartNeeded: true
},
noSpellCheck: {
type: OptionType.BOOLEAN,
description: "Disable spellcheck in notes",
disabled: () => Settings.plugins.BetterNotesBox.hide,
default: false
}
});

export default definePlugin({
name: "BetterNotesBox",
description: "Hide notes or disable spellcheck (Configure in settings!!)",
authors: [Devs.Ven],
settings,

patches: [
{
find: "hideNote:",
all: true,
// Some modules match the find but the replacement is returned untouched
noWarn: true,
predicate: () => Vencord.Settings.plugins.BetterNotesBox.hide,
predicate: () => settings.store.hide,
replacement: {
match: /hideNote:.+?(?=([,}].*?\)))/g,
replace: (m, rest) => {
Expand All @@ -54,7 +70,7 @@ export default definePlugin({
find: "Messages.NOTE_PLACEHOLDER",
replacement: {
match: /\.NOTE_PLACEHOLDER,/,
replace: "$&spellCheck:!Vencord.Settings.plugins.BetterNotesBox.noSpellCheck,"
replace: "$&spellCheck:!$self.noSpellCheck,"
}
},
{
Expand All @@ -66,25 +82,14 @@ export default definePlugin({
}
],

options: {
hide: {
type: OptionType.BOOLEAN,
description: "Hide notes",
default: false,
restartNeeded: true
},
noSpellCheck: {
type: OptionType.BOOLEAN,
description: "Disable spellcheck in notes",
disabled: () => Settings.plugins.BetterNotesBox.hide,
default: false
}
},

patchPadding: ErrorBoundary.wrap(({ lastSection }) => {
if (!lastSection) return null;
return (
<div className={UserPopoutSectionCssClasses.lastSection} ></div>
);
})
}),

get noSpellCheck() {
return settings.store.noSpellCheck;
}
});
42 changes: 42 additions & 0 deletions src/plugins/editUsers/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { definePluginSettings } from "@api/Settings";

export const enum OverrideFlags {
None = 0,
PreferServerNicks = 1 << 0,
DisableNicks = 1 << 1,
KeepServerAvatar = 1 << 2,
DisableServerAvatars = 1 << 3,
KeepServerBanner = 1 << 4,
DisableServerBanners = 1 << 5,
}

export interface UserOverride {
username: string;
avatarUrl: string;
bannerUrl: string;
pronouns: string;
flags: OverrideFlags;
}

export const emptyOverride: UserOverride = Object.freeze({
username: "",
avatarUrl: "",
bannerUrl: "",
pronouns: "",
flags: OverrideFlags.None,
});

export const settings = definePluginSettings({})
.withPrivateSettings<{
users?: Record<string, UserOverride>;
}>();

export const getUserOverride = (userId: string) => settings.store.users?.[userId] ?? emptyOverride;

export const hasFlag = (field: OverrideFlags, flag: OverrideFlags) => (field & flag) === flag;
125 changes: 125 additions & 0 deletions src/plugins/editUsers/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import "./styles.css";

import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { Menu } from "@webpack/common";
import { User } from "discord-types/general";

import { getUserOverride, hasFlag, OverrideFlags, settings } from "./data";
import { openUserEditModal } from "./modal";

export default definePlugin({
name: "EditUsers",
description: "Edit users",
authors: [Devs.Ven],

settings,

contextMenus: {
"user-context"(children, { user }: { user?: User; }) {
if (!user) return;

children.push(
<Menu.MenuItem
id="vc-edit-user"
label="Edit User"
action={() => openUserEditModal(user)}
/>
);
}
},

patches: [
{
find: ",getUserTag:",
replacement: {
match: /if\(\i\((\i)\.global_name\)\)return(?=.{0,100}return"\?\?\?")/,
replace: "const vcEuName=$self.getUsername($1);if(vcEuName)return vcEuName;$&"
}
},
{
find: "=this.guildMemberAvatars[",
replacement: [
{
match: /&&null!=this\.guildMemberAvatars\[\i\]/,
replace: "$& && !$self.shouldIgnoreGuildAvatar(this)"
},
{
match: /(?<=null!=(\i))\?(\i\.\i\.getGuildMemberAvatarURLSimple.+?):(?=\i\.\i\.getUserAvatarURL\(this)/,
replace: "&& this.hasAvatarForGuild?.($1) ? $2 : $self.getAvatarUrl(this)||"
}
]
},
{
find: "this.isUsingGuildMemberBanner()",
replacement: [
{
match: /:\i\.banner\)!=null/,
replace: "$& && !$self.shouldIgnoreGuildBanner(this.userId)"
},
{
match: /(?<=:).{0,10}\(\{id:this\.userId,banner/,
replace: "$self.getBannerUrl(this.userId)||$&"
},
{
match: /isUsingGuildMemberPronouns\(\)\{/,
replace:
"set pronouns(v){this._vcPronouns=v}" +
"get pronouns(){return $self.getPronouns(this.userId)||this._vcPronouns}" +
"isUsingGuildMemberPronouns(){"
},
{
match: /\i\(this,"pronouns",void 0\),/,
replace: ""
}
]
},
{
find: '"GuildMemberStore"',
replacement: {
match: /getNick\(\i,(\i)\)\{/,
replace: "$& if ($self.shouldIgnoreNick($1)) return null;"
}
}
],

getUsername: (user: User) => getUserOverride(user.id).username,
getAvatarUrl: (user: User) => getUserOverride(user.id).avatarUrl,
getBannerUrl: (userId: string) => getUserOverride(userId).bannerUrl,
getPronouns: (userId: string) => getUserOverride(userId).pronouns,

shouldIgnoreGuildAvatar(user: User) {
const { avatarUrl, flags } = getUserOverride(user.id);

if (avatarUrl && !hasFlag(flags, OverrideFlags.KeepServerAvatar))
return true;

return hasFlag(flags, OverrideFlags.DisableServerAvatars);
},

shouldIgnoreGuildBanner(userId: string) {
const { bannerUrl, flags } = getUserOverride(userId);

if (bannerUrl && !hasFlag(flags, OverrideFlags.KeepServerBanner))
return true;

return hasFlag(flags, OverrideFlags.DisableServerBanners);
},

shouldIgnoreNick(userId?: string) {
if (!userId) return false;

const { username, flags } = getUserOverride(userId);

if (username && !hasFlag(flags, OverrideFlags.PreferServerNicks))
return true;

return hasFlag(flags, OverrideFlags.DisableNicks);
}
});
Loading