PronounDB: Fix profile patch, add pronoun source to tooltip

This commit is contained in:
V 2023-06-30 15:39:33 +02:00
parent b592defaaf
commit 13bde79ec8
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
3 changed files with 25 additions and 14 deletions

View file

@ -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
? (

View file

@ -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
]
}
],

View file

@ -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) {