Compare commits

...

12 commits

Author SHA1 Message Date
v
be30f0eb6e
Merge 0a51a865d3 into a015cf96f6 2024-09-19 18:37:14 +02:00
Nuckyz
a015cf96f6
UserVoiceShow: Fix setting name
Some checks are pending
Sync to Codeberg / codeberg (push) Waiting to run
test / test (push) Waiting to run
2024-09-19 13:33:32 -03:00
Vendicated
c7e5295da0
SearchReply => FullSearchContext ~ now adds all options back
Some checks are pending
Sync to Codeberg / codeberg (push) Waiting to run
test / test (push) Waiting to run
2024-09-18 21:33:46 +02:00
vee
0a51a865d3
Merge branch 'dev' into edit-users 2024-07-06 19:05:58 +02:00
Vendicated
560fb982e6
BetterNotes: fix crashing 2024-07-03 21:38:21 +02:00
Vendicated
f4572d0377
fix overriding avatars in guilds 2024-07-03 18:07:11 +02:00
Vendicated
3a7499644e
add pronouns, add nicks (kinda) 2024-07-03 17:24:29 +02:00
vee
1a2033e137
Merge branch 'dev' into edit-users 2024-07-03 16:49:17 +02:00
Vendicated
1bdde745e2
Merge branch 'dev' into edit-users 2024-07-02 22:10:35 +02:00
Vendicated
b333deb731
improve settings ui (again) 2024-07-02 18:51:51 +02:00
Vendicated
e0bb9bf77d
add ui and stuffs 2024-07-02 17:39:48 +02:00
Vendicated
c73c3fa636
sajidfjiasdjiodjioasjiod 2024-07-02 00:17:40 +02:00
11 changed files with 466 additions and 110 deletions

View file

@ -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;

View file

@ -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);
}
});

View file

@ -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} />);
}

View file

@ -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;
}

View file

@ -0,0 +1,5 @@
# FullSearchContext
Makes the message context menu in message search results have all options you'd expect.
![](https://github.com/user-attachments/assets/472d1327-3935-44c7-b7c4-0978b5348550)

View file

@ -0,0 +1,82 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { migratePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
import type { MouseEvent } from "react";
const { useMessageMenu } = findByPropsLazy("useMessageMenu");
function MessageMenu({ message, channel, onHeightUpdate }) {
const canReport = message.author &&
!(message.author.id === UserStore.getCurrentUser().id || message.author.system);
return useMessageMenu({
navId: "message-actions",
ariaLabel: i18n.Messages.MESSAGE_UTILITIES_A11Y_LABEL,
message,
channel,
canReport,
onHeightUpdate,
onClose: () => ContextMenuApi.closeContextMenu(),
textSelection: "",
favoriteableType: null,
favoriteableId: null,
favoriteableName: null,
itemHref: void 0,
itemSrc: void 0,
itemSafeSrc: void 0,
itemTextContent: void 0,
});
}
migratePluginSettings("FullSearchContext", "SearchReply");
export default definePlugin({
name: "FullSearchContext",
description: "Makes the message context menu in message search results have all options you'd expect",
authors: [Devs.Ven, Devs.Aria],
patches: [{
find: "onClick:this.handleMessageClick,",
replacement: {
match: /this(?=\.handleContextMenu\(\i,\i\))/,
replace: "$self"
}
}],
handleContextMenu(event: MouseEvent, message: Message) {
const channel = ChannelStore.getChannel(message.channel_id);
if (!channel) return;
event.stopPropagation();
ContextMenuApi.openContextMenu(event, contextMenuProps =>
<MessageMenu
message={message}
channel={channel}
onHeightUpdate={contextMenuProps.onHeightUpdate}
/>
);
}
});

View file

@ -1,6 +0,0 @@
# SearchReply
Adds a reply button to search results.
![the plugin in action](https://github.com/Vendicated/Vencord/assets/45497981/07e741d3-0f97-4e5c-82b0-80712ecf2cbb)

View file

@ -1,75 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { ReplyIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByCodeLazy } from "@webpack";
import { ChannelStore, i18n, Menu, PermissionsBits, PermissionStore, SelectedChannelStore } from "@webpack/common";
import { Message } from "discord-types/general";
const replyToMessage = findByCodeLazy(".TEXTAREA_FOCUS)", "showMentionToggle:");
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { message }: { message: Message; }) => {
// make sure the message is in the selected channel
if (SelectedChannelStore.getChannelId() !== message.channel_id) return;
const channel = ChannelStore.getChannel(message?.channel_id);
if (!channel) return;
if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
// dms and group chats
const dmGroup = findGroupChildrenByChildId("pin", children);
if (dmGroup && !dmGroup.some(child => child?.props?.id === "reply")) {
const pinIndex = dmGroup.findIndex(c => c?.props.id === "pin");
dmGroup.splice(pinIndex + 1, 0, (
<Menu.MenuItem
id="reply"
label={i18n.Messages.MESSAGE_ACTION_REPLY}
icon={ReplyIcon}
action={(e: React.MouseEvent) => replyToMessage(channel, message, e)}
/>
));
return;
}
// servers
const serverGroup = findGroupChildrenByChildId("mark-unread", children);
if (serverGroup && !serverGroup.some(child => child?.props?.id === "reply")) {
serverGroup.unshift((
<Menu.MenuItem
id="reply"
label={i18n.Messages.MESSAGE_ACTION_REPLY}
icon={ReplyIcon}
action={(e: React.MouseEvent) => replyToMessage(channel, message, e)}
/>
));
return;
}
};
export default definePlugin({
name: "SearchReply",
description: "Adds a reply button to search results",
authors: [Devs.Aria],
contextMenus: {
"message": messageContextMenuPatch
}
});

View file

@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common";
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common";
import { Channel } from "discord-types/general";
const cl = classNameFactory("vc-uvs-");
@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan
const VoiceStateStore = findStoreLazy("VoiceStateStore");
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
interface IconProps extends React.HTMLAttributes<HTMLDivElement> {
interface IconProps extends React.ComponentPropsWithoutRef<"div"> {
size?: number;
}
@ -71,23 +71,18 @@ interface VoiceChannelTooltipProps {
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
const users = useMemo(
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
[voiceStates]
);
const guild = useMemo(
() => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()),
[channel]
);
const guildIcon = useMemo(() => {
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
id: guild.id,
icon: guild.icon,
size: 30
});
}, [guild]);
const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId());
const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
id: guild.id,
icon: guild.icon,
size: 30
});
return (
<>
@ -103,7 +98,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
<UserSummaryItem
users={users}
renderIcon={false}
max={7}
max={13}
size={18}
/>
</div>
@ -119,11 +114,14 @@ const clickTimers = {} as Record<string, any>;
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
const onClick = useCallback((e: React.MouseEvent) => {
const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId);
if (channel == null) return null;
function onClick(e: React.MouseEvent) {
e.preventDefault();
e.stopPropagation();
if (channel == null || channelId == null) return;
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
@ -147,18 +145,15 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
delete clickTimers[channelId];
}, 250);
}
}, [channelId]);
}
const isLocked = useMemo(() => {
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
}, [channelId]);
if (channel == null) return null;
const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
return (
<Tooltip
text={<VoiceChannelTooltip channel={channel} />}
tooltipClassName={cl("tooltip-container")}
tooltipContentClassName={cl("tooltip-content")}
>
{props =>
isLocked ?

View file

@ -32,7 +32,7 @@ const settings = definePluginSettings({
default: true,
restartNeeded: true
},
showInVoiceMemberList: {
showInMemberList: {
type: OptionType.BOOLEAN,
description: "Show a user's Voice Channel indicator in the member and DMs list",
default: true,
@ -82,12 +82,12 @@ export default definePlugin({
match: /\.subtext,children:.+?}\)\]}\)(?=])/,
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
},
predicate: () => settings.store.showInVoiceMemberList
predicate: () => settings.store.showInMemberList
}
],
start() {
if (settings.store.showInVoiceMemberList) {
if (settings.store.showInMemberList) {
addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />);
}
},

View file

@ -15,7 +15,13 @@
}
.vc-uvs-tooltip-container {
max-width: 200px;
max-width: 300px;
}
.vc-uvs-tooltip-content {
display: flex;
flex-direction: column;
gap: 6px;
}
.vc-uvs-guild-name {
@ -31,7 +37,5 @@
.vc-uvs-vc-members {
display: flex;
margin: 8px 0;
flex-direction: row;
gap: 6px;
}