Search in sources :

Example 6 with OptionData

use of net.dv8tion.jda.api.interactions.commands.build.OptionData in project discord-bot-reddit-java by Glaxier0.

the class GivePermissionCommand method addCommandsToGuild.

private void addCommandsToGuild(Guild guild) {
    CommandListUpdateAction guildCommands = guild.updateCommands();
    guildCommands.addCommands(Commands.slash("play", "Play a song on your voice channel.").addOptions(new OptionData(OptionType.STRING, "query", "Song url or name.").setRequired(true)), Commands.slash("skip", "Skip the current song."), Commands.slash("pause", "Pause the current song."), Commands.slash("resume", "Resume paused song."), Commands.slash("leave", "Make bot leave voice channel."), Commands.slash("queue", "List song queue."), Commands.slash("swap", "Swap order of two songs in queue").addOptions(new OptionData(OptionType.INTEGER, "songnum1", "Song number in the queue to be changed.").setRequired(true), new OptionData(OptionType.INTEGER, "songnum2", "Song number in queue to be changed.").setRequired(true)), Commands.slash("shuffle", "Shuffle the queue."), Commands.slash("mhelp", "Help page for music commands.")).queue();
}
Also used : OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) CommandListUpdateAction(net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction)

Example 7 with OptionData

use of net.dv8tion.jda.api.interactions.commands.build.OptionData in project discord-bot-reddit-java by Glaxier0.

the class Bot method addCommands.

private void addCommands(JDA jda) {
    while (jda.getGuildById(TEST_SERVER) == null) {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    Guild testServer = jda.getGuildById(TEST_SERVER);
    CommandListUpdateAction testServerCommands = testServer.updateCommands();
    CommandListUpdateAction globalCommands = jda.updateCommands();
    testServerCommands.addCommands(// admin commands
    Commands.slash("givepermission", "Give permission to guild").addOptions(new OptionData(OptionType.STRING, "guildid", "Guild id.").setRequired(true), new OptionData(OptionType.STRING, "guildname", "Guild name.").setRequired(false)), Commands.slash("retrievepermission", "Retrieve permission from guild").addOptions(new OptionData(OptionType.STRING, "guildid", "Guild id.").setRequired(true)), Commands.slash("guilds", "Get guild list that bot is in."), Commands.slash("status", "Get reddit post statuses."), Commands.slash("stats", "Get user stats.").addOptions(new OptionData(OptionType.MENTIONABLE, "user", "User with mention.").setRequired(true)), Commands.slash("users", "Get bot users."), Commands.slash("logs", "Get logs."), Commands.slash("getguild", "Get guild id."), Commands.slash("addguild", "Add guild to the premium list.").addOptions(new OptionData(OptionType.STRING, "guildname", "Guild name.").setRequired(true)).addOptions(new OptionData(OptionType.STRING, "guildid", "Guild ID.").setRequired(true)), Commands.slash("removeguild", "Remove guild from premium list.").addOptions(new OptionData(OptionType.STRING, "guildid", "Guild ID.").setRequired(true)), Commands.slash("getguilds", "Get premium guilds."), // Music Commands
    Commands.slash("play", "Play a song on your voice channel.").addOptions(new OptionData(OptionType.STRING, "query", "Song url or name.").setRequired(true)), Commands.slash("skip", "Skip the current song."), Commands.slash("pause", "Pause the current song."), Commands.slash("resume", "Resume paused song."), Commands.slash("leave", "Make bot leave voice channel."), Commands.slash("queue", "List song queue."), Commands.slash("swap", "Swap order of two songs in queue").addOptions(new OptionData(OptionType.INTEGER, "songnum1", "Song number in the queue to be changed.").setRequired(true), new OptionData(OptionType.INTEGER, "songnum2", "Song number in queue to be changed.").setRequired(true)), Commands.slash("shuffle", "Shuffle the queue."), Commands.slash("mhelp", "Help page for music commands.")).queue();
    globalCommands.addCommands(// nsfw commands
    Commands.slash("hentai", "Get random hentai image/gif/video."), Commands.slash("porn", "Get random porn image/gif/video."), // reddit commands
    Commands.slash("unexpected", "Get top r/unexpected posts."), Commands.slash("dankmemes", "Get top r/dankmemes posts."), Commands.slash("memes", "Get top r/memes posts."), Commands.slash("greentext", "Get top r/greentext posts."), Commands.slash("blursedimages", "Get top r/blursedimages posts."), Commands.slash("perfectlycutscreams", "Get top r/perfectlycutscreams posts."), Commands.slash("interestingasfuck", "Get top r/interestingasfuck posts."), Commands.slash("facepalm", "Get top r/facepalm posts."), // test commands
    Commands.slash("help", "Info page about bot commands"), Commands.slash("monke", "Get my favorite random monke video."), Commands.slash("github", "My github page and source code of bot."), Commands.slash("howgay", "Calculate how gay is someone.").addOptions(new OptionData(OptionType.USER, "user", "User to calculate how gay.").setRequired(true)), Commands.slash("errrkek", "Calculate how man is someone.").addOptions(new OptionData(OptionType.USER, "user", "User to calculate how man.").setRequired(true)), Commands.slash("topgg", "Top.gg page of Glaxier bot."), // to-do commands
    Commands.slash("todoadd", "Add a task to your to-do list.").addOptions(new OptionData(OptionType.STRING, "task", "A to-do task.").setRequired(true)), Commands.slash("todolist", "Shows your to-do list."), Commands.slash("todoremove", "Remove a task from your to-do list.").addOptions(new OptionData(OptionType.INTEGER, "taskid", "To-do task id to remove.").setRequired(true)), Commands.slash("todoupdate", "Update a task in your to-do list.").addOptions(new OptionData(OptionType.INTEGER, "taskid", "To-do task id to remove.").setRequired(true), new OptionData(OptionType.STRING, "task", "Updated to-do task.").setRequired(true)), Commands.slash("todocomplete", "Complete a task in your to-do list.").addOptions(new OptionData(OptionType.INTEGER, "taskid", "To-do task id to remove.").setRequired(true)), Commands.slash("todoclear", "Clears your to-do list.")).queue();
}
Also used : OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) CommandListUpdateAction(net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction) Guild(net.dv8tion.jda.api.entities.Guild)

Example 8 with OptionData

use of net.dv8tion.jda.api.interactions.commands.build.OptionData in project triumph-cmds by TriumphTeam.

the class SlashSubCommand method getJdaOptions.

public List<OptionData> getJdaOptions() {
    final List<OptionData> options = new ArrayList<>();
    final List<InternalArgument<S, ?>> internalArguments = getArguments();
    for (int i = 0; i < internalArguments.size(); i++) {
        final InternalArgument<S, ?> internalArgument = internalArguments.get(i);
        final OptionData option = new OptionData(JdaOptionUtil.fromType(internalArgument.getType()), internalArgument.getName(), internalArgument.getDescription(), !internalArgument.isOptional());
        options.add(option);
        final Choice suggestion = getChoice(i);
        if (suggestion instanceof EmptyChoice)
            continue;
        option.addChoices(suggestion.getChoices().stream().map(it -> new Command.Choice(it, it)).limit(25).collect(Collectors.toList()));
    }
    return options;
}
Also used : List(java.util.List) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) AbstractSubCommand(dev.triumphteam.cmd.core.AbstractSubCommand) ExecutionProvider(dev.triumphteam.cmd.core.execution.ExecutionProvider) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) Choice(dev.triumphteam.cmd.slash.choices.Choice) JdaOptionUtil(dev.triumphteam.cmd.slash.util.JdaOptionUtil) InternalArgument(dev.triumphteam.cmd.core.argument.InternalArgument) NotNull(org.jetbrains.annotations.NotNull) Command(net.dv8tion.jda.api.interactions.commands.Command) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) Choice(dev.triumphteam.cmd.slash.choices.Choice) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) InternalArgument(dev.triumphteam.cmd.core.argument.InternalArgument) ArrayList(java.util.ArrayList) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice)

Example 9 with OptionData

use of net.dv8tion.jda.api.interactions.commands.build.OptionData in project Lauren by Yuhtin.

the class CommandRegistry method argsInterpreter.

private void argsInterpreter(CommandInfo handler, CommandDataImpl commandData, SubcommandData subcommandData) {
    for (val option : handler.args()) {
        val split = option.split("-");
        val argName = split[0];
        OptionType optionType;
        if (argName.contains("@"))
            optionType = OptionType.USER;
        else if (argName.contains("%"))
            optionType = OptionType.ROLE;
        else if (argName.contains("#"))
            optionType = OptionType.CHANNEL;
        else if (argName.contains("!"))
            optionType = OptionType.INTEGER;
        else
            optionType = OptionType.STRING;
        val reformatedName = argName.replace("[", "").replace("]", "").replace("!", "").replace("<", "").replace(">", "").replace("@", "").replace("%", "").replace("#", "");
        val optionData = new OptionData(optionType, reformatedName, split[1], argName.contains("<"));
        if (commandData != null)
            commandData.addOptions(optionData);
        if (subcommandData != null)
            subcommandData.addOptions(optionData);
    }
}
Also used : lombok.val(lombok.val) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) OptionType(net.dv8tion.jda.api.interactions.commands.OptionType)

Example 10 with OptionData

use of net.dv8tion.jda.api.interactions.commands.build.OptionData in project Bean by Xirado.

the class CommandsRoute method handle.

@Override
public Object handle(Request request, Response response) throws Exception {
    List<SlashCommand> commands = Bean.getInstance().isDebug() ? Bean.getInstance().getInteractionCommandHandler().getRegisteredGuildCommands().get(DEV_GUILD_ID).stream().filter(cmd -> cmd instanceof SlashCommand).map(cmd -> (SlashCommand) cmd).toList() : Bean.getInstance().getInteractionCommandHandler().getRegisteredSlashCommands();
    DataArray commandArray = DataArray.empty();
    for (SlashCommand command : commands) {
        DataObject commandObject = DataObject.empty();
        SlashCommandData slashCommandData = command.getData();
        DataArray options = DataArray.empty();
        DataArray subCommands = DataArray.empty();
        for (OptionData option : slashCommandData.getOptions()) {
            DataObject optionObject = DataObject.empty().put("name", option.getName()).put("type", option.getType().toString()).put("description", option.getDescription()).put("required", option.isRequired());
            options.add(optionObject);
        }
        for (SubcommandData subcommandData : slashCommandData.getSubcommands()) {
            DataObject subCommandObject = DataObject.empty();
            DataArray subCommandOptions = DataArray.empty();
            for (OptionData option : subcommandData.getOptions()) {
                DataObject optionObject = DataObject.empty().put("name", option.getName()).put("type", option.getType().toString()).put("description", option.getDescription()).put("required", option.isRequired());
                subCommandOptions.add(optionObject);
            }
            subCommandObject.put("name", subcommandData.getName()).put("description", subcommandData.getDescription());
            subCommandObject.put("options", subCommandOptions);
            subCommands.add(subCommandObject);
        }
        commandObject.put("name", slashCommandData.getName()).put("description", slashCommandData.getDescription()).put("options", options).put("sub_commands", subCommands);
        commandArray.add(commandObject);
    }
    return commandArray.toString();
}
Also used : SlashCommand(at.xirado.bean.command.SlashCommand) DataArray(net.dv8tion.jda.api.utils.data.DataArray) List(java.util.List) SubcommandData(net.dv8tion.jda.api.interactions.commands.build.SubcommandData) Request(spark.Request) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) Response(spark.Response) SlashCommand(at.xirado.bean.command.SlashCommand) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Route(spark.Route) Bean(at.xirado.bean.Bean) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData) DataObject(net.dv8tion.jda.api.utils.data.DataObject) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData) DataArray(net.dv8tion.jda.api.utils.data.DataArray) SubcommandData(net.dv8tion.jda.api.interactions.commands.build.SubcommandData)

Aggregations

OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)11 CommandListUpdateAction (net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Guild (net.dv8tion.jda.api.entities.Guild)2 Command (net.dv8tion.jda.api.interactions.commands.Command)2 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)2 SubcommandData (net.dv8tion.jda.api.interactions.commands.build.SubcommandData)2 Bean (at.xirado.bean.Bean)1 SlashCommand (at.xirado.bean.command.SlashCommand)1 AbstractSubCommand (dev.triumphteam.cmd.core.AbstractSubCommand)1 InternalArgument (dev.triumphteam.cmd.core.argument.InternalArgument)1 ExecutionProvider (dev.triumphteam.cmd.core.execution.ExecutionProvider)1 Choice (dev.triumphteam.cmd.slash.choices.Choice)1 EmptyChoice (dev.triumphteam.cmd.slash.choices.EmptyChoice)1 JdaOptionUtil (dev.triumphteam.cmd.slash.util.JdaOptionUtil)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Modifier (java.lang.reflect.Modifier)1 Parameter (java.lang.reflect.Parameter)1 Arrays (java.util.Arrays)1