Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/plugins/ircColors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { definePluginSettings } from "@api/Settings";
import { hash as h64 } from "@intrnl/xxhash64";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { useMemo } from "@webpack/common";
import { useMemo, UserStore } from "@webpack/common";

// Calculate a CSS color string based on the user ID
function calculateNameColorForUser(id?: string) {
Expand Down Expand Up @@ -117,9 +117,24 @@ 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 < 90) {
const newColor = (otherUserColor + 180) % 360;
return `hsl(${newColor}, 100%, ${settings.store.lightness}%)`;
}
}
}
return dmColor;
},

calculateNameColorForListContext(context: any) {
Expand All @@ -140,3 +155,4 @@ export default definePlugin({
}
}
});

4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "alfred",
id: 1038466644353232967n
},
Moga: {
name: "Moga",
id: 1204195565685051408n
},
vv: {
name: "VV",
id: 254866377087778816n
Expand Down