CustomUserColors: GDM Support & Server Name Fix

This commit is contained in:
thororen1234 2025-09-11 09:46:41 -04:00
parent 00340d6b09
commit bea01f87e7
No known key found for this signature in database
3 changed files with 45 additions and 22 deletions

View file

@ -14,8 +14,8 @@ import { colors, DATASTORE_KEY } from "./index";
const cl = classNameFactory("vc-customColors-");
export function SetColorModal({ userId, modalProps }: { userId: string, modalProps: ModalProps; }) {
const initialColor = parseInt(colors[userId], 16) || 372735;
export function SetColorModal({ id, modalProps }: { id: string, modalProps: ModalProps; }) {
const initialColor = parseInt(colors[id], 16) || 372735;
// color picker default to current color set for user (if null it's 0x05afff :3 )
const [colorPickerColor, setColorPickerColor] = useState(initialColor);
@ -32,13 +32,13 @@ export function SetColorModal({ userId, modalProps }: { userId: string, modalPro
}
async function saveUserColor() {
colors[userId] = colorPickerColor.toString(16).padStart(6, "0");
colors[id] = colorPickerColor.toString(16).padStart(6, "0");
await set(DATASTORE_KEY, colors);
modalProps.onClose();
}
async function deleteUserColor() {
delete colors[userId];
delete colors[id];
await set(DATASTORE_KEY, colors);
modalProps.onClose();
}

View file

@ -12,9 +12,9 @@ import { definePluginSettings, Settings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
import { openModal } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types";
import { User } from "@vencord/discord-types";
import { Channel, User } from "@vencord/discord-types";
import { extractAndLoadChunksLazy } from "@webpack";
import { Menu } from "@webpack/common";
import { ChannelStore, Menu, SelectedChannelStore } from "@webpack/common";
import { SetColorModal } from "./SetColorModal";
@ -52,20 +52,37 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: {
icon={ColorIcon}
action={async () => {
await requireSettingsMenu();
openModal(modalProps => <SetColorModal userId={user.id} modalProps={modalProps} />);
openModal(modalProps => <SetColorModal id={user.id} modalProps={modalProps} />);
}}
/>
);
children.push(<Menu.MenuSeparator />, setCustomColorItem);
};
export function getCustomColorString(userId: string | undefined, withHash?: boolean): string | undefined {
if (!userId) return;
if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return;
if (withHash) return `#${colors[userId]}`;
return colors[userId];
const channelContextMenuPatch: NavContextMenuPatchCallback = (children, { channel }: { channel: Channel; }) => {
if (channel?.id == null) return;
const setCustomColorItem = (
<Menu.MenuItem
label="Set Color"
id="set-color"
icon={ColorIcon}
action={async () => {
await requireSettingsMenu();
openModal(modalProps => <SetColorModal id={channel.id} modalProps={modalProps} />);
}}
/>
);
children.push(<Menu.MenuSeparator />, setCustomColorItem);
};
export function getCustomColorString(id: string | undefined, withHash?: boolean): string | undefined {
if (!id) return;
if (!colors[id] || !Settings.plugins.CustomUserColors.enabled) return;
if (withHash) return `#${colors[id]}`;
return colors[id];
}
const settings = definePluginSettings({
@ -85,7 +102,10 @@ export default definePlugin({
name: "CustomUserColors",
description: "Lets you add a custom color to any user, anywhere! Highly recommend to use with typingTweaks and roleColorEverywhere",
authors: [EquicordDevs.mochienya],
contextMenus: { "user-context": userContextMenuPatch },
contextMenus: {
"user-context": userContextMenuPatch,
"gdm-context": channelContextMenuPatch,
},
settings,
requireSettingsMenu,
getCustomColorString,
@ -135,10 +155,12 @@ export default definePlugin({
wrapMessageColorProps(colorProps: { colorString: string, colorStrings?: Record<"primaryColor" | "secondaryColor" | "tertiaryColor", string>; }, context: any) {
try {
const channelId = SelectedChannelStore.getChannelId();
const channel = ChannelStore.getChannel(channelId);
const isDM = channel.isDM() || channel.isMultiUserDM();
const colorString = this.colorIfServer(context);
if (colorString === colorProps.colorString) {
return colorProps;
}
if (colorString === colorProps.colorString) return colorProps;
if (!settings.store.colorInServers && !isDM) return colorProps;
return {
...colorProps,
@ -156,8 +178,9 @@ export default definePlugin({
},
colorDMList(context: any): string | undefined {
const userId = context?.user?.id;
const colorString = getCustomColorString(userId, true);
const id = context?.user?.id ?? context?.channel?.id;
const colorString = getCustomColorString(id, true);
return colorString ?? "inherit";
},

View file

@ -142,10 +142,10 @@ export default definePlugin({
]
},
{
find: "profileCardUsernameRow,children",
find: "profileCardUsernameRow,children:",
replacement: {
match: /(?<=displayProfile:(\i).+?badges:)(\i)/,
replace: "[...$self.getBadges($1),...$2]"
match: /badges:(\i)(?<=displayProfile:(\i).+?)/,
replace: "badges:[...$self.getBadges($2),...$1]"
}
}
],