refactor(wrapper): improve Converter structure
All checks were successful
github-mirror / push-github (push) Successful in 1m38s
Build / Gradle-Build (push) Successful in 32s
Test / Gradle-Test (push) Successful in 47s

This commit is contained in:
tueem 2025-04-06 13:14:22 +02:00
parent 991d1c047b
commit 0b7b607a23
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB
4 changed files with 76 additions and 71 deletions

View File

@ -13,27 +13,28 @@ public class AutocompleteIdentifierConverter implements IdentifierProvider.Conve
@Override
public InteractionIdentifier convert(ChatInputAutoCompleteEvent context) {
List<ApplicationCommandInteractionOption> options = Discord4JWrapper.SUB_FILTER.apply(context.getOptions());
String commandName = context.getCommandName();
InteractionIdentifier last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(context.getCommandName())
.build();
List<ApplicationCommandInteractionOption> options = Discord4JWrapper.SUB_FILTER.apply(context.getOptions());
if (!options.isEmpty()) {
last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(options.getFirst().getName())
.parent(last)
.build();
List<ApplicationCommandInteractionOption> subOptions = Discord4JWrapper.SUB_FILTER.apply(options.getFirst().getOptions());
if (!subOptions.isEmpty())
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName,
options.getFirst().getName(),
subOptions.getFirst().getName());
else
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName,
options.getFirst().getName());
}else
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName);
last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(subOptions.getFirst().getName())
.parent(last)
.build();
}
return last;
}
}

View File

@ -13,27 +13,28 @@ public class SlashCommandIdentifierConverter implements IdentifierProvider.Conve
@Override
public InteractionIdentifier convert(ChatInputInteractionEvent context) {
InteractionIdentifier last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(context.getCommandName())
.build();
List<ApplicationCommandInteractionOption> options = Discord4JWrapper.SUB_FILTER.apply(context.getOptions());
String commandName = context.getCommandName();
if (!options.isEmpty()) {
List<ApplicationCommandInteractionOption> sub_options = Discord4JWrapper.SUB_FILTER.apply(options.getFirst().getOptions());
if (!sub_options.isEmpty())
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName,
options.getFirst().getName(),
sub_options.getFirst().getName());
else
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName,
options.getFirst().getName());
}else
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName);
last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(options.getFirst().getName())
.parent(last)
.build();
List<ApplicationCommandInteractionOption> subOptions = Discord4JWrapper.SUB_FILTER.apply(options.getFirst().getOptions());
if (!subOptions.isEmpty())
last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(subOptions.getFirst().getName())
.parent(last)
.build();
}
return last;
}
}

View File

@ -13,27 +13,28 @@ public class AutocompleteIdentifierConverter implements IdentifierProvider.Conve
@Override
public InteractionIdentifier convert(AutocompleteInteraction context) {
List<SlashCommandInteractionOption> options = context.getOptions();
String commandName = context.getCommandName();
InteractionIdentifier last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(context.getCommandName())
.build();
List<SlashCommandInteractionOption> options = context.getOptions();
if (!options.isEmpty()) {
last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(options.getFirst().getName())
.parent(last)
.build();
List<SlashCommandInteractionOption> subOptions = context.getOptions().getFirst().getOptions();
if (!subOptions.isEmpty())
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName,
options.getFirst().getName(),
subOptions.getFirst().getName());
else
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName,
options.getFirst().getName());
}else
return InteractionIdentifier.createHierarchy(
InteractionType.AUTOCOMPLETE,
commandName);
last = InteractionIdentifier.builder()
.type(InteractionType.AUTOCOMPLETE)
.name(subOptions.getFirst().getName())
.parent(last)
.build();
}
return last;
}
}

View File

@ -13,26 +13,28 @@ public class SlashCommandIdentifierConverter implements IdentifierProvider.Conve
@Override
public InteractionIdentifier convert(SlashCommandInteraction context) {
List<SlashCommandInteractionOption> options = context.getOptions();
String commandName = context.getCommandName();
if (!options.isEmpty()) {
List<SlashCommandInteractionOption> sub_options = context.getOptions().getFirst().getOptions();
if (!sub_options.isEmpty())
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName,
options.getFirst().getName(),
sub_options.getFirst().getName());
else
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName,
options.getFirst().getName());
}else
return InteractionIdentifier.createHierarchy(
InteractionType.COMMAND,
commandName);
InteractionIdentifier last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(context.getCommandName())
.build();
List<SlashCommandInteractionOption> options = context.getOptions();
if (!options.isEmpty()) {
last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(options.getFirst().getName())
.parent(last)
.build();
List<SlashCommandInteractionOption> subOptions = context.getOptions().getFirst().getOptions();
if (!subOptions.isEmpty())
last = InteractionIdentifier.builder()
.type(InteractionType.COMMAND)
.name(subOptions.getFirst().getName())
.parent(last)
.build();
}
return last;
}
}