Search in sources :

Example 6 with JamRepository

use of net.javadiscord.javabot.systems.jam.dao.JamRepository in project JavaBot by Java-Discord.

the class PlanNewJamSubcommand method createNewJam.

private void createNewJam(InteractionHook hook, long guildId, String name, LocalDate startsAt) {
    try (Connection con = Bot.dataSource.getConnection()) {
        JamRepository jamRepository = new JamRepository(con);
        Jam activeJam = jamRepository.getActiveJam(guildId);
        if (activeJam != null) {
            Responses.warning(hook, "There is already an active Jam (id = `" + activeJam.getId() + "`). Complete that Jam before planning a new one.").queue();
            return;
        }
        Jam jam = new Jam();
        jam.setGuildId(guildId);
        jam.setName(name);
        jam.setStartedBy(hook.getInteraction().getUser().getIdLong());
        jam.setStartsAt(startsAt);
        jam.setCompleted(false);
        jamRepository.saveNewJam(jam);
        Responses.success(hook, "Jam Created", "Jam has been created! *Jam ID = `" + jam.getId() + "`*. Use `/jam info` for more info.").queue();
    } catch (SQLException e) {
        Responses.error(hook, "Error occurred while creating the Jam: " + e.getMessage()).queue();
    }
}
Also used : 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 7 with JamRepository

use of net.javadiscord.javabot.systems.jam.dao.JamRepository in project JavaBot by Java-Discord.

the class ToSubmissionVotingTransition method transition.

@Override
public void transition(Jam jam, SlashCommandInteractionEvent event, JamChannelManager channelManager, Connection con) throws SQLException {
    List<JamSubmission> submissions = new JamSubmissionRepository(con).getSubmissions(jam);
    if (submissions.isEmpty()) {
        throw new IllegalStateException("Cannot start submission voting because there aren't any submissions.");
    }
    JamMessageRepository messageRepository = new JamMessageRepository(con);
    var messageIds = channelManager.sendSubmissionVotingMessage(jam, submissions, event.getJDA());
    for (var entry : messageIds.entrySet()) {
        messageRepository.saveMessageId(jam, entry.getValue(), "submission-" + entry.getKey().getId());
    }
    new JamRepository(con).updateJamPhase(jam, JamPhase.SUBMISSION_VOTING);
}
Also used : JamSubmissionRepository(net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository) JamSubmission(net.javadiscord.javabot.systems.jam.model.JamSubmission) JamMessageRepository(net.javadiscord.javabot.systems.jam.dao.JamMessageRepository) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository)

Example 8 with JamRepository

use of net.javadiscord.javabot.systems.jam.dao.JamRepository in project JavaBot by Java-Discord.

the class CancelSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    OptionMapping confirmOption = event.getOption("confirm");
    if (confirmOption == null || !confirmOption.getAsString().equals("yes")) {
        return Responses.warning(event, "Invalid confirmation. Type `yes` to confirm cancellation.");
    }
    NewsChannel announcementChannel = config.getAnnouncementChannel();
    if (announcementChannel == null)
        throw new IllegalArgumentException("Invalid jam announcement channel id.");
    new JamRepository(con).cancelJam(activeJam);
    announcementChannel.sendMessage("The current Java Jam has been cancelled.").queue();
    return Responses.success(event, "Jam Cancelled", "The " + activeJam.getFullName() + " has been cancelled.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) NewsChannel(net.dv8tion.jda.api.entities.NewsChannel) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository)

Aggregations

JamRepository (net.javadiscord.javabot.systems.jam.dao.JamRepository)8 JamMessageRepository (net.javadiscord.javabot.systems.jam.dao.JamMessageRepository)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Jam (net.javadiscord.javabot.systems.jam.model.Jam)3 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)2 JamSubmissionRepository (net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository)2 JamThemeRepository (net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)2 JamSubmission (net.javadiscord.javabot.systems.jam.model.JamSubmission)2 JamTheme (net.javadiscord.javabot.systems.jam.model.JamTheme)2 NewsChannel (net.dv8tion.jda.api.entities.NewsChannel)1