Search in sources :

Example 1 with QOTWQuestion

use of net.javadiscord.javabot.systems.qotw.model.QOTWQuestion in project JavaBot by Java-Discord.

the class AddQuestionSubcommand method handleCommand.

@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
    QOTWQuestion question = new QOTWQuestion();
    question.setGuildId(guildId);
    question.setCreatedBy(event.getUser().getIdLong());
    question.setPriority(0);
    OptionMapping textOption = event.getOption("question");
    if (textOption == null) {
        return Responses.warning(event, "Missing required arguments.");
    }
    String text = textOption.getAsString();
    if (text.isBlank() || text.length() > 1024) {
        return Responses.warning(event, "Invalid question text. Must not be blank, and must be less than 1024 characters.");
    }
    question.setText(text);
    OptionMapping priorityOption = event.getOption("priority");
    if (priorityOption != null) {
        question.setPriority((int) priorityOption.getAsLong());
    }
    new QuestionQueueRepository(con).save(question);
    return Responses.success(event, "Question Added", "Your question has been added to the queue. Its id is `" + question.getId() + "`.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) QOTWQuestion(net.javadiscord.javabot.systems.qotw.model.QOTWQuestion) QuestionQueueRepository(net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository)

Aggregations

OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)1 QuestionQueueRepository (net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository)1 QOTWQuestion (net.javadiscord.javabot.systems.qotw.model.QOTWQuestion)1