Files
blitzkit/src/commands/playerInfo.ts
T

56 lines
1.9 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-10-14 11:06:03 -05:00
import { getAccountInfo } from '../core/blitz/getAccountInfo';
2023-10-14 11:32:02 -05:00
import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername';
import embedInfo from '../core/discord/embedInfo';
2023-10-14 11:36:10 -05:00
import markdownTable from '../core/discord/markdownTable';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
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({
inProduction: true,
inPublic: true,
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
command: new SlashCommandBuilder()
.setName('player-info')
.setDescription('Basic information about a player')
.addStringOption(addUsernameChoices),
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
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(
`${markdownEscape(accountInfo.nickname)}'s information`,
2023-05-20 00:13:32 +00:00
2024-03-06 15:34:10 -06:00
markdownTable([
['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
2024-03-06 15:34:10 -06:00
autocomplete: autocompleteUsername,
});
});