Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sern/handler",
"version": "1.1.7-beta",
"version": "1.1.8-beta",
"description": "A customizable, batteries-included, powerful discord.js framework to automate and streamline bot development.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"author": "SernDevs",
"license": "MIT",
"dependencies": {
"discord.js": "^14.0.3",
"discord.js": "^14.1.2",
"rxjs": "^7.5.6",
"ts-pattern": "^4.0.2",
"ts-results": "^3.3.0"
Expand Down
6 changes: 3 additions & 3 deletions src/handler/events/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
} from 'discord.js';
import { isAutocomplete } from '../utilities/predicates';
import { SernError } from '../structures/errors';
import treeSearch from '../utilities/treeSearch';

export function applicationCommandDispatcher(interaction: Interaction) {
if (isAutocomplete(interaction)) {
Expand All @@ -41,10 +42,9 @@ export function applicationCommandDispatcher(interaction: Interaction) {
}

export function dispatchAutocomplete(interaction: AutocompleteInteraction) {
const choice = interaction.options.getFocused(true);
return (mod: BothCommand | SlashCommand) => {
const selectedOption = mod.options?.find(o => o.autocomplete && o.name === choice.name);
if (selectedOption !== undefined && selectedOption.autocomplete) {
const selectedOption = treeSearch(interaction, mod.options);
if (selectedOption !== undefined) {
return {
mod,
execute: () => selectedOption.command.execute(interaction),
Expand Down
31 changes: 31 additions & 0 deletions src/handler/utilities/treeSearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { SernOptionsData } from '../structures/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;
}
}
}