use of net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository in project JavaBot by Java-Discord.
the class JamSubmitSubcommand method handleJamCommand.
@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
if (!activeJam.submissionsAllowed()) {
return Responses.warning(event, "Submissions Not Permitted", "The Jam is not currently accepting submissions.");
}
OptionMapping sourceLinkOption = event.getOption("link");
OptionMapping descriptionOption = event.getOption("description");
if (sourceLinkOption == null || descriptionOption == null) {
return Responses.warning(event, "Missing required arguments.");
}
String link = sourceLinkOption.getAsString();
if (!this.validateLink(link)) {
return Responses.warning(event, "Invalid Source", "The source link you provide must lead to a valid web page.");
}
JamSubmission submission = new JamSubmission();
submission.setUserId(event.getUser().getIdLong());
submission.setJam(activeJam);
submission.setThemeName(this.getThemeName(con, activeJam, event));
submission.setSourceLink(link);
submission.setDescription(descriptionOption.getAsString());
new JamSubmissionRepository(con).saveSubmission(submission);
return Responses.success(event, "Submission Received", "Thank you for your submission to the Jam.");
}
use of net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository in project JavaBot by Java-Discord.
the class ListSubmissionsSubcommand method handleJamCommand.
@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
OptionMapping pageOption = event.getOption("page");
OptionMapping userOption = event.getOption("user");
int page = 1;
if (pageOption != null) {
page = (int) pageOption.getAsLong();
}
Long userId = null;
if (userOption != null) {
userId = userOption.getAsUser().getIdLong();
}
List<JamSubmission> submissions = new JamSubmissionRepository(con).getSubmissions(activeJam, page, userId);
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Submissions").setColor(config.getJamEmbedColor());
for (JamSubmission sub : submissions) {
User user = event.getJDA().getUserById(sub.getUserId());
String userName = user == null ? "Unknown user" : user.getAsTag();
String timestamp = sub.getCreatedAt().format(DateTimeFormatter.ofPattern("dd MMMM yyyy, HH:mm:ss 'UTC'"));
embedBuilder.addField(String.format("`%d` %s at %s", sub.getId(), userName, timestamp), "Link: *" + sub.getSourceLink() + "*\n> " + sub.getDescription(), false);
}
embedBuilder.setFooter("Page " + page + ", up to 10 items per page");
return event.replyEmbeds(embedBuilder.build()).setEphemeral(true);
}
use of net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository in project JavaBot by Java-Discord.
the class RemoveSubmissionsSubcommand method handleJamCommand.
@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
OptionMapping idOption = event.getOption("id");
OptionMapping userOption = event.getOption("user");
if (idOption == null && userOption == null) {
return Responses.warning(event, "Either a submission id or user must be provided.");
}
if (idOption != null && userOption != null) {
return Responses.warning(event, "Provide only a submission id or user, not both.");
}
JamSubmissionRepository submissionRepository = new JamSubmissionRepository(con);
int removed;
if (idOption != null) {
removed = submissionRepository.removeSubmission(activeJam, idOption.getAsLong());
} else {
removed = submissionRepository.removeSubmissions(activeJam, userOption.getAsUser().getIdLong());
}
return Responses.success(event, "Submissions Removed", "Removed " + removed + " submissions from the " + activeJam.getFullName() + ".");
}
use of net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository 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.JamSubmissionRepository 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