Skip to content
Merged
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 @@ -12,6 +12,7 @@

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

Expand All @@ -22,8 +23,8 @@
* use. Meant to be used once a question has been resolved.
*/
public final class CloseCommand extends SlashCommandAdapter {
private static final int COOLDOWN_DURATION_VALUE = 1;
private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.HOURS;
private static final int COOLDOWN_DURATION_VALUE = 30;
private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES;

private final HelpSystemHelper helper;
private final Cache<Long, Instant> helpThreadIdToLastClose;
Expand Down Expand Up @@ -58,8 +59,9 @@ public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {

if (isHelpThreadOnCooldown(helpThread)) {
event
.reply("Please wait a bit, this command can only be used once per %d %s."
.formatted(COOLDOWN_DURATION_VALUE, COOLDOWN_DURATION_UNIT))
.reply("Please wait a bit, this command can only be used once per %d %s.".formatted(
COOLDOWN_DURATION_VALUE,
COOLDOWN_DURATION_UNIT.toString().toLowerCase(Locale.US)))
.setEphemeral(true)
.queue();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public final class HelpSystemHelper {
private static final String CODE_SYNTAX_EXAMPLE_PATH = "codeSyntaxExample.png";
private static final String CATEGORY_GROUP = "category";
private static final String TITLE_GROUP = "title";
private static final Pattern EXTRACT_CATEGORY_TITLE_PATTERN =
Pattern.compile("(?:\\[(?<%s>.+)] )?(?<%s>.+)".formatted(CATEGORY_GROUP, TITLE_GROUP));
private static final Pattern EXTRACT_CATEGORY_TITLE_PATTERN = Pattern
.compile("(?:\\[(?<%s>[^\\[]+)] )?(?<%s>.+)".formatted(CATEGORY_GROUP, TITLE_GROUP));

private static final Pattern TITLE_COMPACT_REMOVAL_PATTERN = Pattern.compile("\\W");
static final int TITLE_COMPACT_LENGTH_MIN = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.togetherjava.tjbot.commands.help;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.requests.RestAction;
Expand Down Expand Up @@ -31,7 +31,7 @@
public final class HelpThreadOverviewUpdater extends MessageReceiverAdapter implements Routine {
private static final Logger logger = LoggerFactory.getLogger(HelpThreadOverviewUpdater.class);

private static final String STATUS_TITLE = "Active questions";
private static final String STATUS_TITLE = "## __**Active questions**__ ##";
private static final int OVERVIEW_QUESTION_LIMIT = 150;

private final HelpSystemHelper helper;
Expand Down Expand Up @@ -131,19 +131,18 @@ private void updateOverview(@NotNull IThreadContainer stagingChannel,

logger.debug("Found {} active questions", activeThreads.size());

MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE)
.setDescription(createDescription(activeThreads))
.setColor(HelpSystemHelper.AMBIENT_COLOR)
Message message = new MessageBuilder()
.setContent(STATUS_TITLE + "\n\n" + createDescription(activeThreads))
.build();

getStatusMessage(overviewChannel).flatMap(maybeStatusMessage -> {
logger.debug("Sending the updated question overview");
if (maybeStatusMessage.isEmpty()) {
return overviewChannel.sendMessageEmbeds(embed);
return overviewChannel.sendMessage(message);
}

String statusMessageId = maybeStatusMessage.orElseThrow().getId();
return overviewChannel.editMessageEmbedsById(statusMessageId, embed);
return overviewChannel.editMessageById(statusMessageId, message);
}).queue();
}

Expand Down Expand Up @@ -186,13 +185,8 @@ private static boolean isStatusMessage(@NotNull Message message) {
return false;
}

List<MessageEmbed> embeds = message.getEmbeds();
if (embeds.isEmpty()) {
return false;
}

MessageEmbed embed = embeds.get(0);
return STATUS_TITLE.equals(embed.getTitle());
String content = message.getContentRaw();
return content.startsWith(STATUS_TITLE);
}

private enum ChannelType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public final class ImplicitAskListener extends MessageReceiverAdapter {
private static final Logger logger = LoggerFactory.getLogger(ImplicitAskListener.class);

private static final int TITLE_MAX_LENGTH = 30;
private static final int TITLE_MAX_LENGTH = 50;

private static final int COOLDOWN_DURATION_VALUE = 15;
private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.SECONDS;
Expand Down