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");
}
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);
}
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);
}
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);
}
Aggregations