mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: /stats
This commit is contained in:
1 parent
bf7993fa38
commit
4482b76746
8 files changed
+192
-37
No files matched your search
+75
-2
@@ -1,14 +1,88 @@
|
||||
import {
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
SlashCommandBuilder,
|
||||
} from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { SERVERS } from '../constants/servers.js';
|
||||
import { PlayerStatistics } from '../types/statistics.js';
|
||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
|
||||
export async function execute(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
interaction.reply('YOU SUCK MORON GO PLAY ROBLOX');
|
||||
const ign = interaction.options.getString('ign')!;
|
||||
const server = interaction.options.getString(
|
||||
'server',
|
||||
) as keyof typeof SERVERS;
|
||||
const period = interaction.options.getString('period')! as
|
||||
| '30'
|
||||
| '90'
|
||||
| 'career';
|
||||
|
||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||
const data = (await (
|
||||
await fetch(
|
||||
`https://www.blitzstars.com/api/top/player/${account.account_id}`,
|
||||
)
|
||||
).json()) as PlayerStatistics;
|
||||
const stats =
|
||||
period === 'career' ? data.statistics : data[`period${period}d`];
|
||||
|
||||
interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(SKILLED_COLOR)
|
||||
.setTitle(
|
||||
`${data.nickname}'s ${
|
||||
period === 'career' ? period : `${period} day`
|
||||
} stats`,
|
||||
)
|
||||
.setDescription(
|
||||
`${[
|
||||
['Winrate', `${stats.special.winrate.toFixed(2)}%`],
|
||||
['Survival', `${stats.special.survivalRate.toFixed(2)}%`],
|
||||
[
|
||||
'Accuracy',
|
||||
`${((stats.all.hits / stats.all.shots) * 100).toFixed(2)}%`,
|
||||
],
|
||||
['WN8', stats.wn8.toFixed(0)],
|
||||
['WN7', stats.wn7.toFixed(0)],
|
||||
[],
|
||||
['Battles', stats.all.battles],
|
||||
['Wins', stats.all.wins],
|
||||
['Losses', stats.all.losses],
|
||||
['Average tier', stats.avg_tier.toFixed(2)],
|
||||
[],
|
||||
['Hits per battle', stats.special.hpb.toFixed(0)],
|
||||
['Damage per battle', stats.special.dpb.toFixed(0)],
|
||||
['Kills per battle', stats.special.kpb.toFixed(2)],
|
||||
['Spots per battle', stats.special.spb.toFixed(2)],
|
||||
[
|
||||
'Shots per battle',
|
||||
(stats.all.shots / stats.all.battles).toFixed(2),
|
||||
],
|
||||
[
|
||||
'Hits per battle',
|
||||
(stats.all.hits / stats.all.battles).toFixed(2),
|
||||
],
|
||||
['XP per battle', (stats.all.xp / stats.all.battles).toFixed(2)],
|
||||
[],
|
||||
['Damage ratio', stats.special.damageRatio.toFixed(2)],
|
||||
['Kills to death ratio', stats.special.kdr.toFixed(2)],
|
||||
]
|
||||
.map((array) =>
|
||||
array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`,
|
||||
)
|
||||
.join(
|
||||
'\n',
|
||||
)}\n\nPowered by [BlitzStars](https://www.blitzstars.com/)`,
|
||||
),
|
||||
],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
@@ -37,7 +111,6 @@ export const data = new SlashCommandBuilder()
|
||||
.setDescription('The last number of days of stats')
|
||||
.setChoices(
|
||||
{ name: '30 Days', value: '30' },
|
||||
{ name: '60 Days', value: '60' },
|
||||
{ name: '90 Days', value: '90' },
|
||||
{ name: 'Career', value: 'career' },
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user