use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository in project JavaBot by Java-Discord.
the class JamSubmitSubcommand method getThemeName.
/**
* Determines the name of the Jam theme that the user is making a submission
* for. It is only required that the user specify explicitly the theme they
* are submitting for, when the jam has more than one active theme.
*
* @param con The database connection.
* @param activeJam The jam.
* @param event The event which triggered this method.
* @return The name of the theme.
* @throws SQLException If a database error occurs.
*/
private String getThemeName(Connection con, Jam activeJam, SlashCommandInteractionEvent event) throws SQLException {
List<JamTheme> possibleThemes = new JamThemeRepository(con).getAcceptedThemes(activeJam);
String themeName = null;
if (possibleThemes.size() > 1) {
OptionMapping themeOption = event.getOption("theme");
if (themeOption == null) {
throw new IllegalArgumentException("This Jam has multiple themes. You must specify the theme you're submitting for.");
}
boolean validThemeFound = false;
for (JamTheme theme : possibleThemes) {
if (themeOption.getAsString().equals(theme.getName())) {
themeName = theme.getName();
validThemeFound = true;
break;
}
}
if (!validThemeFound)
throw new IllegalArgumentException("Couldn't find a theme with the given name.");
} else if (possibleThemes.size() == 1) {
themeName = possibleThemes.get(0).getName();
} else {
throw new IllegalStateException("Cannot process submissions when there are no accepted themes.");
}
if (themeName == null) {
throw new IllegalStateException("Could not determine the name of the theme to use for the submission.");
}
return themeName;
}
Aggregations