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

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-09-08 10:17:40 -05:00
import { getAccountInfo } from '@blitzkit/core';
2023-05-20 00:48:52 +00:00
import markdownEscape from 'markdown-escape';
2024-09-08 10:11:24 -05:00
import { addUsernameChoices } from '../core/discord/addUsernameChoices';
import { autocompleteUsername } from '../core/discord/autocompleteUsername';
2024-03-08 20:43:30 -06:00
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
2024-09-08 10:11:24 -05:00
import { embedInfo } from '../core/discord/embedInfo';
import { markdownTable } from '../core/discord/markdownTable';
import { resolvePlayerFromCommand } from '../core/discord/resolvePlayerFromCommand';
2024-03-08 20:43:30 -06:00
import { translator } from '../core/localization/translator';
2023-07-11 19:54:57 +00:00
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:
createLocalizedCommand('player-info').addStringOption(addUsernameChoices),
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
2024-03-08 20:43:30 -06:00
const { t, translate } = 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(
2024-03-09 12:10:44 -06:00
translate('bot.commands.player_info.body.title', [
2024-03-08 20:43:30 -06:00
markdownEscape(accountInfo.nickname),
]),
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
markdownTable([
[
2024-03-09 12:10:44 -06:00
t`bot.commands.player_info.body.nickname`,
`${accountInfo.nickname}`,
],
[
t`bot.commands.player_info.body.battles`,
2024-03-08 20:43:30 -06:00
`${accountInfo.statistics.all.battles}`,
],
[
2024-03-09 12:10:44 -06:00
t`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)}%`,
],
[],
[
2024-03-09 12:10:44 -06:00
t`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
],
[
2024-03-09 12:10:44 -06:00
t`bot.commands.player_info.body.created`,
2024-03-08 20:43:30 -06:00
new Date(accountInfo.created_at * 1000).toLocaleDateString(
interaction.locale,
),
],
[
2024-03-09 12:10:44 -06:00
t`bot.commands.player_info.body.last_battle`,
2024-03-08 20:43:30 -06:00
new Date(accountInfo.last_battle_time * 1000).toLocaleDateString(
interaction.locale,
),
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,
});
});