mirror of
https://github.com/SrIzan10/handler.git
synced 2026-05-01 10:45:17 +00:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import type { SernOptionsData } from '../../types/module';
|
|
import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js';
|
|
|
|
export default function treeSearch(
|
|
iAutocomplete: AutocompleteInteraction,
|
|
options: SernOptionsData[] | undefined,
|
|
) {
|
|
if (options === undefined) return undefined;
|
|
const _options = options.slice(); // required to prevent direct mutation of options
|
|
while (_options.length > 0) {
|
|
const cur = _options.pop()!;
|
|
switch (cur.type) {
|
|
case ApplicationCommandOptionType.Subcommand:
|
|
{
|
|
for (const option of cur.options ?? []) {
|
|
_options.push(option);
|
|
}
|
|
}
|
|
break;
|
|
case ApplicationCommandOptionType.SubcommandGroup:
|
|
{
|
|
for (const command of cur.options ?? []) {
|
|
_options.push(command);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
if (cur.autocomplete) {
|
|
const choice = iAutocomplete.options.getFocused(true);
|
|
if (cur.name === choice.name && cur.autocomplete) {
|
|
return cur;
|
|
}
|
|
return undefined;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|