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