mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: update bot chunk 3
This commit is contained in:
1 parent
122b3f6478
commit
5499cb5cca
9 files changed
+69
-46
No files matched your search
@@ -28,10 +28,10 @@ export const aboutCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||
|
||||
async handler(interaction) {
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
const { t } = translator(interaction.locale);
|
||||
const { strings } = translator(interaction.locale);
|
||||
|
||||
if (subcommand === 'commands') {
|
||||
return t`bot.commands.about.subcommands.commands.body${(
|
||||
return `${strings.bot.commands.about.subcommands.commands.body}${(
|
||||
await Promise.all(COMMANDS_RAW)
|
||||
)
|
||||
.sort((a, b) =>
|
||||
|
||||
@@ -11,17 +11,17 @@ export const debugCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
command: createLocalizedCommand('debug'),
|
||||
|
||||
async handler(interaction) {
|
||||
const { t } = translator(interaction.locale);
|
||||
const { strings } = translator(interaction.locale);
|
||||
const currentTime = new Date().getTime();
|
||||
const uptime = currentTime - executionStart;
|
||||
const list = [
|
||||
[t`bot.commands.debug.body.version`, packageJSON.version],
|
||||
[strings.bot.commands.debug.body.version, packageJSON.version],
|
||||
[
|
||||
t`bot.commands.debug.body.shard`,
|
||||
client.shard?.ids[0] ?? t`bot.commands.debug.body.shard.default`,
|
||||
strings.bot.commands.debug.body.shard,
|
||||
client.shard?.ids[0] ?? strings.bot.commands.debug.body.shard.default,
|
||||
],
|
||||
[
|
||||
t`bot.commands.debug.body.uptime`,
|
||||
strings.bot.commands.debug.body.uptime,
|
||||
`${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor(
|
||||
(uptime / 1000 / 60) % 60,
|
||||
)}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor(
|
||||
@@ -29,7 +29,7 @@ export const debugCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
)}ms`,
|
||||
],
|
||||
];
|
||||
return t`bot.commands.debug.body.title${list
|
||||
return `${strings.bot.commands.debug.body.title}${list
|
||||
.map(([key, value]) => `- ${key}: ${value}`)
|
||||
.join('\n')}`;
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ export function GenericAllStats({
|
||||
supplementaryStats,
|
||||
locale,
|
||||
}: GenericAllStatsProps) {
|
||||
const { t } = translator(locale);
|
||||
const { strings } = translator(locale);
|
||||
const damageRatio = stats.damage_dealt / stats.damage_received;
|
||||
const killsToDeathRatio =
|
||||
stats.frags / (stats.battles - stats.survived_battles);
|
||||
@@ -30,27 +30,28 @@ export function GenericAllStats({
|
||||
<Root>
|
||||
<Row>
|
||||
<Card
|
||||
title={t`bot.commands.full_stats.body.cards.games`}
|
||||
title={strings.bot.commands.full_stats.body.cards.games.$}
|
||||
items={[
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.games.winrate`,
|
||||
label: strings.bot.commands.full_stats.body.cards.games.winrate,
|
||||
value: `${(100 * (stats.wins / stats.battles)).toFixed(2)}%`,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.games.battles`,
|
||||
label: strings.bot.commands.full_stats.body.cards.games.battles,
|
||||
value: stats.battles,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.games.wins_losses`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.games.wins_losses,
|
||||
value: `${stats.wins} / ${stats.losses}`,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Card
|
||||
title={t`bot.commands.full_stats.body.cards.efficiency`}
|
||||
title={strings.bot.commands.full_stats.body.cards.efficiency.$}
|
||||
items={[
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.efficiency.wn8`,
|
||||
label: strings.bot.commands.full_stats.body.cards.efficiency.wn8,
|
||||
value:
|
||||
supplementaryStats && isNumber(supplementaryStats.WN8)
|
||||
? supplementaryStats.WN8!.toFixed(0)
|
||||
@@ -60,14 +61,16 @@ export function GenericAllStats({
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.efficiency.survival`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.efficiency.survival,
|
||||
value: `${(
|
||||
100 *
|
||||
(stats.survived_battles / stats.battles)
|
||||
).toFixed(2)}%`,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.efficiency.accuracy`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.efficiency.accuracy,
|
||||
value: `${((stats.hits / stats.shots) * 100).toFixed(2)}%`,
|
||||
},
|
||||
]}
|
||||
@@ -75,14 +78,18 @@ export function GenericAllStats({
|
||||
</Row>
|
||||
<Row>
|
||||
<Card
|
||||
title={t`bot.commands.full_stats.body.cards.lethality`}
|
||||
title={strings.bot.commands.full_stats.body.cards.lethality.$}
|
||||
items={[
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.lethality.average_damage`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.lethality
|
||||
.average_damage,
|
||||
value: (stats.damage_dealt / stats.battles).toFixed(0),
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.lethality.damage_per_tier`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.lethality
|
||||
.damage_per_tier,
|
||||
value: supplementaryStats?.tier
|
||||
? (
|
||||
stats.damage_dealt /
|
||||
@@ -92,32 +99,44 @@ export function GenericAllStats({
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.lethality.damage_ratio`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.lethality
|
||||
.damage_ratio,
|
||||
value: isFinite(damageRatio) ? damageRatio.toFixed(2) : undefined,
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.lethality.average_kills`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.lethality
|
||||
.average_kills,
|
||||
value: (stats.frags / stats.battles).toFixed(0),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Card
|
||||
title={t`bot.commands.full_stats.body.cards.miscellaneous`}
|
||||
title={strings.bot.commands.full_stats.body.cards.miscellaneous.$}
|
||||
items={[
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.miscellaneous.average_tier`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.miscellaneous
|
||||
.average_tier,
|
||||
value: supplementaryStats?.tier?.toFixed(2),
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.miscellaneous.average_spots`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.miscellaneous
|
||||
.average_spots,
|
||||
value: (stats.spotted / stats.battles).toFixed(2),
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.miscellaneous.average_xp`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.miscellaneous
|
||||
.average_xp,
|
||||
value: (stats.xp / stats.battles).toFixed(0),
|
||||
},
|
||||
{
|
||||
label: t`bot.commands.full_stats.body.cards.miscellaneous.kills_to_death_ratio`,
|
||||
label:
|
||||
strings.bot.commands.full_stats.body.cards.miscellaneous
|
||||
.kills_to_death_ratio,
|
||||
value: isFinite(killsToDeathRatio)
|
||||
? killsToDeathRatio.toFixed(2)
|
||||
: undefined,
|
||||
|
||||
@@ -8,15 +8,15 @@ export async function searchClansAcrossRegionsBotWrapper(
|
||||
locale: Locale,
|
||||
limit?: number,
|
||||
) {
|
||||
const { t } = translator(locale);
|
||||
const { strings } = translator(locale);
|
||||
const trimmed = search.trim();
|
||||
|
||||
if (trimmed.length < 3) {
|
||||
throw new UserError(t`bot.common.errors.query_too_small`);
|
||||
throw new UserError(strings.bot.common.errors.query_too_small);
|
||||
}
|
||||
|
||||
if (trimmed.length > 100) {
|
||||
throw new UserError(t`bot.common.errors.query_too_long`);
|
||||
throw new UserError(strings.bot.common.errors.query_too_long);
|
||||
}
|
||||
|
||||
return await searchClansAcrossRegions(trimmed, limit);
|
||||
|
||||
@@ -8,15 +8,15 @@ export async function searchPlayersAcrossRegionsBotWrapper(
|
||||
locale: Locale,
|
||||
limit?: number,
|
||||
) {
|
||||
const { t } = translator(locale);
|
||||
const { strings } = translator(locale);
|
||||
const trimmed = search.trim();
|
||||
|
||||
if (trimmed.length < 3) {
|
||||
throw new UserError(t`bot.common.errors.query_too_small`);
|
||||
throw new UserError(strings.bot.common.errors.query_too_small);
|
||||
}
|
||||
|
||||
if (trimmed.length > 100) {
|
||||
throw new UserError(t`bot.common.errors.query_too_long`);
|
||||
throw new UserError(strings.bot.common.errors.query_too_long);
|
||||
}
|
||||
|
||||
return await searchPlayersAcrossRegions(trimmed, limit);
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function getTankHistories(
|
||||
locale: Locale,
|
||||
options?: Partial<GetTankHistoriesOptions>,
|
||||
) {
|
||||
const { t } = translator(locale);
|
||||
const { strings } = translator(locale);
|
||||
const mergedOptions = { ...getTankHistoriesDefaultOptions, ...options };
|
||||
const tankHistoriesResponse = await fetch(
|
||||
`https://www.blitzstars.com/api/tankhistories/for/${id}/`,
|
||||
@@ -82,7 +82,7 @@ export async function getTankHistories(
|
||||
const tankStats = await getTankStats(server, id);
|
||||
|
||||
if (tankStats === null) {
|
||||
throw new UserError(t`bot.common.errors.no_tank_stats`);
|
||||
throw new UserError(strings.bot.common.errors.no_tank_stats);
|
||||
}
|
||||
|
||||
tankStats.forEach((tankHistory) => {
|
||||
|
||||
@@ -3,16 +3,22 @@ import { translator } from '../localization/translator';
|
||||
import { localizationObject } from './localizationObject';
|
||||
|
||||
export function addUsernameChoices(option: SlashCommandStringOption) {
|
||||
const { t } = translator(Locale.EnglishUS);
|
||||
const { strings } = translator(Locale.EnglishUS);
|
||||
|
||||
return option
|
||||
.setName(t`bot.common.options.username`)
|
||||
.setName(strings.bot.common.options.username.$)
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.username', undefined, true),
|
||||
localizationObject(
|
||||
(strings) => strings.bot.common.options.username.$,
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(t`bot.common.options.username.description`)
|
||||
.setDescription(strings.bot.common.options.username.description)
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.username.description'),
|
||||
localizationObject(
|
||||
(strings) => strings.bot.common.options.username.description,
|
||||
),
|
||||
)
|
||||
.setAutocomplete(true);
|
||||
}
|
||||
@@ -6,13 +6,13 @@ export function buttonRefresh(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
path: string,
|
||||
) {
|
||||
const { t } = translator(interaction.locale);
|
||||
const { strings } = translator(interaction.locale);
|
||||
|
||||
if (
|
||||
interaction.appPermissions?.has('ReadMessageHistory') &&
|
||||
interaction.appPermissions?.has('ViewChannel')
|
||||
) {
|
||||
return buttonPrimary(path, t`bot.common.buttons.refresh`);
|
||||
return buttonPrimary(path, strings.bot.common.buttons.refresh);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -12,8 +12,6 @@ import {
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
|
||||
import { handleAutocomplete } from './handlers/autocomplete';
|
||||
import { handleChatInputCommand } from './handlers/chatInputCommand';
|
||||
|
||||
export type InteractionRawReturnable =
|
||||
| string
|
||||
@@ -109,9 +107,9 @@ export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
|
||||
|
||||
export async function interactionCreate(interaction: Interaction<CacheType>) {
|
||||
if (interaction.isAutocomplete()) {
|
||||
handleAutocomplete(interaction);
|
||||
// handleAutocomplete(interaction);
|
||||
} else if (interaction.isChatInputCommand()) {
|
||||
handleChatInputCommand(interaction);
|
||||
// handleChatInputCommand(interaction);
|
||||
} else if (interaction.isButton()) {
|
||||
// handleButton(interaction);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user