diff options
author | V <vendicated@riseup.net> | 2023-06-30 15:39:33 +0200 |
---|---|---|
committer | V <vendicated@riseup.net> | 2023-06-30 15:39:33 +0200 |
commit | 13bde79ec8c78a471eb9cf3e6e58f404e8f1bd1f (patch) | |
tree | 97b083f36611449ddc9e273c0702f1edbcc190b0 | |
parent | b592defaaf5f92c942b6c2dc3f39c4761a823ca3 (diff) | |
download | Vencord-13bde79ec8c78a471eb9cf3e6e58f404e8f1bd1f.tar.gz Vencord-13bde79ec8c78a471eb9cf3e6e58f404e8f1bd1f.tar.bz2 Vencord-13bde79ec8c78a471eb9cf3e6e58f404e8f1bd1f.zip |
PronounDB: Fix profile patch, add pronoun source to tooltip
-rw-r--r-- | src/plugins/pronoundb/components/PronounsChatComponent.tsx | 4 | ||||
-rw-r--r-- | src/plugins/pronoundb/index.ts | 27 | ||||
-rw-r--r-- | 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 3e51544..97d2494 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 f9e26b1..c996551 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 63565bb..d47d7d4 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) { |