mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: inactive command localization
This commit is contained in:
1 parent
bd6f1f3570
commit
9f4c8c9088
3 files changed
+61
-14
No files matched your search
+27
-12
@@ -1,4 +1,4 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import CommandWrapper from '../components/CommandWrapper';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import GenericStats from '../components/GenericStats';
|
import GenericStats from '../components/GenericStats';
|
||||||
import NoData from '../components/NoData';
|
import NoData from '../components/NoData';
|
||||||
@@ -7,7 +7,10 @@ import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
|||||||
import { getClanInfo } from '../core/blitz/getClanInfo';
|
import { getClanInfo } from '../core/blitz/getClanInfo';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
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 resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
||||||
|
import { translator } from '../core/localization/translator';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
const DEFAULT_THRESHOLD = 7;
|
const DEFAULT_THRESHOLD = 7;
|
||||||
@@ -17,20 +20,29 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
inProduction: true,
|
inProduction: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: createLocalizedCommand('inactive')
|
||||||
.setName('inactive')
|
|
||||||
.setDescription('Lists all inactive players')
|
|
||||||
.addStringOption(addClanChoices)
|
.addStringOption(addClanChoices)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) => {
|
||||||
option
|
const { translate } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
|
return option
|
||||||
.setName('threshold')
|
.setName('threshold')
|
||||||
.setDescription(
|
.setNameLocalizations(
|
||||||
`The number of days inactive (default: ${DEFAULT_THRESHOLD})`,
|
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) {
|
async handler(interaction) {
|
||||||
|
const { translate } = translator(interaction.locale);
|
||||||
const { region, id } = await resolveClanFromCommand(interaction);
|
const { region, id } = await resolveClanFromCommand(interaction);
|
||||||
const threshold =
|
const threshold =
|
||||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||||
@@ -49,7 +61,10 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
.sort((a, b) => b[1] - a[1])
|
.sort((a, b) => b[1] - a[1])
|
||||||
.map(
|
.map(
|
||||||
([name, days]) =>
|
([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;
|
const hasInactiveMembers = inactive.length > 0;
|
||||||
|
|
||||||
@@ -58,7 +73,7 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
<TitleBar
|
<TitleBar
|
||||||
title={clanInfo.name}
|
title={clanInfo.name}
|
||||||
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
|
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
|
||||||
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
|
description={`${translate('bot.commands.inactive.body.subtitle', [`${threshold}`])} • ${new Date().toLocaleDateString(interaction.locale)}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!hasInactiveMembers && (
|
{!hasInactiveMembers && (
|
||||||
|
|||||||
@@ -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) {
|
export default function addClanChoices(option: SlashCommandStringOption) {
|
||||||
|
const { translate } = translator(Locale.EnglishUS);
|
||||||
|
|
||||||
return option
|
return option
|
||||||
.setName('clan')
|
.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)
|
.setAutocomplete(true)
|
||||||
.setMinLength(2)
|
.setMinLength(2)
|
||||||
.setRequired(true);
|
.setRequired(true);
|
||||||
|
|||||||
@@ -80,6 +80,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"options": {
|
||||||
|
"clan": {
|
||||||
|
"$": "clan",
|
||||||
|
"description": "The clan name or tag"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"periods": {
|
"periods": {
|
||||||
"career": "Career",
|
"career": "Career",
|
||||||
"today": "Today",
|
"today": "Today",
|
||||||
@@ -174,6 +181,23 @@
|
|||||||
"description": "Tank statistics"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user