From 13bde79ec8c78a471eb9cf3e6e58f404e8f1bd1f Mon Sep 17 00:00:00 2001 From: V Date: Fri, 30 Jun 2023 15:39:33 +0200 Subject: [PATCH] PronounDB: Fix profile patch, add pronoun source to tooltip --- .../components/PronounsChatComponent.tsx | 4 +-- src/plugins/pronoundb/index.ts | 27 +++++++++++++------ src/plugins/pronoundb/pronoundbUtils.ts | 8 +++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/plugins/pronoundb/components/PronounsChatComponent.tsx b/src/plugins/pronoundb/components/PronounsChatComponent.tsx index 3e51544b..97d24943 100644 --- a/src/plugins/pronoundb/components/PronounsChatComponent.tsx +++ b/src/plugins/pronoundb/components/PronounsChatComponent.tsx @@ -52,7 +52,7 @@ export function CompactPronounsChatComponentWrapper({ message }: { message: Mess } function PronounsChatComponent({ message }: { message: Message; }) { - const result = useFormattedPronouns(message.author.id); + const [result] = useFormattedPronouns(message.author.id); return result ? ( @@ -64,7 +64,7 @@ function PronounsChatComponent({ message }: { message: Message; }) { } export function CompactPronounsChatComponent({ message }: { message: Message; }) { - const result = useFormattedPronouns(message.author.id); + const [result] = useFormattedPronouns(message.author.id); return result ? ( diff --git a/src/plugins/pronoundb/index.ts b/src/plugins/pronoundb/index.ts index f9e26b10..c9965516 100644 --- a/src/plugins/pronoundb/index.ts +++ b/src/plugins/pronoundb/index.ts @@ -26,6 +26,11 @@ import { CompactPronounsChatComponentWrapper, PronounsChatComponentWrapper } fro import { useProfilePronouns } from "./pronoundbUtils"; import { settings } from "./settings"; +const PRONOUN_TOOLTIP_PATCH = { + match: /text:(.{0,10}.Messages\.USER_PROFILE_PRONOUNS)(?=,)/, + replace: '$& + (typeof vcPronounSource !== "undefined" ? ` (${vcPronounSource})` : "")' +}; + export default definePlugin({ name: "PronounDB", authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven], @@ -50,18 +55,24 @@ export default definePlugin({ // Patch the profile popout username header to use our pronoun hook instead of Discord's pronouns { find: ".userTagNoNickname", - replacement: { - match: /=(\i)\.pronouns/, - replace: "=$self.useProfilePronouns($1.user.id)" - } + replacement: [ + { + match: /,(\i)=(\i)\.pronouns/, + replace: ",[$1,vcPronounSource]=$self.useProfilePronouns($2.user.id)" + }, + PRONOUN_TOOLTIP_PATCH + ] }, // Patch the profile modal username header to use our pronoun hook instead of Discord's pronouns { find: ".USER_PROFILE_ACTIVITY", - replacement: { - match: /\).showPronouns/, - replace: ").showPronouns||true;const vcPronounce=$self.useProfilePronouns(arguments[0].user.id);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce" - } + replacement: [ + { + match: /getGlobalName\(\i\);(?<=displayProfile.{0,200})/, + replace: "$&const [vcPronounce,vcPronounSource]=$self.useProfilePronouns(arguments[0].user.id);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce;" + }, + PRONOUN_TOOLTIP_PATCH + ] } ], diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts index 63565bb0..d47d7d4f 100644 --- a/src/plugins/pronoundb/pronoundbUtils.ts +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -62,7 +62,7 @@ function getDiscordPronouns(id: string) { ); } -export function useFormattedPronouns(id: string): string | null { +export function useFormattedPronouns(id: string): [string | null, string] { // Discord is so stupid you can put tons of newlines in pronouns const discordPronouns = getDiscordPronouns(id)?.trim().replace(NewLineRe, " "); @@ -72,12 +72,12 @@ export function useFormattedPronouns(id: string): string | null { }); if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns) - return discordPronouns; + return [discordPronouns, "Discord"]; if (result && result !== "unspecified") - return formatPronouns(result); + return [formatPronouns(result), "PronounDB"]; - return discordPronouns; + return [discordPronouns, "Discord"]; } export function useProfilePronouns(id: string) {