mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: full name search
This commit is contained in:
1 parent
638c2c73da
commit
c04192e15e
4 files changed
+13
-15
No files matched your search
@@ -120,7 +120,11 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
|
||||
} else {
|
||||
setSearchedList(
|
||||
go(event.target.value, searchableTanks, {
|
||||
keys: ['name', 'id'] satisfies (keyof TankDefinition)[],
|
||||
keys: [
|
||||
'name',
|
||||
'name_full',
|
||||
'id',
|
||||
] satisfies (keyof TankDefinition)[],
|
||||
}).map(({ obj }) => obj),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { tankNamesDiacritics } from '../core/blitzkrieg/tankDefinitions';
|
||||
import { tankNames } from '../core/blitzkrieg/tankDefinitions';
|
||||
import addTankChoices from '../core/discord/addTankChoices';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
@@ -25,7 +25,7 @@ export const searchTanksCommand: CommandRegistry = {
|
||||
async handler(interaction) {
|
||||
const tank = interaction.options.getString('tank')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const results = go(tank, await tankNamesDiacritics, {
|
||||
const results = go(tank, await tankNames, {
|
||||
limit,
|
||||
keys: ['combined'],
|
||||
}).map((result) => result.obj.original);
|
||||
|
||||
@@ -86,21 +86,15 @@ export const tanksDefinitionsArray = new Promise<TankDefinition[]>(
|
||||
resolve((await entries).map((entry) => entry));
|
||||
},
|
||||
);
|
||||
export const tankNames = new Promise<string[]>(async (resolve) => {
|
||||
resolve((await entries).map(({ name }) => name));
|
||||
});
|
||||
export const tankNamesDiacritics = tankNames.then((tankNames) =>
|
||||
export const tankNames = tanksDefinitionsArray.then((tanks) =>
|
||||
Promise.all(
|
||||
tankNames.map(async (tankName, index) => {
|
||||
tanks.map(async (tank, index) => {
|
||||
const { id } = (await tanksDefinitionsArray)[index];
|
||||
const name = tankName ?? `Unknown Tank ${id}`;
|
||||
const diacriticless = deburr(name);
|
||||
|
||||
return {
|
||||
original: name,
|
||||
diacriticless,
|
||||
combined: `${name}${diacriticless}`,
|
||||
id,
|
||||
original: tank.name,
|
||||
combined: `${tank.name}${deburr(tank.name)}${tank.name_full ? `${tank.name_full}${deburr(tank.name_full)}` : ''}`,
|
||||
};
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import { tankNamesDiacritics } from '../blitzkrieg/tankDefinitions';
|
||||
import { tankNames } from '../blitzkrieg/tankDefinitions';
|
||||
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 tankNamesDiacritics, {
|
||||
go(focusedOption.value, await tankNames, {
|
||||
keys: ['combined'],
|
||||
limit: 10,
|
||||
}).map(async (item) => {
|
||||
|
||||
Reference in new issue
Block a user