Skip to content

Commit

Permalink
Rename SlashCommandInteractionOptionsProvider methods that are only u…
Browse files Browse the repository at this point in the history
…sable if they get arguments from getOption* to getArgument* and changed the implementation to get the arguments instead
  • Loading branch information
felldo committed Oct 30, 2022
1 parent 68752f3 commit 3164d9c
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 143 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {
`java-library`
`maven-publish`
signing
id("com.github.johnrengelman.shadow") version "2.0.4" apply false
id("net.researchgate.release") version "2.7.0" apply false
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
id("net.researchgate.release") version "3.0.2" apply false
}

repositories {
Expand Down
4 changes: 2 additions & 2 deletions javacord-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import java.time.Instant

plugins {
`java-library`
id("com.gorylenko.gradle-git-properties") version "2.4.0"
id("biz.aQute.bnd.builder") version "6.2.0"
id("com.gorylenko.gradle-git-properties") version "2.4.1"
id("biz.aQute.bnd.builder") version "6.3.1"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
package org.javacord.api.interaction;

import java.util.List;

public interface SlashCommandInteraction extends ApplicationCommandInteraction, SlashCommandInteractionOptionsProvider {

/**
* Gets the arguments of this slash command if there are any.
*
* <p>This is a shorthand method to avoid checking for Subcommmands or SubcommandGroups
* to get the slash command arguments.
*
* @return The argument options.
*/
List<SlashCommandInteractionOption> getArguments();

/**
* Gets the full command name of this slash command including the name of the Subcommand and SubcommandGroup.
*
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javacord-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import aQute.bnd.version.MavenVersion.parseMavenString

plugins {
`java-library`
id("biz.aQute.bnd.builder") version "6.2.0"
id("biz.aQute.bnd.builder") version "6.3.1"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public String getCommandName() {
return commandName;
}

// TODO: Move the implementation to the SlashCommandInteractionOptionsProvider once we upgraded to Java 9+
// because interfaces currently do not support private methods
@Override
public List<SlashCommandInteractionOption> getArguments() {
return getArgumentsRecursive(getOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,21 @@ public Optional<CompletableFuture<Mentionable>> requestMentionableValue() {
public List<SlashCommandInteractionOption> getOptions() {
return Collections.unmodifiableList(options);
}

// TODO: Move the implementation to the SlashCommandInteractionOptionsProvider once we upgraded to Java 9+
// because interfaces currently do not support private methods
@Override
public List<SlashCommandInteractionOption> getArguments() {
return getArgumentsRecursive(getOptions());
}

private List<SlashCommandInteractionOption> getArgumentsRecursive(List<SlashCommandInteractionOption> options) {
if (options.isEmpty()) {
return Collections.emptyList();
} else if (options.get(0).isSubcommandOrGroup()) {
return getArgumentsRecursive(options.get(0).getOptions());
} else {
return options;
}
}
}

0 comments on commit 3164d9c

Please sign in to comment.