Files
blitzkit/src/commands/playerinfo.ts
T

60 lines
2.0 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-05-20 00:13:32 +00:00
import usernameAutocomplete from '../core/autocomplete/username.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import cleanTable from '../core/interaction/cleanTable.js';
2023-05-21 16:50:05 +00:00
import infoEmbed from '../core/interaction/infoEmbed.js';
2023-05-20 00:13:32 +00:00
import addUsernameOption from '../core/options/addUsernameOption.js';
2023-06-23 01:35:15 +00:00
import resolvePlayer from '../core/options/resolvePlayer.js';
2023-06-12 01:17:26 +00:00
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
2023-05-20 00:13:32 +00:00
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
export default {
inProduction: true,
2023-06-16 02:15:46 +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')
.addStringOption(addUsernameOption),
async execute(interaction) {
2023-06-23 01:35:15 +00:00
const account = await resolvePlayer(interaction);
2023-05-20 00:13:32 +00:00
const { id, server } = account;
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-16 02:01:06 +00:00
return infoEmbed(
`${markdownEscape(accountInfo.nickname)}'s information`,
2023-05-20 00:13:32 +00:00
2023-06-16 02:01:06 +00:00
cleanTable([
['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
},
autocomplete: usernameAutocomplete,
} satisfies CommandRegistry;