Search in sources :

Example 21 with OptionMapping

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

the class JamInfoSubcommand method fetchJam.

private Jam fetchJam(SlashCommandInteractionEvent event) {
    Jam jam;
    try (Connection con = Bot.dataSource.getConnection()) {
        JamRepository jamRepository = new JamRepository(con);
        OptionMapping idOption = event.getOption("id");
        if (idOption == null) {
            if (event.getGuild() == null) {
                throw new RuntimeException("Cannot find active Jam without Guild context.");
            }
            jam = jamRepository.getActiveJam(event.getGuild().getIdLong());
        } else {
            jam = jamRepository.getJam(idOption.getAsLong());
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException("Error occurred while fetching the Jam info.", e);
    }
    return jam;
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) SQLException(java.sql.SQLException) Jam(net.javadiscord.javabot.systems.jam.model.Jam) Connection(java.sql.Connection) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository)

Example 22 with OptionMapping

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

the class EditJamSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    OptionMapping propertyNameOption = event.getOption("property");
    OptionMapping propertyValueOption = event.getOption("value");
    if (propertyNameOption == null || propertyValueOption == null) {
        return Responses.warning(event, "Missing required arguments.");
    }
    String value = propertyValueOption.getAsString();
    if (value.equalsIgnoreCase("null")) {
        value = null;
    }
    var propertyHandler = propertyHandlers.get(propertyNameOption.getAsString().toLowerCase());
    if (propertyHandler == null) {
        return Responses.warning(event, "Unsupported Property", "Only the following properties may be updated: " + String.join(", ", propertyHandlers.keySet()));
    }
    return propertyHandler.updateProperty(event, con, activeJam, value);
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 23 with OptionMapping

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

the class PlanNewJamSubcommand method handleSlashCommandInteraction.

@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) {
    OptionMapping startOption = event.getOption("start-date");
    if (startOption == null) {
        return Responses.warning(event, "Missing start date.");
    }
    LocalDate startsAt;
    try {
        startsAt = LocalDate.parse(startOption.getAsString(), DateTimeFormatter.ofPattern("dd-MM-yyyy"));
    } catch (DateTimeParseException e) {
        return Responses.warning(event, "Invalid start date. Must be formatted as `dd-MM-yyyy`. For example, June 5th, 2017 is formatted as `05-06-2017`.");
    }
    if (startsAt.isBefore(LocalDate.now())) {
        return Responses.warning(event, "Invalid start date. The Jam cannot start in the past.");
    }
    long guildId = Objects.requireNonNull(event.getGuild()).getIdLong();
    String name = null;
    OptionMapping nameOption = event.getOption("name");
    if (nameOption != null) {
        name = nameOption.getAsString();
    }
    // So we can pass the variable in the lambda expression.
    final String nameFinal = name;
    Bot.asyncPool.submit(() -> this.createNewJam(event.getHook(), guildId, nameFinal, startsAt));
    return event.deferReply();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) DateTimeParseException(java.time.format.DateTimeParseException) LocalDate(java.time.LocalDate)

Example 24 with OptionMapping

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

the class WarnsCommand method handleSlashCommandInteraction.

@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) throws ResponseException {
    OptionMapping warnsOption = event.getOption("user");
    Member member = warnsOption == null ? event.getMember() : warnsOption.getAsMember();
    if (member == null)
        return Responses.error(event, "Member is missing.");
    LocalDateTime cutoff = LocalDateTime.now().minusDays(Bot.config.get(event.getGuild()).getModeration().getWarnTimeoutDays());
    try (var con = Bot.dataSource.getConnection()) {
        return event.replyEmbeds(buildWarnsEmbed(new WarnRepository(con).getWarnsByUserId(member.getIdLong(), cutoff), member));
    } catch (SQLException e) {
        throw ResponseException.error("Could not get warns from user: " + member.getUser().getAsTag(), e);
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) LocalDateTime(java.time.LocalDateTime) SQLException(java.sql.SQLException) Member(net.dv8tion.jda.api.entities.Member) WarnRepository(net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository)

Example 25 with OptionMapping

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

the class RemoveQuestionSubcommand method handleCommand.

@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
    OptionMapping idOption = event.getOption("id");
    if (idOption == null) {
        return Responses.warning(event, "Missing required arguments.");
    }
    long id = idOption.getAsLong();
    boolean removed = new QuestionQueueRepository(con).removeQuestion(guildId, id);
    if (removed) {
        return Responses.success(event, "Question Removed", "The question with id `" + id + "` has been removed.");
    } else {
        return Responses.warning(event, "Could not remove question with id `" + id + "`. Are you sure it exists?");
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) QuestionQueueRepository(net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository)

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