Files
blitzkit/packages/bot/src/commands/playerInfo.ts
T

69 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-10-01 22:45:21 -05:00
import { getAccountInfo } from "@blitzkit/core";
import { literals } from "@blitzkit/i18n";
import markdownEscape from "markdown-escape";
import { addUsernameChoices } from "../core/discord/addUsernameChoices";
import { autocompleteUsername } from "../core/discord/autocompleteUsername";
import { createLocalizedCommand } from "../core/discord/createLocalizedCommand";
import { embedInfo } from "../core/discord/embedInfo";
import { markdownTable } from "../core/discord/markdownTable";
import { resolvePlayerFromCommand } from "../core/discord/resolvePlayerFromCommand";
import { translator } from "../core/localization/translator";
import { CommandRegistry } from "../events/interactionCreate";
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => {
resolve({
2024-03-08 20:43:30 -06:00
command:
2025-10-01 22:45:21 -05:00
createLocalizedCommand("player-info").addStringOption(addUsernameChoices),
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
2025-01-16 13:48:13 -06:00
const { strings } = translator(interaction.locale);
2024-03-06 15:34:10 -06:00
const account = await resolvePlayerFromCommand(interaction);
const { id, region: region } = account;
const accountInfo = await getAccountInfo(region, id);
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
return embedInfo(
2025-10-01 22:45:21 -05:00
literals(strings.bot.commands.player_info.body.title, {
name: markdownEscape(accountInfo.nickname),
}),
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
markdownTable([
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.nickname,
2024-03-09 12:10:44 -06:00
`${accountInfo.nickname}`,
],
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.battles,
2024-03-08 20:43:30 -06:00
`${accountInfo.statistics.all.battles}`,
],
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.winrate,
2024-03-06 15:34:10 -06:00
`${(
100 *
(accountInfo.statistics.all.wins /
accountInfo.statistics.all.battles)
).toFixed(2)}%`,
],
[],
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.account_id,
2024-03-08 20:43:30 -06:00
`${accountInfo.account_id}`,
2024-03-06 15:34:10 -06:00
],
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.created,
2024-03-08 20:43:30 -06:00
new Date(accountInfo.created_at * 1000).toLocaleDateString(
2025-10-01 22:45:21 -05:00
interaction.locale
2024-03-08 20:43:30 -06:00
),
],
[
2025-01-16 13:48:13 -06:00
strings.bot.commands.player_info.body.last_battle,
2024-03-08 20:43:30 -06:00
new Date(accountInfo.last_battle_time * 1000).toLocaleDateString(
2025-10-01 22:45:21 -05:00
interaction.locale
2024-03-08 20:43:30 -06:00
),
2024-03-06 15:34:10 -06:00
],
2025-10-01 22:45:21 -05:00
])
2024-03-06 15:34:10 -06:00
);
},
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
autocomplete: autocompleteUsername,
});
});