Search in sources :

Example 1 with JamThemeRepository

use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository 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");
}
Also used : JamMessageRepository(net.javadiscord.javabot.systems.jam.dao.JamMessageRepository) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 2 with JamThemeRepository

use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository 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);
}
Also used : JamMessageRepository(net.javadiscord.javabot.systems.jam.dao.JamMessageRepository) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 3 with JamThemeRepository

use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository in project JavaBot by Java-Discord.

the class ListThemesSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    List<JamTheme> themes = new JamThemeRepository(con).getThemes(activeJam);
    EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Themes for Jam " + activeJam.getId()).setColor(config.getJamEmbedColor());
    for (JamTheme theme : themes) {
        embedBuilder.addField(theme.getName(), theme.getDescription(), false);
    }
    return event.replyEmbeds(embedBuilder.build()).setEphemeral(true);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 4 with JamThemeRepository

use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository in project JavaBot by Java-Discord.

the class RemoveThemeSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    if (activeJam.getCurrentPhase() == null || !activeJam.getCurrentPhase().equals(JamPhase.THEME_PLANNING)) {
        return Responses.warning(event, "Themes can only be removed during theme planning.");
    }
    JamThemeRepository themeRepository = new JamThemeRepository(con);
    List<JamTheme> themes = themeRepository.getThemes(activeJam);
    for (JamTheme theme : themes) {
        if (theme.getName().equals(Objects.requireNonNull(event.getOption("name")).getAsString())) {
            themeRepository.removeTheme(theme);
            return Responses.success(event, "Theme Removed", "Theme **" + theme.getName() + "** has been removed.");
        }
    }
    return Responses.warning(event, "Theme Not Found", "No theme with that name was found.");
}
Also used : JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Example 5 with JamThemeRepository

use of net.javadiscord.javabot.systems.jam.dao.JamThemeRepository in project JavaBot by Java-Discord.

the class AddThemeSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    OptionMapping nameOption = event.getOption("name");
    OptionMapping descriptionOption = event.getOption("description");
    if (nameOption == null || descriptionOption == null) {
        return Responses.warning(event, "Invalid command arguments.");
    }
    JamThemeRepository themeRepository = new JamThemeRepository(con);
    // First check that we don't have too many themes, and make sure none of them have the same name.
    List<JamTheme> themes = themeRepository.getThemes(activeJam);
    if (themes.size() >= 9) {
        return Responses.warning(event, "Too Many Themes", "Cannot have more than 9 themes. Remove some if you want to add new ones.");
    }
    JamTheme theme = new JamTheme();
    theme.setName(nameOption.getAsString());
    theme.setDescription(descriptionOption.getAsString());
    for (JamTheme existingTheme : themes) {
        if (existingTheme.getName().equals(theme.getName())) {
            return Responses.warning(event, "Theme Already Exists", "There is already a theme with that name.");
        }
    }
    themeRepository.addTheme(activeJam, theme);
    return Responses.success(event, "Theme Added", "Added theme **" + theme.getName() + "** to the jam.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) JamTheme(net.javadiscord.javabot.systems.jam.model.JamTheme) JamThemeRepository(net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)

Aggregations

JamThemeRepository (net.javadiscord.javabot.systems.jam.dao.JamThemeRepository)6 JamTheme (net.javadiscord.javabot.systems.jam.model.JamTheme)6 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)2 JamMessageRepository (net.javadiscord.javabot.systems.jam.dao.JamMessageRepository)2 JamRepository (net.javadiscord.javabot.systems.jam.dao.JamRepository)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1