6969import org .comroid .api .attr .LongAttribute ;
7070import org .comroid .api .attr .Named ;
7171import org .comroid .api .attr .StringAttribute ;
72- import org .comroid .api .data .seri .DataNode ;
72+ import org .comroid .api .data .seri .adp . JSON ;
7373import org .comroid .api .data .seri .type .ArrayValueType ;
7474import org .comroid .api .data .seri .type .BoundValueType ;
7575import org .comroid .api .data .seri .type .StandardValueType ;
111111import java .util .List ;
112112import java .util .Map ;
113113import java .util .NoSuchElementException ;
114+ import java .util .Objects ;
114115import java .util .Optional ;
115116import java .util .Set ;
116117import java .util .UUID ;
@@ -427,7 +428,7 @@ public final Stream<AutoFillOption> autoComplete(
427428
428429 protected final Usage createUsageBase (Handler source , String [] fullCommand , Object ... baseArgs ) {
429430 var baseNode = baseNodes .stream () // find base node to initiate advancing to execution node
430- .filter (node -> node .aliases ().anyMatch (fullCommand [0 ]::equals ))
431+ .filter (node -> node .names ().anyMatch (fullCommand [0 ]::equals ))
431432 .flatMap (cast (Node .Callable .class ))
432433 .findAny ()
433434 .orElseThrow (() -> new Error ("No such command: " + Arrays .toString (fullCommand )));
@@ -451,7 +452,17 @@ public final Stream<AutoFillOption> autoComplete(Usage usage, String argName, @N
451452 usage .advanceFull ();
452453 //todo verifyPermission(usage);
453454
454- return (usage .node instanceof Node .Call call ? call .nodes ()
455+ if (!(argName .isBlank () || argName .matches ("\\ d+" ))) {
456+ return usage .node .nodes ()
457+ .flatMap (Streams .cast (Node .Parameter .class ))
458+ .filter (node -> node .getName ().equals (argName ))
459+ .flatMap (param -> param .autoFill (usage , argName , currentValue ))
460+ .filter (str -> {
461+ var current = currentValue == null ? "" : currentValue ;
462+ return str .toLowerCase ().startsWith (current .toLowerCase ());
463+ })
464+ .map (str -> new AutoFillOption (str , str ));
465+ } else return (usage .node instanceof Node .Call call ? call .nodes ()
455466 .skip (usage .callIndex + usage .fullCommand .length - 2 )
456467 .limit (1 )
457468 .flatMap (param -> param .autoFill (usage , argName , currentValue )) : usage .node .nodes ().map (Node ::getName )).map (String ::trim )
@@ -601,7 +612,7 @@ private Node.Parameter createParameterNode(int index, Method origin, Parameter s
601612 .stream ()
602613 .flatMap (cast (AutoFillProvider .class ))
603614 .findAny ()
604- .orElseGet (() -> Activator .get (providerType ).createInstance (DataNode . Value . NULL ));
615+ .orElseGet (() -> Activator .get (providerType ).createInstance (JSON . Parser . createObjectNode () ));
605616 builder .autoFillProvider (provider );
606617 }
607618 return builder .build ();
@@ -731,9 +742,9 @@ public void onGenericEvent(@NotNull GenericEvent event) {
731742 bus .flatMap (CommandAutoCompleteInteractionEvent .class ).listen ().subscribeData (event -> {
732743 var option = event .getFocusedOption ();
733744 var options = autoComplete (Adapter$JDA .this ,
734- event .getCommandString ().split (" " ),
745+ event .getCommandString ().substring ( 1 ). split (" " ),
735746 option .getName (),
736- option .getValue ()).map (e -> new net .dv8tion .jda .api .interactions .commands .Command .Choice (e .key , e .description )).toList ();
747+ option .getValue ()).map (e -> new net .dv8tion .jda .api .interactions .commands .Command .Choice (e .key , e .description )).limit ( 25 ). toList ();
737748 event .replyChoices (options ).queue ();
738749 });
739750
@@ -1332,7 +1343,7 @@ public static class Parameter extends Node implements AutoFillProvider, Default.
13321343
13331344 @ Override
13341345 public Stream <String > autoFill (Usage usage , String argName , String currentValue ) {
1335- return autoFillProviders .stream ().flatMap (provider -> provider .autoFill (usage , argName , currentValue )).distinct ();
1346+ return autoFillProviders .stream ().filter ( Objects :: nonNull ). flatMap (provider -> provider .autoFill (usage , argName , currentValue )).distinct ();
13361347 }
13371348
13381349 @ Override
0 commit comments