mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: cleaned up directories
This commit is contained in:
1 parent
473ebfa46c
commit
613527e78f
41 files changed
+116
-832
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from 'discord.js';
|
||||
import { handleError } from '../behaviors/error.js';
|
||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||
import { client } from '../index.js';
|
||||
|
||||
export default async function blitzStarsError(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
error: Error,
|
||||
command: string,
|
||||
) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`${client.user?.username} ran into an issue`)
|
||||
.setDescription(
|
||||
'BlitzStars returned an error. Please try again later.',
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`BlitzStars returned an error`);
|
||||
handleError(error, client, command);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
|
||||
export default function blitzStarsLinks(server: BlitzServer, nickname: string) {
|
||||
return `[View full stats](https://www.blitzstars.com/player/${server}/${nickname}) • [Support BlitzStars](https://www.blitzstars.com/supporters)`;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { PlayerPeriodicStatsCollection } from '../../types/statistics.js';
|
||||
import { notTrackedByBlitzStars } from '../interaction/notTrackedByBlitzStars.js';
|
||||
|
||||
export default async function getBlitzStarsAccount(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
accountId: number,
|
||||
) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://www.blitzstars.com/api/top/player/${accountId}`,
|
||||
);
|
||||
const parsed = (await response.json()) as PlayerPeriodicStatsCollection;
|
||||
|
||||
if (parsed.statistics) {
|
||||
return parsed;
|
||||
} else throw new Error('No data to display');
|
||||
} catch (error) {
|
||||
await interaction.editReply({
|
||||
embeds: [notTrackedByBlitzStars],
|
||||
});
|
||||
|
||||
console.log(`Not tracked by BlitzStars.`);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { PlayerStats } from '../../types/playerStats.js';
|
||||
|
||||
export default async function getPlayerStats(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
command: string,
|
||||
id: number,
|
||||
callback: (playerStats: PlayerStats) => void,
|
||||
) {
|
||||
fetch(`https://www.blitzstars.com/api/playerstats/${id}`).then(
|
||||
async (response) => {
|
||||
callback((await response.json()) as PlayerStats);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
|
||||
export default function poweredByBlitzStars(embed: EmbedBuilder) {
|
||||
return embed.setTimestamp().setFooter({
|
||||
text: 'Powered by BlitzStars',
|
||||
iconURL: 'https://www.blitzstars.com/assets/images/TankyMcPewpew.png',
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export type TankType = 'heavyTank' | 'AT-SPG' | 'mediumTank' | 'lightTank';
|
||||
|
||||
export interface Tankopedia {
|
||||
status: 'ok'; // always will be ok since it is cached
|
||||
meta: {
|
||||
count: number;
|
||||
};
|
||||
data: {
|
||||
[tankId: number]: {
|
||||
name?: string;
|
||||
nation: string;
|
||||
is_premium: boolean;
|
||||
tier: number;
|
||||
cost: {
|
||||
price_credit: number;
|
||||
price_gold: number;
|
||||
};
|
||||
images: {
|
||||
preview: string;
|
||||
normal: string;
|
||||
};
|
||||
tank_id: number;
|
||||
type: TankType;
|
||||
description: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const tankopedia = (await (
|
||||
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
).json()) as Tankopedia;
|
||||
|
||||
export const tankIds = Object.keys(tankopedia.data) as unknown as number[];
|
||||
|
||||
export const tankNames = tankIds.map((id) => tankopedia.data[id].name);
|
||||
|
||||
export const tanks = tankIds.map((id) => tankopedia.data[id]);
|
||||
|
||||
export const TANK_TYPE_NAMES: Record<TankType, string> = {
|
||||
'AT-SPG': 'Tank Destroyer',
|
||||
heavyTank: 'Heavy Tank',
|
||||
mediumTank: 'Medium Tank',
|
||||
lightTank: 'Light Tank',
|
||||
};
|
||||
|
||||
export const TANK_TYPE_EMOJIS: Record<TankType, string> = {
|
||||
'AT-SPG': '🔽',
|
||||
heavyTank: '🇭',
|
||||
mediumTank: '🇲',
|
||||
lightTank: '🇱',
|
||||
};
|
||||
Reference in new issue
Block a user