From 686a55270d007b2a6d245a34b17a91895261b5f9 Mon Sep 17 00:00:00 2001 From: Gir0fa Date: Wed, 6 May 2026 06:49:37 -0500 Subject: [PATCH] feat(CopyProfileColors): add server profile colors option (#1046) - Add 'Copy Server Profile Colors' context menu item when guild-specific theme colors exist - Use UserProfileStore.getGuildMemberProfile for guild-specific colors - Replace console.error with Logger - Add Gir0fa as contributor --- .../copyProfileColors/index.tsx | 44 ++++++++++++++----- src/utils/constants.ts | 4 ++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/equicordplugins/copyProfileColors/index.tsx b/src/equicordplugins/copyProfileColors/index.tsx index fb175839c..d6acd32e5 100644 --- a/src/equicordplugins/copyProfileColors/index.tsx +++ b/src/equicordplugins/copyProfileColors/index.tsx @@ -7,14 +7,20 @@ import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { copyToClipboard } from "@utils/clipboard"; import { EquicordDevs } from "@utils/constants"; +import { Logger } from "@utils/Logger"; import definePlugin from "@utils/types"; -import { Menu, Toasts, UserProfileStore } from "@webpack/common"; +import { User } from "@vencord/discord-types"; +import { Menu, SelectedGuildStore, Toasts, UserProfileStore } from "@webpack/common"; -function getProfileColors(userId) { +const logger = new Logger("CopyProfileColors"); + +function getProfileColors(userId: string, guildId?: string) { try { - const profile = UserProfileStore.getUserProfile(userId); + const profile = guildId + ? UserProfileStore.getGuildMemberProfile(userId, guildId) + : UserProfileStore.getUserProfile(userId); - if (!profile || !profile.themeColors || profile.themeColors.length < 2) { + if (!profile?.themeColors || profile.themeColors.length < 2) { return null; } @@ -23,13 +29,13 @@ function getProfileColors(userId) { return { primaryColor, secondaryColor }; } catch (e) { - console.error("Failed to get profile colors:", e); + logger.error("Failed to get profile colors:", e); return null; } } -function copyProfileColors(userId) { - const colors = getProfileColors(userId); +function copyProfileColors(userId: string, guildId?: string) { + const colors = getProfileColors(userId, guildId); if (!colors) { Toasts.show({ @@ -53,7 +59,7 @@ function copyProfileColors(userId) { id: Toasts.genId() }); } catch (e) { - console.error("Failed to copy to clipboard:", e); + logger.error("Failed to copy to clipboard:", e); Toasts.show({ type: Toasts.Type.FAILURE, message: "Error copying profile colors!", @@ -75,8 +81,15 @@ export function ColorIcon() { ); } // spawn in the context menu -const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }) => { +const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user, guildId }: { user?: User; guildId?: string; }) => { if (!user) return; + + const effectiveGuildId = guildId ?? SelectedGuildStore.getGuildId(); + const guildProfile = effectiveGuildId + ? UserProfileStore.getGuildMemberProfile(user.id, effectiveGuildId) + : null; + const hasGuildColors = guildProfile?.themeColors && guildProfile.themeColors.length >= 2; + children.push( copyProfileColors(user.id)} /> ); + + if (hasGuildColors && effectiveGuildId) { + children.push( + copyProfileColors(user.id, effectiveGuildId)} + /> + ); + } }; export default definePlugin({ name: "CopyProfileColors", description: "A plugin to copy people's profile gradient colors to clipboard.", tags: ["Appearance", "Customisation"], - authors: [EquicordDevs.Crxa, EquicordDevs.Cortex], + authors: [EquicordDevs.Crxa, EquicordDevs.Cortex, EquicordDevs.Gir0fa], contextMenus: { "user-context": userContextMenuPatch, "user-profile-actions": userContextMenuPatch diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 09a44488f..7dd06e1a9 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1305,6 +1305,10 @@ export const EquicordDevs = Object.freeze({ name: "DKA", id: 119386840624005121n }, + Gir0fa: { + name: "gir0fa", + id: 1282734265955520545n, + }, yonn2222: { name: "yonn2222", id: 821835831844012103n