From 9f4c8c90883848d483552385172edb6ee400f86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:19:00 -0600 Subject: [PATCH] feat: inactive command localization --- src/commands/inactive.tsx | 39 +++++++++++++++++++++--------- src/core/discord/addClanChoices.ts | 12 +++++++-- src/lang/en-US.json | 24 ++++++++++++++++++ 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index 39d803123..d5f3d78ac 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -1,4 +1,4 @@ -import { SlashCommandBuilder } from 'discord.js'; +import { Locale } from 'discord.js'; import CommandWrapper from '../components/CommandWrapper'; import GenericStats from '../components/GenericStats'; import NoData from '../components/NoData'; @@ -7,7 +7,10 @@ import { getAccountInfo } from '../core/blitz/getAccountInfo'; import { getClanInfo } from '../core/blitz/getClanInfo'; import addClanChoices from '../core/discord/addClanChoices'; import autocompleteClan from '../core/discord/autocompleteClan'; +import { createLocalizedCommand } from '../core/discord/createLocalizedCommand'; +import { localizationObject } from '../core/discord/localizationObject'; import resolveClanFromCommand from '../core/discord/resolveClanFromCommand'; +import { translator } from '../core/localization/translator'; import { CommandRegistry } from '../events/interactionCreate'; const DEFAULT_THRESHOLD = 7; @@ -17,20 +20,29 @@ export const inactiveCommand = new Promise((resolve) => { inProduction: true, inPublic: true, - command: new SlashCommandBuilder() - .setName('inactive') - .setDescription('Lists all inactive players') + command: createLocalizedCommand('inactive') .addStringOption(addClanChoices) - .addNumberOption((option) => - option + .addNumberOption((option) => { + const { translate } = translator(Locale.EnglishUS); + + return option .setName('threshold') - .setDescription( - `The number of days inactive (default: ${DEFAULT_THRESHOLD})`, + .setNameLocalizations( + localizationObject('bot.commands.inactive.options.threshold'), ) - .setMinValue(0), - ), + .setDescription( + translate('bot.commands.inactive.options.threshold.description'), + ) + .setDescriptionLocalizations( + localizationObject( + 'bot.commands.inactive.options.threshold.description', + ), + ) + .setMinValue(0); + }), async handler(interaction) { + const { translate } = translator(interaction.locale); const { region, id } = await resolveClanFromCommand(interaction); const threshold = interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD; @@ -49,7 +61,10 @@ export const inactiveCommand = new Promise((resolve) => { .sort((a, b) => b[1] - a[1]) .map( ([name, days]) => - [name, `${days.toFixed(0)} days`] as [string, string], + [ + name, + translate('bot.commands.inactive.body.listing', [`${days}`]), + ] as [string, string], ); const hasInactiveMembers = inactive.length > 0; @@ -58,7 +73,7 @@ export const inactiveCommand = new Promise((resolve) => { {!hasInactiveMembers && ( diff --git a/src/core/discord/addClanChoices.ts b/src/core/discord/addClanChoices.ts index f25c29156..7e3a46be3 100644 --- a/src/core/discord/addClanChoices.ts +++ b/src/core/discord/addClanChoices.ts @@ -1,9 +1,17 @@ -import { SlashCommandStringOption } from 'discord.js'; +import { Locale, SlashCommandStringOption } from 'discord.js'; +import { translator } from '../localization/translator'; +import { localizationObject } from './localizationObject'; export default function addClanChoices(option: SlashCommandStringOption) { + const { translate } = translator(Locale.EnglishUS); + return option .setName('clan') - .setDescription('The clan name or tag you are checking') + .setNameLocalizations(localizationObject('bot.common.options.clan')) + .setDescription(translate('bot.common.options.clan.description')) + .setDescriptionLocalizations( + localizationObject('bot.common.options.clan.description'), + ) .setAutocomplete(true) .setMinLength(2) .setRequired(true); diff --git a/src/lang/en-US.json b/src/lang/en-US.json index efdf3ff25..ec8223263 100644 --- a/src/lang/en-US.json +++ b/src/lang/en-US.json @@ -80,6 +80,13 @@ } }, + "options": { + "clan": { + "$": "clan", + "description": "The clan name or tag" + } + }, + "periods": { "career": "Career", "today": "Today", @@ -174,6 +181,23 @@ "description": "Tank statistics" } } + }, + + "inactive": { + "$": "inactive", + "description": "Lists all inactive players in a clan above a threshold", + + "options": { + "threshold": { + "$": "threshold", + "description": "The number of days inactive (default: %s days)" + } + }, + + "body": { + "subtitle": "Inactive for %s+ days", + "listing": "%s days" + } } } },