mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: player info
This commit is contained in:
1 parent
29eeeb41ae
commit
2c472e25af
1 file changed
+69
@@ -0,0 +1,69 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cleanTable from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import sklldEmbed from '../core/interaction/sklldEmbed.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('playerinfo'))
|
||||
.setDescription('Basic information about a player')
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const name = interaction.options.getString('username')!;
|
||||
const account = await getBlitzAccount(interaction, name);
|
||||
if (!account) return;
|
||||
const { id, server } = account;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accounts) return;
|
||||
const accountInfo = accounts[id];
|
||||
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
sklldEmbed(
|
||||
`${accountInfo.nickname}'s information`,
|
||||
|
||||
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()}`,
|
||||
],
|
||||
]),
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Displaying player info for ${accountInfo.nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
Reference in new issue
Block a user