-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Vendicated
wants to merge
9
commits into
dev
Choose a base branch
from
edit-users
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
EditUsers #2657
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c73c3fa
sajidfjiasdjiodjioasjiod
Vendicated e0bb9bf
add ui and stuffs
Vendicated b333deb
improve settings ui (again)
Vendicated 1bdde74
Merge branch 'dev' into edit-users
Vendicated 1a2033e
Merge branch 'dev' into edit-users
Vendicated 3a74996
add pronouns, add nicks (kinda)
Vendicated f4572d0
fix overriding avatars in guilds
Vendicated 560fb98
BetterNotes: fix crashing
Vendicated 0a51a86
Merge branch 'dev' into edit-users
Vendicated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2024 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import { classNameFactory } from "@api/Styles"; | ||
import { Flex } from "@components/Flex"; | ||
import { Margins } from "@utils/margins"; | ||
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; | ||
import { Button, DisplayProfileUtils, showToast, Switch, TabBar, Text, TextInput, Toasts, UsernameUtils, useState } from "@webpack/common"; | ||
import { User } from "discord-types/general"; | ||
import type { Dispatch, SetStateAction } from "react"; | ||
|
||
import { emptyOverride, hasFlag, OverrideFlags, settings, UserOverride } from "./data"; | ||
|
||
const cl = classNameFactory("vc-editUsers-"); | ||
|
||
interface OverrideProps { | ||
override: UserOverride; | ||
setOverride: Dispatch<SetStateAction<UserOverride>>; | ||
} | ||
|
||
interface SettingsRowProps extends OverrideProps { | ||
overrideKey: keyof Omit<UserOverride, "flags">; | ||
name: string; | ||
flagDisable: OverrideFlags; | ||
flagPrefer: OverrideFlags; | ||
placeholder: string; | ||
} | ||
|
||
function SettingsRow(props: SettingsRowProps) { | ||
const { name, override, setOverride, overrideKey, placeholder, flagDisable, flagPrefer } = props; | ||
const namePlural = name + "s"; | ||
const { flags } = override; | ||
|
||
const toggleFlag = (on: boolean, flag: OverrideFlags) => | ||
on | ||
? flags | flag | ||
: flags & ~flag; | ||
|
||
return ( | ||
<> | ||
<TextInput | ||
className={Margins.bottom16} | ||
value={override[overrideKey]} | ||
onChange={v => setOverride(o => ({ ...o, [overrideKey]: v }))} | ||
placeholder={placeholder} | ||
autoFocus | ||
/> | ||
<Switch | ||
value={hasFlag(flags, flagDisable)} | ||
onChange={v => setOverride(o => ({ ...o, flags: toggleFlag(v, flagDisable) }))} | ||
note={`Will use the user's global ${name} (or your EditUser configured ${name}) over server specific ${namePlural}`} | ||
> | ||
Disable server specific {namePlural} | ||
</Switch> | ||
<Switch | ||
value={hasFlag(flags, flagPrefer)} | ||
onChange={v => setOverride(o => ({ ...o, flags: toggleFlag(v, flagPrefer) }))} | ||
note={`Will use server specific ${namePlural} over the EditUser configured ${name}`} | ||
hideBorder | ||
> | ||
Prefer server specific {namePlural} | ||
</Switch> | ||
</> | ||
); | ||
} | ||
|
||
const Tabs = { | ||
username: { | ||
name: "Username", | ||
flagDisable: OverrideFlags.DisableNicks, | ||
flagPrefer: OverrideFlags.PreferServerNicks, | ||
placeholder: (user: User) => UsernameUtils.getName(user), | ||
}, | ||
avatarUrl: { | ||
name: "Avatar", | ||
flagDisable: OverrideFlags.DisableServerAvatars, | ||
flagPrefer: OverrideFlags.KeepServerAvatar, | ||
placeholder: (user: User) => user.getAvatarURL(), | ||
}, | ||
bannerUrl: { | ||
name: "Banner", | ||
flagDisable: OverrideFlags.DisableServerBanners, | ||
flagPrefer: OverrideFlags.KeepServerBanner, | ||
placeholder: (user: User) => DisplayProfileUtils.getDisplayProfile(user.id)?.getBannerURL({ canAnimate: true, size: 64 }) ?? "", | ||
}, | ||
} as const; | ||
const TabKeys = Object.keys(Tabs) as (keyof typeof Tabs)[]; | ||
|
||
function EditTabs({ user, override, setOverride }: { user: User; } & OverrideProps) { | ||
const [currentTabName, setCurrentTabName] = useState(TabKeys[0]); | ||
|
||
const currentTab = Tabs[currentTabName]; | ||
|
||
return ( | ||
<> | ||
<TabBar | ||
type="top" | ||
look="brand" | ||
className={cl("tabBar")} | ||
selectedItem={currentTabName} | ||
onItemSelect={setCurrentTabName} | ||
> | ||
{TabKeys.map(key => ( | ||
<TabBar.Item | ||
id={key} | ||
key={key} | ||
className={cl("tab")} | ||
> | ||
{Tabs[key].name} | ||
</TabBar.Item> | ||
))} | ||
</TabBar> | ||
|
||
<SettingsRow | ||
{...currentTab} | ||
override={override} | ||
overrideKey={currentTabName} | ||
setOverride={setOverride} | ||
placeholder={currentTab.placeholder(user)} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
function EditModal({ user, modalProps }: { user: User; modalProps: ModalProps; }) { | ||
const [override, setOverride] = useState(() => ({ ...settings.store.users?.[user.id] ?? emptyOverride })); | ||
|
||
return ( | ||
<ModalRoot {...modalProps} size={ModalSize.MEDIUM}> | ||
<ModalHeader> | ||
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>Edit User {user.username}</Text> | ||
<ModalCloseButton onClick={modalProps.onClose} /> | ||
</ModalHeader> | ||
|
||
<ModalContent> | ||
<div className={cl("modal")}> | ||
<EditTabs user={user} override={override} setOverride={setOverride} /> | ||
</div> | ||
</ModalContent> | ||
|
||
<ModalFooter> | ||
<Flex> | ||
<Button | ||
color={Button.Colors.RED} | ||
onClick={() => setOverride({ ...emptyOverride })} | ||
> | ||
Reset All | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
const s = settings.store.users ??= {}; | ||
s[user.id] = override; | ||
modalProps.onClose(); | ||
showToast("Saved! Switch chats for changes to apply everywhere", Toasts.Type.SUCCESS, { position: Toasts.Position.BOTTOM }); | ||
}} | ||
> | ||
Save | ||
</Button> | ||
</Flex> | ||
</ModalFooter> | ||
</ModalRoot> | ||
); | ||
} | ||
|
||
export function openUserEditModal(user: User) { | ||
openModal(props => <EditModal user={user} modalProps={props} />); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.vc-editUsers-modal { | ||
padding: 1em 0; | ||
} | ||
|
||
.vc-editUsers-tabBar { | ||
gap: 1em; | ||
margin-bottom: 16px; | ||
border-bottom: 2px solid var(--background-modifier-accent); | ||
} | ||
|
||
.vc-editUsers-tab { | ||
padding-bottom: 8px; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leaving this here despite this being a draft;
Any chance you could include an option to use a colour picker for the banner?