Skip to content

Commit

Permalink
ref: begin working on settings translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Jan 30, 2025
1 parent 70abafa commit bcb548b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,34 @@
"noConfirmation": "No confirmation received, cancelling deletion of data."
}
},
"settings": {
"names": {
"command": "settings",
"subcmd": {
"reset": "reset",
"list": "list",
"set": "set",
"args": {
"newValue": "new_value"
}
}
},
"descriptions": {
"command": "View or edit the bot's settings for your user account",
"subcmd": {
"reset": "Reset the settings to the default values",
"list": "List all configurable settings and their current values",
"set": "Set a specific setting to a new value"
}
},
"settingName": {
"autoReplyEnabled": "auto reply state"
},
"changeSettingDescription": {
"autoReplyEnabled": "Change whether the bot will automatically reply to your messages containing a video link",
"autoReplyEnabledArg": "Whether auto-reply should be enabled"
}
},
"video_info": {
"names": {
"command": "video_info",
Expand Down
39 changes: 27 additions & 12 deletions src/commands/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { capitalize } from "@lib/text.js";
import { getAutoReplyValues } from "@cmd/Config.js";
import { GuildConfig } from "@models/GuildConfig.model.js";
import type { Stringifiable } from "@src/types.js";
import { getLocMap, tr } from "@lib/translate.js";

// TODO: translate

Expand All @@ -19,47 +20,55 @@ const scNames = {
} as const satisfies Partial<Record<keyof UserSettings, string>>;

/** All options that can be configured */
const configurableOptions: Record<
const getConfigurableOptions: (locale: string) => Record<
typeof scNames[keyof typeof scNames],
Omit<Parameters<typeof SettingsCmd.editSetting>[0], "int" | "opt"> & {
builder: (grpOpt: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder;
}
> = {
> = (locale: string) => ({
[scNames.autoReplyEnabled]: {
settProp: "autoReplyEnabled",
settingName: "auto reply state",
settingName: tr.for(locale, "commands.settings.settingName.autoReplyEnabled"),
getValueLabel: (val, loc) => getAutoReplyValues(loc).find(c => c.value === Boolean(val))?.name,
builder: (grpOpt: SlashCommandSubcommandBuilder) => grpOpt
.setDescription("Change whether the bot will automatically reply to your messages containing a video link")
.setDescription(tr.for("en-US", "commands.settings.changeSettingDescription.autoReplyEnabled"))
.setDescriptionLocalizations(getLocMap("commands.settings.changeSettingDescription.autoReplyEnabled"))
.addBooleanOption(opt =>
opt.setName("new_value")
.setDescription("Whether auto-reply should be enabled")
opt.setName(tr.for("en-US", "commands.settings.names.subcmd.args.newValue"))
.setNameLocalizations(getLocMap("commands.settings.names.subcmd.args.newValue"))
.setDescription(tr.for("en-US", "commands.settings.changeSettingDescription.autoReplyEnabledArg"))
.setDescriptionLocalizations(getLocMap("commands.settings.changeSettingDescription.autoReplyEnabledArg"))
.setRequired(true)
)
},
} as const;
} as const);

//#region constructor

export class SettingsCmd extends SlashCommand {
constructor() {
super(new SlashCommandBuilder()
.setName(CmdBase.getCmdName("settings"))
.setDescription("View or edit the bot's settings for your user account")
.setNameLocalizations(getLocMap("commands.settings.names.command", SettingsCmd.cmdPrefix))
.setDescription(tr.for("en-US", "commands.settings.descriptions.command"))
.setDescriptionLocalizations(getLocMap("commands.settings.descriptions.command"))
.addSubcommand(option => option
.setName("reset")
.setDescription("Reset the settings to the default values")
.setNameLocalizations(getLocMap("commands.settings.names.subcmd.reset"))
.setDescription(tr.for("en-US", "commands.settings.descriptions.subcmd.reset"))
)
.addSubcommand(option => option
.setName("list")
.setDescription("List all configurable settings and their current values")
.setNameLocalizations(getLocMap("commands.settings.names.subcmd.list"))
.setDescription(tr.for("en-US", "commands.settings.descriptions.subcmd.list"))
)
.addSubcommandGroup(grpOpt => {
grpOpt
.setName("set")
.setDescription("Set a specific setting to a new value");
.setNameLocalizations(getLocMap("commands.settings.names.subcmd.set"))
.setDescription(tr.for("en-US", "commands.settings.descriptions.subcmd.set"));

for(const [name, { builder }] of Object.entries(configurableOptions))
for(const [name, { builder }] of Object.entries(getConfigurableOptions("en-US")))
grpOpt.addSubcommand(option => builder(option).setName(name));

return grpOpt;
Expand All @@ -72,6 +81,12 @@ export class SettingsCmd extends SlashCommand {
public async run(int: CommandInteraction, opt: CommandInteractionOption) {
const reply = await int.deferReply({ ephemeral: true });

const locale = await SettingsCmd.getGuildLocale(int);
const configurableOptions = getConfigurableOptions(locale);
const t = tr.use(locale);

void ["TODO:", t];

switch(opt.name) {
case "set":
if(!opt.options?.[0])
Expand Down

0 comments on commit bcb548b

Please # to comment.