aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/pronoundb/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/pronoundb/utils.ts')
-rw-r--r--src/plugins/pronoundb/utils.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/plugins/pronoundb/utils.ts b/src/plugins/pronoundb/utils.ts
index 24a55da..4547f94 100644
--- a/src/plugins/pronoundb/utils.ts
+++ b/src/plugins/pronoundb/utils.ts
@@ -1,5 +1,8 @@
+import gitHash from "git-hash";
+import { PronounsFormat } from ".";
import { debounce } from "../../utils";
-import { PronounCode, PronounsResponse } from "./types";
+import { Settings } from "../../Vencord";
+import { PronounCode, PronounMapping, PronounsResponse } from "./types";
// A map of cached pronouns so the same request isn't sent twice
const cache: Record<string, PronounCode> = {};
@@ -41,7 +44,8 @@ async function bulkFetchPronouns(ids: string[]): Promise<PronounsResponse> {
const req = await fetch("https://pronoundb.org/api/v1/lookup-bulk?" + params.toString(), {
method: "GET",
headers: {
- "Accept": "application/json"
+ "Accept": "application/json",
+ "X-PronounDB-Source": `Vencord/${gitHash} (github.com/Vendicated/Vencord)`
}
});
return await req.json()
@@ -57,3 +61,16 @@ async function bulkFetchPronouns(ids: string[]): Promise<PronounsResponse> {
return dummyPronouns;
}
}
+
+export function formatPronouns(pronouns: PronounCode): string {
+ const { pronounsFormat } = Settings.plugins.PronounDB as { pronounsFormat: PronounsFormat, enabled: boolean; };
+ // For capitalized pronouns, just return the mapping (it is by default capitalized)
+ if (pronounsFormat === PronounsFormat.Capitalized) return PronounMapping[pronouns];
+ // If it is set to lowercase and a special code (any, ask, avoid), then just return the capitalized text
+ else if (
+ pronounsFormat === PronounsFormat.Lowercase
+ && ["any", "ask", "avoid", "other"].includes(pronouns)
+ ) return PronounMapping[pronouns];
+ // Otherwise (lowercase and not a special code), then convert the mapping to lowercase
+ else return PronounMapping[pronouns].toLowerCase();
+}