sajidfjiasdjiodjioasjiod

This commit is contained in:
Vendicated 2024-07-02 00:17:40 +02:00
parent 77492061f5
commit c73c3fa636
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
3 changed files with 181 additions and 0 deletions

View file

@ -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<string, UserOverride>;
}>();
export const getUserOverride = (userId: string) => settings.store.users?.[userId] ?? emptyConstantOverride;
export const hasFlag = (field: OverrideFlags, flag: OverrideFlags) => (field & flag) === flag;

View file

@ -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(
<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: /(?<=:)\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);
}
});

View file

@ -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 => (
<ModalRoot {...props}>
<ModalHeader>
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>Notification Log</Text>
<ModalCloseButton onClick={props.onClose} />
</ModalHeader>
<ModalContent>
<EditModal user={user} />
</ModalContent>
<ModalFooter>
<Flex>
<Button
color={Button.Colors.RED}
>
Reset Settings
</Button>
<Button>
Save
</Button>
</Flex>
</ModalFooter>
</ModalRoot>
));
}