Search in sources :

Example 1 with JamMessageRepository

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

the class ToSubmissionTransition method transition.

@Override
public void transition(Jam jam, SlashCommandInteractionEvent event, JamChannelManager channelManager, Connection con) throws SQLException {
    JamMessageRepository messageRepository = new JamMessageRepository(con);
    List<JamTheme> themes = new JamThemeRepository(con).getThemes(jam);
    long themeVotingMessageId = messageRepository.getMessageId(jam, "theme_voting");
    var votes = channelManager.getThemeVotes(themeVotingMessageId, themes);
    var voteCounts = this.recordAndCountVotes(jam, votes, con);
    JamTheme winningTheme = this.determineWinner(voteCounts);
    if (winningTheme == null) {
        throw new IllegalStateException("No winning jam theme could be found.");
    }
    this.updateThemesAcceptedState(themes, winningTheme, con);
    channelManager.sendChosenThemeMessage(voteCounts, winningTheme);
    new JamRepository(con).updateJamPhase(jam, JamPhase.SUBMISSION);
    messageRepository.removeMessageId(jam, "theme_voting");
}
Also used : JamMessageRepository(net.javadiscord.javabot.systems.jam.dao.JamMessageRepository) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 2 with JamMessageRepository

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

the class ToThemeVotingTransition method transition.

@Override
public void transition(Jam jam, SlashCommandInteractionEvent event, JamChannelManager channelManager, Connection con) throws SQLException {
    List<JamTheme> themes = new JamThemeRepository(con).getThemes(jam);
    if (themes.isEmpty()) {
        throw new IllegalStateException("Cannot start theme voting until at least one theme is available.");
    }
    long votingMessageId = channelManager.sendThemeVotingMessages(jam, themes);
    new JamMessageRepository(con).saveMessageId(jam, votingMessageId, "theme_voting");
    new JamRepository(con).updateJamPhase(jam, JamPhase.THEME_VOTING);
}
Also used : JamMessageRepository(net.javadiscord.javabot.systems.jam.dao.JamMessageRepository) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 3 with JamMessageRepository

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

the class ToCompletionTransition method transition.

@Override
public void transition(Jam jam, SlashCommandInteractionEvent event, JamChannelManager channelManager, Connection con) throws SQLException {
    JamMessageRepository messageRepository = new JamMessageRepository(con);
    List<JamSubmission> submissions = new JamSubmissionRepository(con).getSubmissions(jam);
    var votes = channelManager.getSubmissionVotes(this.getSubmissionMessageIds(submissions, messageRepository));
    var voteCounts = this.recordAndCountVotes(votes, con, messageRepository);
    var winningSubmissions = this.determineWinners(voteCounts);
    if (winningSubmissions.isEmpty()) {
        channelManager.sendNoWinnersMessage();
    } else if (winningSubmissions.size() == 1) {
        channelManager.sendSingleWinnerMessage(winningSubmissions.get(0), voteCounts, event);
    } else {
        channelManager.sendMultipleWinnersMessage(winningSubmissions, voteCounts, event);
    }
    new JamRepository(con).completeJam(jam);
}
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 4 with JamMessageRepository

use of net.javadiscord.javabot.systems.jam.dao.JamMessageRepository 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)

Aggregations

JamMessageRepository (net.javadiscord.javabot.systems.jam.dao.JamMessageRepository)4 JamRepository (net.javadiscord.javabot.systems.jam.dao.JamRepository)4 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