Compare commits
No commits in common. "9058629af59c6aff1fa499d69367edb145ca9b14" and "5d8f7374819f8493bf371564fba5153c37692b71" have entirely different histories.
9058629af5
...
5d8f737481
@ -51,33 +51,21 @@ public class SlashCommandDefinition {
|
|||||||
subCommandGroupMap.put(x.name(), x);
|
subCommandGroupMap.put(x.name(), x);
|
||||||
});
|
});
|
||||||
|
|
||||||
return subCommandGroupMap.values().toArray(SubCommandGroup[]::new);
|
return subCommandGroupMap.values().toArray(new SubCommandGroup[0]);
|
||||||
}
|
|
||||||
|
|
||||||
public SubCommand[] getSubCommands() {
|
|
||||||
List<SubCommand> subCommands;
|
|
||||||
subCommands = Arrays.stream(getExecutableDefinitons())
|
|
||||||
.filter((x) -> x.subCommandGroup() == null && x.subCommand() != null)
|
|
||||||
.map((x) -> x.subCommand())
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
|
|
||||||
HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
|
||||||
subCommands.forEach((x) -> {
|
|
||||||
SubCommand current = subCommandMap.get(x.name());
|
|
||||||
if (current == null || (current.description().isBlank() && !x.description().isBlank()))
|
|
||||||
subCommandMap.put(x.name(), x);
|
|
||||||
});
|
|
||||||
|
|
||||||
return subCommandMap.values().toArray(SubCommand[]::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCommand[] getSubCommands(String groupName) {
|
public SubCommand[] getSubCommands(String groupName) {
|
||||||
List<SubCommand> subCommands;
|
List<SubCommand> subCommands;
|
||||||
subCommands = Arrays.stream(getExecutableDefinitons())
|
if (groupName == null)
|
||||||
.filter((x) -> x.subCommandGroup().name().equals(groupName) && x.subCommand() != null)
|
subCommands = Arrays.stream(getExecutableDefinitons())
|
||||||
.map((x) -> x.subCommand())
|
.filter((x) -> x.subCommandGroup() == null && x.subCommand() != null)
|
||||||
.toList();
|
.map((x) -> x.subCommand())
|
||||||
|
.toList();
|
||||||
|
else
|
||||||
|
subCommands = Arrays.stream(getExecutableDefinitons())
|
||||||
|
.filter((x) -> x.subCommandGroup().name().equals(groupName) && x.subCommand() != null)
|
||||||
|
.map((x) -> x.subCommand())
|
||||||
|
.toList();
|
||||||
|
|
||||||
HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
||||||
subCommands.forEach((x) -> {
|
subCommands.forEach((x) -> {
|
||||||
@ -86,7 +74,18 @@ public class SlashCommandDefinition {
|
|||||||
subCommandMap.put(x.name(), x);
|
subCommandMap.put(x.name(), x);
|
||||||
});
|
});
|
||||||
|
|
||||||
return subCommandMap.values().toArray(SubCommand[]::new);
|
return subCommandMap.values().toArray(new SubCommand[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlashCommand getFullSlashCommand() {
|
||||||
|
if (isRootCommand())
|
||||||
|
return getSlashCommand();
|
||||||
|
for (ExecutableSlashCommandDefinition executableSlashCommandDefinition : executableDefinitons) {
|
||||||
|
if (executableSlashCommandDefinition.options().length > 0)
|
||||||
|
return executableSlashCommandDefinition.applicationCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlashCommand getSlashCommand() {
|
public SlashCommand getSlashCommand() {
|
||||||
|
@ -81,8 +81,8 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
|
|
||||||
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
||||||
ApplicationCommandRequest request = convertSlashCommand(slashCommandDefinition);
|
ApplicationCommandRequest request = convertSlashCommand(slashCommandDefinition);
|
||||||
if (slashCommandDefinition.getSlashCommand().serverIds().length > 0) {
|
if (slashCommandDefinition.getFullSlashCommand().serverIds().length > 0) {
|
||||||
for (long serverId : slashCommandDefinition.getSlashCommand().serverIds()) {
|
for (long serverId : slashCommandDefinition.getFullSlashCommand().serverIds()) {
|
||||||
serverCommands.putIfAbsent(serverId, new ArrayList<>());
|
serverCommands.putIfAbsent(serverId, new ArrayList<>());
|
||||||
serverCommands.get(serverId).add(request);
|
serverCommands.get(serverId).add(request);
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
|
|
||||||
private ApplicationCommandRequest convertSlashCommand(SlashCommandDefinition def) {
|
private ApplicationCommandRequest convertSlashCommand(SlashCommandDefinition def) {
|
||||||
List<ApplicationCommandOptionData> options = new ArrayList<>();
|
List<ApplicationCommandOptionData> options = new ArrayList<>();
|
||||||
SlashCommand cmd = def.getSlashCommand();
|
SlashCommand cmd = def.getFullSlashCommand();
|
||||||
if (!def.isRootCommand()) {
|
if (!def.isRootCommand()) {
|
||||||
Arrays.stream(def.getSubCommands(null)).map(this::convertSubCommandDef).forEach(options::add);
|
Arrays.stream(def.getSubCommands(null)).map(this::convertSubCommandDef).forEach(options::add);
|
||||||
Arrays.stream(def.getSubCommandGroups()).map((x) -> convertSubCommandGroupDef(def, x)).forEach(options::add);
|
Arrays.stream(def.getSubCommandGroups()).map((x) -> convertSubCommandGroupDef(def, x)).forEach(options::add);
|
||||||
@ -191,7 +191,6 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
builder.value(choice.doubleValue());
|
builder.value(choice.doubleValue());
|
||||||
if (!choice.stringValue().isEmpty())
|
if (!choice.stringValue().isEmpty())
|
||||||
builder.value(choice.stringValue());
|
builder.value(choice.stringValue());
|
||||||
convertedChoices.add(builder.build());
|
|
||||||
}
|
}
|
||||||
return convertedChoices;
|
return convertedChoices;
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
Set<SlashCommandBuilder> globalCommands = new HashSet<>();
|
Set<SlashCommandBuilder> globalCommands = new HashSet<>();
|
||||||
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
||||||
SlashCommandBuilder builder = convertSlashCommand(slashCommandDefinition);
|
SlashCommandBuilder builder = convertSlashCommand(slashCommandDefinition);
|
||||||
if (slashCommandDefinition.getSlashCommand().serverIds().length > 0) {
|
if (slashCommandDefinition.getFullSlashCommand().serverIds().length > 0) {
|
||||||
for (long serverId : slashCommandDefinition.getSlashCommand().serverIds()) {
|
for (long serverId : slashCommandDefinition.getFullSlashCommand().serverIds()) {
|
||||||
serverCommands.putIfAbsent(serverId, new HashSet<>());
|
serverCommands.putIfAbsent(serverId, new HashSet<>());
|
||||||
serverCommands.get(serverId).add(builder);
|
serverCommands.get(serverId).add(builder);
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
|
|
||||||
private SlashCommandBuilder convertSlashCommand(SlashCommandDefinition def) {
|
private SlashCommandBuilder convertSlashCommand(SlashCommandDefinition def) {
|
||||||
List<org.javacord.api.interaction.SlashCommandOption> options = new ArrayList<>();
|
List<org.javacord.api.interaction.SlashCommandOption> options = new ArrayList<>();
|
||||||
SlashCommand cmd = def.getSlashCommand();
|
SlashCommand cmd = def.getFullSlashCommand();
|
||||||
if (!def.isRootCommand()) {
|
if (!def.isRootCommand()) {
|
||||||
Arrays.stream(def.getSubCommands(null)).map(this::convertSubCommandDef).forEach(options::add);
|
Arrays.stream(def.getSubCommands(null)).map(this::convertSubCommandDef).forEach(options::add);
|
||||||
Arrays.stream(def.getSubCommandGroups()).map((x) -> convertSubCommandGroupDef(def, x)).forEach(options::add);
|
Arrays.stream(def.getSubCommandGroups()).map((x) -> convertSubCommandGroupDef(def, x)).forEach(options::add);
|
||||||
@ -164,7 +164,6 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
*/
|
*/
|
||||||
if (!choice.stringValue().isEmpty())
|
if (!choice.stringValue().isEmpty())
|
||||||
builder.setValue(choice.stringValue());
|
builder.setValue(choice.stringValue());
|
||||||
convertedChoices.add(builder.build());
|
|
||||||
}
|
}
|
||||||
return convertedChoices;
|
return convertedChoices;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user