mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +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 {
|
} else {
|
||||||
setSearchedList(
|
setSearchedList(
|
||||||
go(event.target.value, searchableTanks, {
|
go(event.target.value, searchableTanks, {
|
||||||
keys: ['name', 'id'] satisfies (keyof TankDefinition)[],
|
keys: [
|
||||||
|
'name',
|
||||||
|
'name_full',
|
||||||
|
'id',
|
||||||
|
] satisfies (keyof TankDefinition)[],
|
||||||
}).map(({ obj }) => obj),
|
}).map(({ obj }) => obj),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { tankNamesDiacritics } from '../core/blitzkrieg/tankDefinitions';
|
import { tankNames } from '../core/blitzkrieg/tankDefinitions';
|
||||||
import addTankChoices from '../core/discord/addTankChoices';
|
import addTankChoices from '../core/discord/addTankChoices';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
@@ -25,7 +25,7 @@ export const searchTanksCommand: CommandRegistry = {
|
|||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const tank = interaction.options.getString('tank')!;
|
const tank = interaction.options.getString('tank')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const results = go(tank, await tankNamesDiacritics, {
|
const results = go(tank, await tankNames, {
|
||||||
limit,
|
limit,
|
||||||
keys: ['combined'],
|
keys: ['combined'],
|
||||||
}).map((result) => result.obj.original);
|
}).map((result) => result.obj.original);
|
||||||
|
|||||||
@@ -86,21 +86,15 @@ export const tanksDefinitionsArray = new Promise<TankDefinition[]>(
|
|||||||
resolve((await entries).map((entry) => entry));
|
resolve((await entries).map((entry) => entry));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
export const tankNames = new Promise<string[]>(async (resolve) => {
|
export const tankNames = tanksDefinitionsArray.then((tanks) =>
|
||||||
resolve((await entries).map(({ name }) => name));
|
|
||||||
});
|
|
||||||
export const tankNamesDiacritics = tankNames.then((tankNames) =>
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
tankNames.map(async (tankName, index) => {
|
tanks.map(async (tank, index) => {
|
||||||
const { id } = (await tanksDefinitionsArray)[index];
|
const { id } = (await tanksDefinitionsArray)[index];
|
||||||
const name = tankName ?? `Unknown Tank ${id}`;
|
|
||||||
const diacriticless = deburr(name);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
original: name,
|
|
||||||
diacriticless,
|
|
||||||
combined: `${name}${diacriticless}`,
|
|
||||||
id,
|
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,
|
CacheType,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import { tankNamesDiacritics } from '../blitzkrieg/tankDefinitions';
|
import { tankNames } from '../blitzkrieg/tankDefinitions';
|
||||||
import {
|
import {
|
||||||
DISCORD_CHOICES_MAX_NAME_SIZE,
|
DISCORD_CHOICES_MAX_NAME_SIZE,
|
||||||
OVERFLOW_SUFFIX,
|
OVERFLOW_SUFFIX,
|
||||||
@@ -19,7 +19,7 @@ export default async function autocompleteTanks(
|
|||||||
await interaction.respond(
|
await interaction.respond(
|
||||||
focusedOption.value
|
focusedOption.value
|
||||||
? await Promise.all(
|
? await Promise.all(
|
||||||
go(focusedOption.value, await tankNamesDiacritics, {
|
go(focusedOption.value, await tankNames, {
|
||||||
keys: ['combined'],
|
keys: ['combined'],
|
||||||
limit: 10,
|
limit: 10,
|
||||||
}).map(async (item) => {
|
}).map(async (item) => {
|
||||||
|
|||||||
Reference in new issue
Block a user