mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import {
|
|
CacheType,
|
|
ChatInputCommandInteraction,
|
|
EmbedBuilder,
|
|
} from 'discord.js';
|
|
import fetch from 'node-fetch';
|
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
|
import { PlayerStatistics } from '../types/statistics.js';
|
|
|
|
export default async function getBlitzStarsAccount(
|
|
interaction: ChatInputCommandInteraction<CacheType>,
|
|
accountId: number,
|
|
name: string,
|
|
callback: (account: PlayerStatistics) => void,
|
|
) {
|
|
await interaction.deferReply();
|
|
|
|
async function notTracked() {
|
|
await interaction.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle('No data to display')
|
|
.setDescription(`${name} is not tracked by BlitzStars.`)
|
|
.setColor(NEGATIVE_COLOR),
|
|
],
|
|
});
|
|
|
|
console.log(`${name} is not tracked by BlitzStars.`);
|
|
}
|
|
|
|
fetch(`https://www.blitzstars.com/api/top/player/${accountId}`)
|
|
.then(async (response) => {
|
|
const data = (await response.json()) as PlayerStatistics;
|
|
|
|
if (data.statistics) {
|
|
callback(data);
|
|
} else {
|
|
notTracked();
|
|
}
|
|
})
|
|
.catch(notTracked);
|
|
}
|