use of net.javadiscord.javabot.systems.jam.dao.JamRepository in project JavaBot by Java-Discord.
the class ActiveJamSubcommand method handleSlashCommandInteraction.
@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) {
if (event.getGuild() == null) {
return Responses.warning(event, "This command can only be used in a guild.");
}
try (Connection con = Bot.dataSource.getConnection()) {
con.setAutoCommit(false);
Jam activeJam = new JamRepository(con).getActiveJam(event.getGuild().getIdLong());
if (activeJam == null) {
return Responses.warning(event, "No Active Jam", "There is currently no active jam in this guild.");
}
try {
var reply = this.handleJamCommand(event, activeJam, con, Bot.config.get(event.getGuild()).getJam());
con.commit();
return reply;
} catch (SQLException e) {
con.rollback();
log.warn("Exception thrown while handling Jam command: {}", e.getMessage());
return Responses.error(event, "An error occurred:\n```" + e.getMessage() + "```");
}
} catch (SQLException e) {
e.printStackTrace();
return Responses.error(event, "An SQL error occurred.");
}
}
use of net.javadiscord.javabot.systems.jam.dao.JamRepository 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.JamRepository 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.JamRepository 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;
}
use of net.javadiscord.javabot.systems.jam.dao.JamRepository 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);
}
Aggregations