Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand All @@ -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.");
}
Expand All @@ -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(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,7 @@ public void markUsed(@NotNull QOTWQuestion question) throws DataAccessException
*/
public List<QOTWQuestion> 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<QOTWQuestion> 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);
}

/**
Expand Down
Loading