Fix CustomUserColors
Some checks failed
Release / Build Equicord (push) Has been cancelled
Test / Test (push) Has been cancelled

This commit is contained in:
thororen1234 2025-06-17 17:09:14 -04:00
parent 0741086dc2
commit ee16f4b8d8
No known key found for this signature in database

View file

@ -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 (!userId) return;
if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return; if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return;
if (withHash) return `#${colors[userId]}`; if (withHash) return `#${colors[userId]}`;
@ -96,9 +96,8 @@ export default definePlugin({
find: '="SYSTEM_TAG"', find: '="SYSTEM_TAG"',
replacement: { replacement: {
// Override colorString with our custom color and disable gradients if applying the custom color. // Override colorString with our custom color and disable gradients if applying the custom color.
match: /useContext\(\i\.\i\),(?<=colorString:(\i).+?(\i)=.+?)/, match: /(?<=colorString:\i,colorStrings:\i,colorRoleName:\i}=)(\i),/,
replace: (m, colorString, hasGradientColors) => `${m}` + replace: "$self.wrapMessageColorProps($1, arguments[0]),"
`vcCustomUserColorsDummy=[${colorString},${hasGradientColors}]=$self.getMessageColorsVariables(arguments[0],${hasGradientColors}),`
}, },
predicate: () => !Settings.plugins.IrcColors.enabled predicate: () => !Settings.plugins.IrcColors.enabled
}, },
@ -133,11 +132,26 @@ export default definePlugin({
}, },
], ],
getMessageColorsVariables(context: any, hasGradientColors: boolean) { wrapMessageColorProps(colorProps: { colorString: string, colorStrings?: Record<"primaryColor" | "secondaryColor" | "tertiaryColor", string>; }, context: any) {
try {
const colorString = this.colorIfServer(context); const colorString = this.colorIfServer(context);
const originalColorString = context?.author?.colorString; 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 { colorDMList(context: any): string | undefined {
@ -150,6 +164,8 @@ export default definePlugin({
const userId = context?.message?.author?.id; const userId = context?.message?.author?.id;
const colorString = context?.author?.colorString; 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; if (context?.channel?.guild_id && !settings.store.colorInServers) return colorString;
const color = getCustomColorString(userId, true); const color = getCustomColorString(userId, true);