From 054e2a020883db0aa8e4ce5fbed5b108779c1be1 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Thu, 6 Mar 2025 16:47:46 -0500 Subject: [PATCH] CustomUserColors: Use Usernames Now (Fix DM Colors) --- .../customUserColors/SetColorModal.tsx | 8 +++--- .../customUserColors/index.tsx | 28 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/equicordplugins/customUserColors/SetColorModal.tsx b/src/equicordplugins/customUserColors/SetColorModal.tsx index bdb36d6a..830d1e22 100644 --- a/src/equicordplugins/customUserColors/SetColorModal.tsx +++ b/src/equicordplugins/customUserColors/SetColorModal.tsx @@ -23,8 +23,8 @@ const ColorPicker = findComponentByCodeLazy("#{intl::USER_SETT const cl = classNameFactory("vc-customColors-"); -export function SetColorModal({ userId, modalProps }: { userId: string, modalProps: ModalProps; }) { - const initialColor = parseInt(colors[userId], 16) || 372735; +export function SetColorModal({ username, modalProps }: { username: string, modalProps: ModalProps; }) { + const initialColor = parseInt(colors[username], 16) || 372735; // color picker default to current color set for user (if null it's 0x05afff :3 ) const [colorPickerColor, setColorPickerColor] = useState(initialColor); @@ -41,13 +41,13 @@ export function SetColorModal({ userId, modalProps }: { userId: string, modalPro } async function saveUserColor() { - colors[userId] = colorPickerColor.toString(16).padStart(6, "0"); + colors[username] = colorPickerColor.toString(16).padStart(6, "0"); await set(DATASTORE_KEY, colors); modalProps.onClose(); } async function deleteUserColor() { - delete colors[userId]; + delete colors[username]; await set(DATASTORE_KEY, colors); modalProps.onClose(); } diff --git a/src/equicordplugins/customUserColors/index.tsx b/src/equicordplugins/customUserColors/index.tsx index 1136829d..0db522ae 100644 --- a/src/equicordplugins/customUserColors/index.tsx +++ b/src/equicordplugins/customUserColors/index.tsx @@ -29,7 +29,7 @@ export let colors: Record = {}; const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}(\i\.\i\("?.+?"?\).*?).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/); const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { user: User; }) => { - if (user?.id == null) return; + if (user?.username == null) return; const setCustomColorItem = ( { await requireSettingsMenu(); - openModal(modalProps => ); + openModal(modalProps => ); }} /> ); @@ -46,14 +46,14 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { }; -export function getCustomColorString(userId: string, withHash?: boolean): string | undefined { - if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) +export function getCustomColorString(username: string, withHash?: boolean): string | undefined { + if (!colors[username] || !Settings.plugins.CustomUserColors.enabled) return; if (withHash) - return `#${colors[userId]}`; + return `#${colors[username]}`; - return colors[userId]; + return colors[username]; } const settings = definePluginSettings({ @@ -94,16 +94,20 @@ export default definePlugin({ predicate: () => settings.store.dmList, find: "!1,wrapContent", replacement: { - match: /(nameAndDecorators,)/, - replace: "$1style:{color:$self.colorDMList(arguments[0])}," + match: /(?<=\}=(\i).*?nameAndDecorators,)/, + replace: "style:{color:$self.colorDMList($1)}," }, }, ], colorDMList(a: any): string | undefined { - const userId = a?.subText?.props?.user?.id; - if (!userId) return; - const colorString = getCustomColorString(userId, true); + const username = + typeof a?.name?.props?.children === "string" + ? a.name.props.children + : a?.name?.props?.children?.props?.children?.[0] + ?? null; + if (!username) return; + const colorString = getCustomColorString(username, true); if (colorString) return colorString; return "inherit"; }, @@ -113,7 +117,7 @@ export default definePlugin({ if (a?.channel?.guild_id && !settings.store.colorInServers) return roleColor; - const color = getCustomColorString(a.message.author.id, true); + const color = getCustomColorString(a.message.author.username, true); return color ?? roleColor ?? undefined; } });