feat: tankopedia website

This commit is contained in:
TrèsAbhi committed 2023-11-30 12:21:20 -06:00
1 parent 818ee1d447
commit f3144be382
7 files changed
+77 -13

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
import { go } from 'fuzzysort';
import { TANKS, tankopedia } from '../blitzkrieg/tankopedia';
import { tankopedia, tanks } from '../blitzkrieg/tankopedia';
import { UserError } from '../blitzkrieg/userError';
export default async function resolveTankId(tank: string | number) {
const number = typeof tank === 'string' ? parseInt(tank) : tank;
if (Number.isNaN(number)) {
const searchResult = go(`${tank}`, await TANKS, {
const searchResult = go(`${tank}`, await tanks, {
keys: ['name'],
limit: 1,
});
+6 -6
View File
@@ -1,5 +1,5 @@
import { deburr } from 'lodash';
import { TreeTypeString } from '../../components/Tanks';
import { TankType, TreeTypeString } from '../../components/Tanks';
import { asset } from './asset';
export interface TankopediaEntry {
@@ -25,7 +25,7 @@ export interface BlitzkriegTankopediaEntry {
name_short?: string;
tree_type: TreeTypeString;
tier: Tier;
type: string;
type: TankType;
}
export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>;
@@ -36,18 +36,18 @@ export const tankopedia = fetch(asset('tankopedia.json')).then(
const entries = new Promise<BlitzkriegTankopediaEntry[]>(async (resolve) => {
resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
});
export const TANKS = new Promise<BlitzkriegTankopediaEntry[]>(
export const tanks = new Promise<BlitzkriegTankopediaEntry[]>(
async (resolve) => {
resolve((await entries).map((entry) => entry));
},
);
export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
export const tankNames = new Promise<string[]>(async (resolve) => {
resolve((await entries).map(({ name }) => name));
});
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) =>
export const tankNamesDiacritics = tankNames.then((tankNames) =>
Promise.all(
tankNames.map(async (tankName, index) => {
const { id } = (await TANKS)[index];
const { id } = (await tanks)[index];
const name = tankName ?? `Unknown Tank ${id}`;
const diacriticless = deburr(name);
+2 -2
View File
@@ -4,7 +4,7 @@ import {
CacheType,
} from 'discord.js';
import { go } from 'fuzzysort';
import { TANK_NAMES_DIACRITICS } from '../blitzkrieg/tankopedia';
import { tankNamesDiacritics } from '../blitzkrieg/tankopedia';
import {
DISCORD_CHOICES_MAX_NAME_SIZE,
OVERFLOW_SUFFIX,
@@ -19,7 +19,7 @@ export default async function autocompleteTanks(
await interaction.respond(
focusedOption.value
? await Promise.all(
go(focusedOption.value, await TANK_NAMES_DIACRITICS, {
go(focusedOption.value, await tankNamesDiacritics, {
keys: ['combined'],
limit: 10,
}).map(async (item) => {