From c73c3fa6360ee2c929d2dfe0c2709a4768dee9f4 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 2 Jul 2024 00:17:40 +0200 Subject: [PATCH] sajidfjiasdjiodjioasjiod --- src/plugins/editUsers/data.ts | 43 +++++++++++++++ src/plugins/editUsers/index.tsx | 95 +++++++++++++++++++++++++++++++++ src/plugins/editUsers/modal.tsx | 43 +++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 src/plugins/editUsers/data.ts create mode 100644 src/plugins/editUsers/index.tsx create mode 100644 src/plugins/editUsers/modal.tsx diff --git a/src/plugins/editUsers/data.ts b/src/plugins/editUsers/data.ts new file mode 100644 index 000000000..e70c68cb6 --- /dev/null +++ b/src/plugins/editUsers/data.ts @@ -0,0 +1,43 @@ +/* + * 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 | null; + bannerUrl: string | null; + flags: OverrideFlags; +} + +export function makeBlankUserOverride(): UserOverride { + return { + username: "", + avatarUrl: "", + bannerUrl: "", + flags: OverrideFlags.None, + }; +} + +const emptyConstantOverride = makeBlankUserOverride(); + +export const settings = definePluginSettings({}) + .withPrivateSettings<{ + users?: Record; + }>(); + +export const getUserOverride = (userId: string) => settings.store.users?.[userId] ?? emptyConstantOverride; +export const hasFlag = (field: OverrideFlags, flag: OverrideFlags) => (field & flag) === flag; diff --git a/src/plugins/editUsers/index.tsx b/src/plugins/editUsers/index.tsx new file mode 100644 index 000000000..ad998f610 --- /dev/null +++ b/src/plugins/editUsers/index.tsx @@ -0,0 +1,95 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +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( + 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: /(?<=:)\i\.\i\.getUserAvatarURL\(this/, + replace: "$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)||$&" + } + ] + } + ], + + getUsername: (user: User) => getUserOverride(user.id).username, + getAvatarUrl: (user: User) => getUserOverride(user.id).avatarUrl, + getBannerUrl: (userId: string) => getUserOverride(userId).bannerUrl, + + 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); + } +}); diff --git a/src/plugins/editUsers/modal.tsx b/src/plugins/editUsers/modal.tsx new file mode 100644 index 000000000..bb5d91918 --- /dev/null +++ b/src/plugins/editUsers/modal.tsx @@ -0,0 +1,43 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Flex } from "@components/Flex"; +import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, openModal } from "@utils/modal"; +import { Button, Text } from "@webpack/common"; +import { User } from "discord-types/general"; + +function EditModal({ user }: { user: User; }) { + // TODO trolley + return null; +} + +export function openUserEditModal(user) { + openModal(props => ( + + + Notification Log + + + + + + + + + + + + + + + )); +}