Search in sources :

Example 71 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project Ree6 by Ree6-Applications.

the class Info method onPerform.

@Override
public void onPerform(CommandEvent commandEvent) {
    if (commandEvent.isSlashCommand()) {
        OptionMapping targetOption = commandEvent.getSlashCommandInteractionEvent().getOption("target");
        if (targetOption != null && targetOption.getAsMember() != null) {
            sendInfo(targetOption.getAsMember(), commandEvent);
        } else {
            sendMessage("No User was given to get the Data from!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
        }
    } else {
        if (commandEvent.getArguments().length == 1) {
            if (commandEvent.getMessage().getMentionedMembers().isEmpty()) {
                sendMessage("No User mentioned!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
                sendMessage("Use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "info @user", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
            } else {
                sendInfo(commandEvent.getMessage().getMentionedMembers().get(0), commandEvent);
            }
        } else {
            sendMessage("Not enough Arguments!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
            sendMessage("Use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "info @user", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
        }
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 72 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project Ree6 by Ree6-Applications.

the class Unmute method onPerform.

@Override
public void onPerform(CommandEvent commandEvent) {
    if (commandEvent.getMember().hasPermission(Permission.ADMINISTRATOR)) {
        if (!Main.getInstance().getSqlConnector().getSqlWorker().isMuteSetup(commandEvent.getGuild().getId())) {
            sendMessage("Mute Role hasn't been set!\nTo set it up type " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "setup mute @MuteRole !", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
            return;
        }
        if (commandEvent.isSlashCommand()) {
            OptionMapping targetOption = commandEvent.getSlashCommandInteractionEvent().getOption("target");
            if (targetOption != null) {
                unmuteMember(targetOption.getAsMember(), commandEvent);
            } else {
                sendMessage("No User was given to Unmute!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
            }
        } else {
            if (commandEvent.getArguments().length == 1) {
                if (commandEvent.getMessage().getMentionedMembers().isEmpty()) {
                    sendMessage("No User mentioned!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
                    sendMessage("Use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "unmute @user", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
                } else {
                    unmuteMember(commandEvent.getMessage().getMentionedMembers().get(0), commandEvent);
                }
            } else {
                sendMessage("Not enough Arguments!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
                sendMessage("Use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "unmute @user", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
            }
        }
    } else {
        sendMessage("You dont have the Permission for this Command!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook());
    }
    deleteMessage(commandEvent.getMessage(), commandEvent.getInteractionHook());
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 73 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project MMDBot by MinecraftModDevelopment.

the class CmdForgeVersion method execute.

/**
 * Execute.
 *
 * @param event The {@link SlashCommandEvent CommandEvent} that triggered this Command.
 */
@Override
protected void execute(final SlashCommandEvent event) {
    if (!Utils.checkCommand(this, event)) {
        return;
    }
    MinecraftForgeVersion latest;
    OptionMapping version = event.getOption("version");
    try {
        if (version != null)
            latest = new MinecraftForgeVersion(version.getAsString(), ForgeVersionHelper.getForgeVersionsForMcVersion(version.getAsString()));
        else
            latest = ForgeVersionHelper.getLatestMcVersionForgeVersions();
    } catch (Exception ex) {
        event.reply("Unable to get forge versions.").setEphemeral(true).queue();
        ex.printStackTrace();
        return;
    }
    try {
        final var latestForgeVersion = latest.getForgeVersion();
        final var latestForge = latestForgeVersion.getLatest();
        var recommendedForge = latestForgeVersion.getRecommended();
        if (recommendedForge == null) {
            recommendedForge = "none";
        }
        final var changelogLink = Utils.makeHyperlink("Changelog", String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%1$s-%2$s/forge-%1$s-%2$s-changelog.txt", latest.getMcVersion(), latest.getForgeVersion().getLatest()));
        final var embed = new EmbedBuilder();
        embed.setTitle(String.format("Forge Versions for MC %s", latest.getMcVersion()));
        embed.addField("Latest", latestForge, true);
        embed.addField("Recommended", recommendedForge, true);
        embed.setDescription(changelogLink);
        embed.setColor(Color.ORANGE);
        embed.setTimestamp(Instant.now());
        event.replyEmbeds(embed.build()).mentionRepliedUser(false).queue();
    } catch (NullPointerException e) {
        event.reply("The given Minecraft version " + version.getAsString() + " is invalid.").setEphemeral(true).queue();
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MinecraftForgeVersion(com.mcmoddev.mmdbot.utilities.updatenotifiers.forge.MinecraftForgeVersion)

Example 74 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class AddThemeSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    OptionMapping nameOption = event.getOption("name");
    OptionMapping descriptionOption = event.getOption("description");
    if (nameOption == null || descriptionOption == null) {
        return Responses.warning(event, "Invalid command arguments.");
    }
    JamThemeRepository themeRepository = new JamThemeRepository(con);
    // First check that we don't have too many themes, and make sure none of them have the same name.
    List<JamTheme> themes = themeRepository.getThemes(activeJam);
    if (themes.size() >= 9) {
        return Responses.warning(event, "Too Many Themes", "Cannot have more than 9 themes. Remove some if you want to add new ones.");
    }
    JamTheme theme = new JamTheme();
    theme.setName(nameOption.getAsString());
    theme.setDescription(descriptionOption.getAsString());
    for (JamTheme existingTheme : themes) {
        if (existingTheme.getName().equals(theme.getName())) {
            return Responses.warning(event, "Theme Already Exists", "There is already a theme with that name.");
        }
    }
    themeRepository.addTheme(activeJam, theme);
    return Responses.success(event, "Theme Added", "Added theme **" + theme.getName() + "** to the jam.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 75 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class JamSubmitSubcommand method getThemeName.

/**
 * Determines the name of the Jam theme that the user is making a submission
 * for. It is only required that the user specify explicitly the theme they
 * are submitting for, when the jam has more than one active theme.
 *
 * @param con       The database connection.
 * @param activeJam The jam.
 * @param event     The event which triggered this method.
 * @return The name of the theme.
 * @throws SQLException If a database error occurs.
 */
private String getThemeName(Connection con, Jam activeJam, SlashCommandInteractionEvent event) throws SQLException {
    List<JamTheme> possibleThemes = new JamThemeRepository(con).getAcceptedThemes(activeJam);
    String themeName = null;
    if (possibleThemes.size() > 1) {
        OptionMapping themeOption = event.getOption("theme");
        if (themeOption == null) {
            throw new IllegalArgumentException("This Jam has multiple themes. You must specify the theme you're submitting for.");
        }
        boolean validThemeFound = false;
        for (JamTheme theme : possibleThemes) {
            if (themeOption.getAsString().equals(theme.getName())) {
                themeName = theme.getName();
                validThemeFound = true;
                break;
            }
        }
        if (!validThemeFound)
            throw new IllegalArgumentException("Couldn't find a theme with the given name.");
    } else if (possibleThemes.size() == 1) {
        themeName = possibleThemes.get(0).getName();
    } else {
        throw new IllegalStateException("Cannot process submissions when there are no accepted themes.");
    }
    if (themeName == null) {
        throw new IllegalStateException("Could not determine the name of the theme to use for the submission.");
    }
    return themeName;
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Aggregations

OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)133 CommandException (uwu.narumi.tama.command.CommandException)44 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)12 Member (net.dv8tion.jda.api.entities.Member)8 TextChannel (net.dv8tion.jda.api.entities.TextChannel)8 Guild (net.dv8tion.jda.api.entities.Guild)5 Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)4 User (net.dv8tion.jda.api.entities.User)4 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)4 Message (net.dv8tion.jda.api.entities.Message)3 JamSubmissionRepository (net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Bean (at.xirado.bean.Bean)2 SlashCommand (at.xirado.bean.command.SlashCommand)2 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)2 EmbedUtil (at.xirado.bean.misc.EmbedUtil)2 ApplicationOptionData (com.freya02.botcommands.internal.ApplicationOptionData)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)2 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2