From 87bcf6231ecadd4719b7ac2a7147463f9d789cd2 Mon Sep 17 00:00:00 2001 From: fckyough Date: Tue, 14 Apr 2026 09:44:31 +0800 Subject: [PATCH] fix irc colors for dms (#971) * fix irc colors for dms minimum difference if the colors are 45 deg or less apart * Update .gitignore * Update .gitignore * 1000 miles --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> Co-authored-by: creations --- src/plugins/ircColors/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugins/ircColors/index.ts b/src/plugins/ircColors/index.ts index bd3b72e8b..66bc716ac 100644 --- a/src/plugins/ircColors/index.ts +++ b/src/plugins/ircColors/index.ts @@ -22,6 +22,7 @@ import { hash as h64 } from "@intrnl/xxhash64"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { useMemo } from "@webpack/common"; +import { UserStore } from "@webpack/common"; // Calculate a CSS color string based on the user ID function calculateNameColorForUser(id?: string) { @@ -121,9 +122,25 @@ export default definePlugin({ return colorString; } - return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) + const dmColor = (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) ? color : colorString; + + // guarantee minimum difference in dms + if (context?.channel?.isPrivate?.() && dmColor && userId) { + const currentUserId = UserStore.getCurrentUser()?.id; + if (currentUserId && userId !== currentUserId) { + const currentUserColor = Number(h64(currentUserId) % 360n); + const otherUserColor = Number(h64(userId) % 360n); + const colorDiff = Math.min(Math.abs(currentUserColor - otherUserColor), 360 - Math.abs(currentUserColor - otherUserColor)); + if (colorDiff < 45) { + const newColor = (otherUserColor + 180) % 360; + return `hsl(${newColor}, 100%, ${settings.store.lightness}%)`; + } + } + } + + return dmColor; }, calculateNameColorForListContext(context: any) {