use of dev.triumphteam.cmd.core.annotation.Default in project triumph-cmds by TriumphTeam.
the class SlashCommand method asCommandData.
@NotNull
public SlashCommandData asCommandData() {
final SlashCommandData commandData = Commands.slash(name, description);
commandData.setDefaultEnabled(enabledRoles.isEmpty());
if (isDefault) {
final SlashSubCommand<S> subCommand = getDefaultSubCommand();
// Should never be null.
if (subCommand == null)
throw new CommandRegistrationException("Could not find default subcommand");
commandData.addOptions(subCommand.getJdaOptions());
return commandData;
}
final List<SubcommandData> subData = subCommands.entrySet().stream().map(entry -> new SubcommandData(entry.getKey(), entry.getValue().getDescription()).addOptions(entry.getValue().getJdaOptions())).collect(Collectors.toList());
commandData.addSubcommands(subData);
return commandData;
}
use of dev.triumphteam.cmd.core.annotation.Default in project triumph-cmds by TriumphTeam.
the class AbstractSubCommandProcessor method extractSubCommandNames.
/**
* Extracts the data from the method to retrieve the sub command name or the default name.
*/
private void extractSubCommandNames() {
final Default defaultAnnotation = method.getAnnotation(Default.class);
final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = method.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class);
if (defaultAnnotation == null && subCommandAnnotation == null) {
return;
}
if (defaultAnnotation != null) {
name = Default.DEFAULT_CMD_NAME;
alias.addAll(Arrays.stream(defaultAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList()));
isDefault = true;
return;
}
name = subCommandAnnotation.value().toLowerCase();
alias.addAll(Arrays.stream(subCommandAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList()));
if (this.name.isEmpty()) {
throw createException("@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty");
}
}
Aggregations