use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project Utility by anweisen.
the class ISubcommandGroupData method convert.
@Nonnull
public SubcommandGroupData convert() {
SubcommandGroupData data = new SubcommandGroupData(name, " ");
subcommands.forEach(subcommand -> data.addSubcommands(subcommand.convert()));
return data;
}
use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project DIH4JDA by DynxstyGIT.
the class InteractionHandler method getSubcommandGroupData.
/**
* Gets all {@link SubcommandGroupData} (including Subcommands) of a single {@link BaseSlashCommand}.
*
* @param command The base command's instance.
* @param guild The current guild (if available)
* @return All {@link SubcommandGroupData} stored in a List.
* @throws Exception If an error occurs.
*/
private Set<SubcommandGroupData> getSubcommandGroupData(@NotNull BaseSlashCommand command, @Nullable Guild guild) throws Exception {
Set<SubcommandGroupData> groupDataList = new HashSet<>();
for (Class<? extends SubcommandGroup> group : command.getSubcommandGroups()) {
SubcommandGroup instance = (SubcommandGroup) this.getClassInstance(guild, group);
if (instance.getSubcommandGroupData() == null) {
DIH4JDALogger.warn(String.format("Class %s is missing SubcommandGroupData. It will be ignored.", group.getName()));
continue;
}
if (instance.getSubcommands() == null) {
DIH4JDALogger.warn(String.format("SubcommandGroup %s is missing Subcommands. It will be ignored.", instance.getSubcommandGroupData().getName()));
continue;
}
SubcommandGroupData groupData = instance.getSubcommandGroupData();
groupData.addSubcommands(this.getSubcommandData(command, instance.getSubcommands(), groupData.getName(), guild));
groupDataList.add(groupData);
}
return groupDataList;
}
use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project JDA by DV8FromTheWorld.
the class CommandDataTest method testSubcommandGroup.
@Test
public void testSubcommandGroup() {
CommandDataImpl command = new CommandDataImpl("mod", "Moderation commands").addSubcommandGroups(new SubcommandGroupData("ban", "Ban or unban a user from this server").addSubcommands(new SubcommandData("add", "Ban a user from this server").addOption(OptionType.USER, "user", "The user to ban", // required before non-required
true).addOption(OptionType.STRING, "reason", // test that default is false
"The ban reason").addOption(OptionType.INTEGER, "days", "The duration of the ban", // test with explicit false
false)));
DataObject data = command.toData();
Assertions.assertEquals("mod", data.getString("name"));
Assertions.assertEquals("Moderation commands", data.getString("description"));
Assertions.assertTrue(data.getBoolean("default_permission"));
DataObject group = data.getArray("options").getObject(0);
Assertions.assertEquals("ban", group.getString("name"));
Assertions.assertEquals("Ban or unban a user from this server", group.getString("description"));
DataObject subdata = group.getArray("options").getObject(0);
Assertions.assertEquals("add", subdata.getString("name"));
Assertions.assertEquals("Ban a user from this server", subdata.getString("description"));
DataArray options = subdata.getArray("options");
DataObject option = options.getObject(0);
Assertions.assertTrue(option.getBoolean("required"));
Assertions.assertEquals("user", option.getString("name"));
Assertions.assertEquals("The user to ban", option.getString("description"));
option = options.getObject(1);
Assertions.assertFalse(option.getBoolean("required"));
Assertions.assertEquals("reason", option.getString("name"));
Assertions.assertEquals("The ban reason", option.getString("description"));
option = options.getObject(2);
Assertions.assertFalse(option.getBoolean("required"));
Assertions.assertEquals("days", option.getString("name"));
Assertions.assertEquals("The duration of the ban", option.getString("description"));
}
use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project JDA by DV8FromTheWorld.
the class CommandDataTest method testNameChecks.
@Test
public void testNameChecks() {
Assertions.assertThrows(IllegalArgumentException.class, () -> new CommandDataImpl("invalid name", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new CommandDataImpl("invalidName", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new CommandDataImpl("valid_name", ""));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandData("invalid name", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandData("invalidName", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandData("valid_name", ""));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandGroupData("invalid name", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandGroupData("invalidName", "Valid description"));
Assertions.assertThrows(IllegalArgumentException.class, () -> new SubcommandGroupData("valid_name", ""));
}
use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project JDA by DV8FromTheWorld.
the class CommandDataImpl method addSubcommandGroups.
@Nonnull
@Override
public CommandDataImpl addSubcommandGroups(@Nonnull SubcommandGroupData... groups) {
Checks.noneNull(groups, "SubcommandGroups");
if (groups.length == 0)
return this;
checkType(Command.Type.SLASH, "add subcommand groups");
if (!allowGroups)
throw new IllegalArgumentException("You cannot mix options with subcommands/groups.");
Checks.check(groups.length + options.length() <= 25, "Cannot have more than 25 subcommand groups for a command!");
Checks.checkUnique(Stream.concat(getSubcommandGroups().stream(), Arrays.stream(groups)).map(SubcommandGroupData::getName), "Cannot have multiple subcommand groups with the same name. Name: \"%s\" appeared %d times!", (count, value) -> new Object[] { value, count });
allowOption = false;
for (SubcommandGroupData data : groups) options.add(data);
return this;
}
Aggregations