Files
blitzkit/src/commands/playerInfo.ts
T

60 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-05-20 00:13:32 +00:00
import { SlashCommandBuilder } from 'discord.js';
2023-05-20 00:48:52 +00:00
import markdownEscape from 'markdown-escape';
2023-07-11 19:54:57 +00:00
import getWargamingResponse from '../core/blitz/getWargamingResponse';
import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername';
import embedInfo from '../core/discord/embedInfo';
import markdownTable from '../core/discord/markdownTable';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments';
import { CommandRegistry } from '../events/interactionCreate';
import { AccountInfo } from '../types/accountInfo';
2023-05-20 00:13:32 +00:00
2023-07-05 01:15:18 +00:00
export const playerInfoCommand: CommandRegistry = {
2023-05-20 00:13:32 +00:00
inProduction: true,
2023-07-08 19:39:35 +00:00
inDevelopment: false,
2023-05-20 00:13:32 +00:00
inPublic: true,
command: new SlashCommandBuilder()
.setName('playerinfo')
2023-05-20 00:13:32 +00:00
.setDescription('Basic information about a player')
2023-06-27 02:22:28 +00:00
.addStringOption(addUsernameChoices),
2023-05-20 00:13:32 +00:00
2023-06-27 01:43:30 +00:00
async handler(interaction) {
2023-06-27 02:07:14 +00:00
const account = await resolvePlayerFromCommand(interaction);
const { id, region: server } = account;
2023-05-20 00:13:32 +00:00
const accounts = await getWargamingResponse<AccountInfo>(
2023-06-12 01:17:26 +00:00
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
2023-05-20 00:13:32 +00:00
);
const accountInfo = accounts[id];
2023-06-27 02:22:28 +00:00
return embedInfo(
2023-06-16 02:01:06 +00:00
`${markdownEscape(accountInfo.nickname)}'s information`,
2023-05-20 00:13:32 +00:00
2023-06-27 02:22:28 +00:00
markdownTable([
2023-06-16 02:01:06 +00:00
['Nickname', `${accountInfo.nickname}`],
['Battles', `${accountInfo.statistics.all.battles}`],
[
'Winrate',
`${(
100 *
(accountInfo.statistics.all.wins /
accountInfo.statistics.all.battles)
).toFixed(2)}%`,
],
[],
['Account ID', `${accountInfo.account_id}`],
[
'Created',
`${new Date(accountInfo.created_at * 1000).toDateString()}`,
],
[
'Last battle',
`${new Date(accountInfo.last_battle_time * 1000).toDateString()}`,
],
]),
);
2023-05-20 00:13:32 +00:00
},
2023-06-27 02:22:28 +00:00
autocomplete: autocompleteUsername,
2023-07-05 01:15:18 +00:00
};