diff --git a/src/equicordplugins/customUserColors/index.tsx b/src/equicordplugins/customUserColors/index.tsx index c9dae89e..6ee2074b 100644 --- a/src/equicordplugins/customUserColors/index.tsx +++ b/src/equicordplugins/customUserColors/index.tsx @@ -61,7 +61,7 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { }; -export function getCustomColorString(userId: string, withHash?: boolean): string | undefined { +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]}`; @@ -96,9 +96,8 @@ export default definePlugin({ find: '="SYSTEM_TAG"', replacement: { // Override colorString with our custom color and disable gradients if applying the custom color. - match: /useContext\(\i\.\i\),(?<=colorString:(\i).+?(\i)=.+?)/, - replace: (m, colorString, hasGradientColors) => `${m}` + - `vcCustomUserColorsDummy=[${colorString},${hasGradientColors}]=$self.getMessageColorsVariables(arguments[0],${hasGradientColors}),` + match: /(?<=colorString:\i,colorStrings:\i,colorRoleName:\i}=)(\i),/, + replace: "$self.wrapMessageColorProps($1, arguments[0])," }, predicate: () => !Settings.plugins.IrcColors.enabled }, @@ -133,11 +132,26 @@ export default definePlugin({ }, ], - getMessageColorsVariables(context: any, hasGradientColors: boolean) { - const colorString = this.colorIfServer(context); - const originalColorString = context?.author?.colorString; + wrapMessageColorProps(colorProps: { colorString: string, colorStrings?: Record<"primaryColor" | "secondaryColor" | "tertiaryColor", string>; }, context: any) { + try { + const colorString = this.colorIfServer(context); + if (colorString === colorProps.colorString) { + return colorProps; + } - return [colorString, hasGradientColors && colorString === originalColorString]; + return { + ...colorProps, + colorString, + colorStrings: colorProps.colorStrings && { + primaryColor: colorString, + secondaryColor: undefined, + tertiaryColor: undefined + } + }; + } catch (e) { + console.error("Failed to calculate message color strings:", e); + return colorProps; + } }, colorDMList(context: any): string | undefined { @@ -150,6 +164,8 @@ export default definePlugin({ const userId = context?.message?.author?.id; const colorString = context?.author?.colorString; + if (context?.message?.channel_id === "1337" && userId === "313337") return colorString; + if (context?.channel?.guild_id && !settings.store.colorInServers) return colorString; const color = getCustomColorString(userId, true);