diff options
author | nea <nea@nea.moe> | 2023-01-13 08:38:59 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-01-13 08:44:16 +0100 |
commit | 069cb8bbf5f5bd413eec01535b71f9449f75a64d (patch) | |
tree | d90a6c7c8b8e61785bb9514f534c8893eba707df /src/plugins/pronoundb/index.ts | |
parent | 26f2b51eb95d59ed55d1fc0f81a1579e08bd29f3 (diff) | |
download | Vencord-069cb8bbf5f5bd413eec01535b71f9449f75a64d.tar.gz Vencord-069cb8bbf5f5bd413eec01535b71f9449f75a64d.tar.bz2 Vencord-069cb8bbf5f5bd413eec01535b71f9449f75a64d.zip |
feat(PronounDB): Allow setting local pronoun overrides for peoplefeat/localpronounoverrides
Diffstat (limited to 'src/plugins/pronoundb/index.ts')
-rw-r--r-- | src/plugins/pronoundb/index.ts | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/plugins/pronoundb/index.ts b/src/plugins/pronoundb/index.ts index c848110..87fb902 100644 --- a/src/plugins/pronoundb/index.ts +++ b/src/plugins/pronoundb/index.ts @@ -1,6 +1,6 @@ /* * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors + * Copyright (c) 2022-2023 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,12 +16,15 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import PronounsAboutComponent from "./components/PronounsAboutComponent"; import PronounsChatComponent from "./components/PronounsChatComponent"; import PronounsProfileWrapper from "./components/PronounsProfileWrapper"; +import { formatPronouns, getLocalPronounOverride, setLocalPronounOverride } from "./pronoundbUtils"; +import { PronounCode, PronounMapping } from "./types"; export enum PronounsFormat { Lowercase = "LOWERCASE", @@ -81,6 +84,60 @@ export default definePlugin({ default: true } }, + + commands: [ + { + description: "Set local pronouns for a person", + name: "setpronouns", + options: [ + { + description: "The user for which you want to set the local pronoun override", + name: "user", + displayName: "User", + type: ApplicationCommandOptionType.USER, + required: true, + }, + { + name: "pronouns", + displayName: "Pronouns", + type: ApplicationCommandOptionType.STRING, + description: "What pronouns should I display for this user.", + required: false, + choices: [ + ...Object.keys(PronounMapping).map(id => ({ + label: PronounMapping[id], + value: id, + name: PronounMapping[id], + })), + { + label: "Clear local override", + name: "Clear local override", + value: "clear", + } + ], + } + ], + inputType: ApplicationCommandInputType.BOT, + async execute(args, ctx) { + const user = findOption<string>(args, "user")!!; + const overrideWith = findOption<string>(args, "pronouns", "view"); + const currentOverride = await getLocalPronounOverride(user); + const currentOverrideText = currentOverride ? formatPronouns(currentOverride) : "No override"; + if (overrideWith === "view") { + sendBotMessage(ctx.channel.id, { content: `Current pronoun override for <@${user}>: ${currentOverrideText}` }); + return; + } + if (overrideWith !== currentOverride) { + const asPronounCode = overrideWith === "clear" ? null : overrideWith as PronounCode; + await setLocalPronounOverride(user, asPronounCode); + sendBotMessage(ctx.channel.id, { content: `Changed pronoun override for <@${user}> from ${currentOverrideText} to ${asPronounCode ? formatPronouns(asPronounCode) : "No override"}` }); + return; + } + sendBotMessage(ctx.channel.id, { content: `Pronoun override for <@${user}> is alredy ${currentOverrideText}` }); + }, + }, + ], + settingsAboutComponent: PronounsAboutComponent, // Re-export the components on the plugin object so it is easily accessible in patches PronounsChatComponent, |