Search in sources :

Example 1 with Default

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;
}
Also used : Command(dev.triumphteam.cmd.core.Command) NamedArgumentRegistry(dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry) SubcommandData(net.dv8tion.jda.api.interactions.commands.build.SubcommandData) ExecutionProvider(dev.triumphteam.cmd.core.execution.ExecutionProvider) ArgumentRegistry(dev.triumphteam.cmd.core.argument.ArgumentRegistry) MessageRegistry(dev.triumphteam.cmd.core.message.MessageRegistry) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) BaseCommand(dev.triumphteam.cmd.core.BaseCommand) CommandRegistrationException(dev.triumphteam.cmd.core.exceptions.CommandRegistrationException) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData) Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Default(dev.triumphteam.cmd.core.annotation.Default) ChoiceRegistry(dev.triumphteam.cmd.slash.choices.ChoiceRegistry) Registry(dev.triumphteam.cmd.core.registry.Registry) RequirementRegistry(dev.triumphteam.cmd.core.requirement.RequirementRegistry) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull) SenderValidator(dev.triumphteam.cmd.core.sender.SenderValidator) Method(java.lang.reflect.Method) CommandRegistrationException(dev.triumphteam.cmd.core.exceptions.CommandRegistrationException) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData) SubcommandData(net.dv8tion.jda.api.interactions.commands.build.SubcommandData) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Default

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");
    }
}
Also used : Default(dev.triumphteam.cmd.core.annotation.Default)

Aggregations

Default (dev.triumphteam.cmd.core.annotation.Default)2 BaseCommand (dev.triumphteam.cmd.core.BaseCommand)1 Command (dev.triumphteam.cmd.core.Command)1 ArgumentRegistry (dev.triumphteam.cmd.core.argument.ArgumentRegistry)1 NamedArgumentRegistry (dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry)1 CommandRegistrationException (dev.triumphteam.cmd.core.exceptions.CommandRegistrationException)1 ExecutionProvider (dev.triumphteam.cmd.core.execution.ExecutionProvider)1 MessageRegistry (dev.triumphteam.cmd.core.message.MessageRegistry)1 Registry (dev.triumphteam.cmd.core.registry.Registry)1 RequirementRegistry (dev.triumphteam.cmd.core.requirement.RequirementRegistry)1 SenderValidator (dev.triumphteam.cmd.core.sender.SenderValidator)1 ChoiceRegistry (dev.triumphteam.cmd.slash.choices.ChoiceRegistry)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Commands (net.dv8tion.jda.api.interactions.commands.build.Commands)1 SlashCommandData (net.dv8tion.jda.api.interactions.commands.build.SlashCommandData)1