diff --git a/src/main/java/net/discordjug/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java b/src/main/java/net/discordjug/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java index bfdbe7eaf..5daa66c50 100644 --- a/src/main/java/net/discordjug/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java +++ b/src/main/java/net/discordjug/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java @@ -36,7 +36,7 @@ public ListQuestionsSubcommand(QuestionQueueRepository questionQueueRepository, this.asyncPool = asyncPool; this.questionQueueRepository = questionQueueRepository; setCommandData(new SubcommandData("list", "Show a list of all questions in the queue.") - .addOption(OptionType.INTEGER, "page", "The page of results you get.", false) + .addOption(OptionType.INTEGER, "page", "The page of results you get, starting at 1.", false) ); } @@ -45,7 +45,7 @@ protected InteractionCallbackAction handleCommand(@NotNull SlashCommandIntera OptionMapping pageOption = event.getOption("page"); int page = 0; if (pageOption != null) { - int userPage = (int) pageOption.getAsLong(); + int userPage = (int) pageOption.getAsLong() - 1; if (userPage < 0) { return Responses.warning(event, "Invalid page."); } @@ -57,7 +57,7 @@ protected InteractionCallbackAction handleCommand(@NotNull SlashCommandIntera .setTitle("QOTW Questions Queue") .setColor(Responses.Type.DEFAULT.getColor()); if (questions.isEmpty()) { - embedBuilder.setDescription("There are no questions in the queue."); + embedBuilder.setDescription(page == 0 ? "There are no questions in the queue." : "There are no more questions at that page."); return event.replyEmbeds(embedBuilder.build()); } asyncPool.submit(() -> { diff --git a/src/main/java/net/discordjug/javabot/systems/qotw/dao/QuestionQueueRepository.java b/src/main/java/net/discordjug/javabot/systems/qotw/dao/QuestionQueueRepository.java index fc7d86373..14ebecd95 100644 --- a/src/main/java/net/discordjug/javabot/systems/qotw/dao/QuestionQueueRepository.java +++ b/src/main/java/net/discordjug/javabot/systems/qotw/dao/QuestionQueueRepository.java @@ -105,21 +105,7 @@ public void markUsed(@NotNull QOTWQuestion question) throws DataAccessException */ public List getQuestions(long guildId, int page, int size) throws DataAccessException { return jdbcTemplate.query("SELECT * FROM qotw_question WHERE guild_id = ? AND used = FALSE ORDER BY priority DESC, created_at ASC LIMIT ? OFFSET ?", (rs, row)-> this.read(rs), - guildId, size, page); - } - - /** - * Gets as many questions matching a query as specified. - * @param guildId The current guild's id.. - * @param query The query to match questions against. - * @param page The page. - * @param size The amount of questions to return. - * @return A {@link List} containing the specified amount (or less) of {@link QOTWQuestion} matching the query. - * @throws DataAccessException If an error occurs. - */ - public List getUsedQuestionsWithQuery(long guildId, String query, int page, int size) throws DataAccessException { - return jdbcTemplate.query("SELECT * FROM qotw_question WHERE guild_id = ? AND \"TEXT\" LIKE ? AND used = TRUE ORDER BY question_number DESC, created_at ASC LIMIT ? OFFSET ?", (rs, rows)->this.read(rs), - guildId, "%" + query.toLowerCase() + "%", size, page); + guildId, size, page * size); } /**