diff --git a/application/src/main/java/org/togetherjava/tjbot/Application.java b/application/src/main/java/org/togetherjava/tjbot/Application.java
index 2d9490bf64..b6efebddd0 100644
--- a/application/src/main/java/org/togetherjava/tjbot/Application.java
+++ b/application/src/main/java/org/togetherjava/tjbot/Application.java
@@ -7,6 +7,7 @@
import net.dv8tion.jda.api.requests.GatewayIntent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Features;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.system.BotCore;
diff --git a/application/src/main/java/org/togetherjava/tjbot/CommandReloading.java b/application/src/main/java/org/togetherjava/tjbot/CommandReloading.java
index 54108595ae..36ce0388d7 100644
--- a/application/src/main/java/org/togetherjava/tjbot/CommandReloading.java
+++ b/application/src/main/java/org/togetherjava/tjbot/CommandReloading.java
@@ -7,6 +7,7 @@
import org.jetbrains.annotations.Contract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.BotCommand;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.system.CommandProvider;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/BotCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/BotCommand.java
index cc923af08f..0bd53a32b7 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/BotCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/BotCommand.java
@@ -2,7 +2,6 @@
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
-import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import java.util.List;
@@ -25,16 +24,6 @@
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
*/
public interface BotCommand extends UserInteractor {
-
- /**
- * Gets the type of this command.
- *
- * After registration of the command, the type must not change anymore.
- *
- * @return the type of the command
- */
- Command.Type getType();
-
/**
* Gets the visibility of this command.
*
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java b/application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java
index 3a5e5af1f3..c9c4a52dbb 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java
@@ -6,11 +6,11 @@
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import org.jetbrains.annotations.Contract;
-import org.togetherjava.tjbot.commands.componentids.ComponentId;
+
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
+import org.togetherjava.tjbot.commands.componentids.ComponentIdInteractor;
import org.togetherjava.tjbot.commands.componentids.Lifespan;
-import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -23,26 +23,23 @@
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)} can be overridden if desired. The
* default implementation is empty, the adapter will not react to such events.
*
- *
* The adapter manages some getters for you, you've to create the {@link CommandData} yourself. See
* {@link #BotCommandAdapter(CommandData, CommandVisibility)}} for more info on that. Minimal
* modifications can be done on the {@link CommandData} returned by {@link #getData()}.
*
- *
* If implementations want to add buttons or selection menus, it is highly advised to use component
* IDs generated by {@link #generateComponentId(String...)}, which will automatically create IDs
* that are valid per {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
*
- *
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
* Registration of commands can be done in {@link Features}.
*/
public abstract class BotCommandAdapter implements BotCommand {
private final String name;
- private final Command.Type type;
+ private final UserInteractionType interactionType;
private final CommandVisibility visibility;
private final CommandData data;
- private ComponentIdGenerator componentIdGenerator;
+ private final ComponentIdInteractor componentIdInteractor;
/**
* Creates a new adapter with the given data.
@@ -54,8 +51,19 @@ protected BotCommandAdapter(CommandData data, CommandVisibility visibility) {
this.data = data.setGuildOnly(visibility == CommandVisibility.GUILD);
this.visibility = Objects.requireNonNull(visibility, "The visibility shouldn't be null");
- this.name = data.getName();
- this.type = data.getType();
+ name = data.getName();
+ interactionType = commandTypeToInteractionType(data.getType());
+ componentIdInteractor = new ComponentIdInteractor(interactionType, name);
+ }
+
+ private static UserInteractionType commandTypeToInteractionType(Command.Type type) {
+ return switch (type) {
+ case SLASH -> UserInteractionType.SLASH_COMMAND;
+ case USER -> UserInteractionType.USER_CONTEXT_COMMAND;
+ case MESSAGE -> UserInteractionType.MESSAGE_CONTEXT_COMMAND;
+ case UNKNOWN -> throw new IllegalArgumentException(
+ "Can not infer the type of user interaction for this command, it is unknown.");
+ };
}
@Override
@@ -64,8 +72,8 @@ public final String getName() {
}
@Override
- public Command.Type getType() {
- return type;
+ public final UserInteractionType getInteractionType() {
+ return interactionType;
}
@Override
@@ -81,8 +89,7 @@ public CommandData getData() {
@Override
@Contract(mutates = "this")
public final void acceptComponentIdGenerator(ComponentIdGenerator generator) {
- componentIdGenerator =
- Objects.requireNonNull(generator, "The given generator cannot be null");
+ componentIdInteractor.acceptComponentIdGenerator(generator);
}
@SuppressWarnings("NoopMethodInAbstractClass")
@@ -113,7 +120,7 @@ public void onSelectionMenu(SelectMenuInteractionEvent event, List args)
*/
@SuppressWarnings("OverloadedVarargsMethod")
protected final String generateComponentId(String... args) {
- return generateComponentId(Lifespan.REGULAR, args);
+ return componentIdInteractor.generateComponentId(args);
}
/**
@@ -130,8 +137,6 @@ protected final String generateComponentId(String... args) {
*/
@SuppressWarnings({"OverloadedVarargsMethod", "WeakerAccess"})
protected final String generateComponentId(Lifespan lifespan, String... args) {
- return componentIdGenerator
- .generate(new ComponentId(UserInteractorPrefix.getPrefixedNameFromInstance(this),
- Arrays.asList(args)), lifespan);
+ return componentIdInteractor.generateComponentId(lifespan, args);
}
}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java
index f05b626572..581296a77d 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java
@@ -1,6 +1,7 @@
package org.togetherjava.tjbot.commands;
import net.dv8tion.jda.api.JDA;
+
import org.togetherjava.tjbot.commands.basic.PingCommand;
import org.togetherjava.tjbot.commands.basic.RoleSelectCommand;
import org.togetherjava.tjbot.commands.basic.SuggestionsUpDownVoter;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/MessageContextCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/MessageContextCommand.java
index 912f264450..3983535f1d 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/MessageContextCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/MessageContextCommand.java
@@ -6,6 +6,7 @@
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
+
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import java.util.List;
@@ -21,7 +22,6 @@
* {@link BotCommandAdapter} available that implemented most methods already. A new command can then
* be registered by adding it to {@link Features}.
*
- *
* Context commands can either be visible globally in Discord or just to specific guilds. Minor
* adjustments can be made via {@link CommandData}, which is then to be returned by
* {@link #getData()} where the system will then pick it up from.
@@ -31,11 +31,9 @@
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
*
- *
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
*/
public interface MessageContextCommand extends BotCommand {
-
/**
* Triggered by the core system when a message context-command corresponding to this
* implementation (based on {@link #getData()}) has been triggered.
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java
index ba72609bc2..af7c17fa28 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java
@@ -10,6 +10,7 @@
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
+
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import java.util.List;
@@ -39,7 +40,6 @@
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
*/
public interface SlashCommand extends BotCommand {
-
/**
* Gets the description of the command.
*
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/UserContextCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/UserContextCommand.java
index cb1cab4127..4d25446f15 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/UserContextCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/UserContextCommand.java
@@ -6,6 +6,7 @@
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
+
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import java.util.List;
@@ -22,7 +23,6 @@
* {@link BotCommandAdapter} available that implemented most methods already. A new command can then
* be registered by adding it to {@link Features}.
*
- *
* Context commands can either be visible globally in Discord or just to specific guilds. Minor
* adjustments can be made via {@link CommandData}, which is then to be returned by
* {@link #getData()} where the system will then pick it up from.
@@ -32,11 +32,9 @@
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
*
- *
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
*/
public interface UserContextCommand extends BotCommand {
-
/**
* Triggered by the core system when a user context-command corresponding to this implementation
* (based on {@link #getData()}) has been triggered.
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractionType.java b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractionType.java
new file mode 100644
index 0000000000..799852d7b2
--- /dev/null
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractionType.java
@@ -0,0 +1,61 @@
+package org.togetherjava.tjbot.commands;
+
+/**
+ * Different types of user interactions.
+ *
+ * Also allows user interactors of different type to have the same name.
+ */
+public enum UserInteractionType {
+ /**
+ * User types a command leaded by a slash, such as {@code /ping}.
+ */
+ SLASH_COMMAND(SlashCommand.class, "s-"),
+ /**
+ * User right-clicks a message and selects a command.
+ */
+ MESSAGE_CONTEXT_COMMAND(MessageContextCommand.class, "mc-"),
+ /**
+ * User right-clicks a user and selects a command.
+ */
+ USER_CONTEXT_COMMAND(UserContextCommand.class, "uc-"),
+ /**
+ * Other types of interactions, for example a routine that offers buttons to click on.
+ */
+ OTHER(UserInteractor.class, "");
+
+ private final Class extends UserInteractor> classType;
+ private final String prefix;
+
+ UserInteractionType(Class extends UserInteractor> classType, final String prefix) {
+ this.classType = classType;
+ this.prefix = prefix;
+ }
+
+ /**
+ * The prefix for the command
+ *
+ * @return the command's prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Returns the name, attached with the prefix in front of it.
+ *
+ * @param name the name
+ * @return the name, with the prefix in front of it.
+ */
+ public String getPrefixedName(String name) {
+ return prefix + name;
+ }
+
+ /**
+ * The class type that should receive the prefix
+ *
+ * @return a {@link Class} instance of the type
+ */
+ public Class extends UserInteractor> getClassType() {
+ return classType;
+ }
+}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractor.java b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractor.java
index 65311be4bc..714a944afd 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractor.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractor.java
@@ -3,6 +3,7 @@
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
+
import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import org.togetherjava.tjbot.commands.componentids.Lifespan;
@@ -15,14 +16,14 @@
*
* An interactor can react to button clicks and selection menu actions. This is done based on the
* given {@link #getName()}, because of this names have to be unique. But, names can be complicated
- * if their type is different, all the types can be seen in {@link UserInteractorPrefix}
+ * if their type is different, all the types can be seen in {@link UserInteractionType}
*/
public interface UserInteractor extends Feature {
/**
* Gets the name of the interactor.
*
- * You cannot start the name with any of the prefixes found in {@link UserInteractorPrefix}
+ * You cannot start the name with any of the prefixes found in {@link UserInteractionType}
*
* After registration of the interactor, the name must not change anymore.
*
@@ -30,6 +31,16 @@ public interface UserInteractor extends Feature {
*/
String getName();
+
+ /**
+ * Gets the type of interactors this interactor allows.
+ *
+ * After registration of the interactor, the type must not change anymore.
+ *
+ * @return the type of the interaction allowed by this interactor
+ */
+ UserInteractionType getInteractionType();
+
/**
* Triggered by the core system when a button corresponding to this implementation (based on
* {@link #getName()}) has been clicked.
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java
deleted file mode 100644
index 53c76a3b5c..0000000000
--- a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.togetherjava.tjbot.commands;
-
-import org.jetbrains.annotations.Contract;
-
-/**
- * Contains the prefixes for the UserInteractor's.
- *
- * This is used for separate interactors with the same name, by command type (and possibly more in
- * the future). Our system doesn't allow multiple interactors with the same name, while having a
- * slash-command, and a message-context-command with the same name can be useful.
- */
-public enum UserInteractorPrefix {
- // Implementations that are none of the following have no dedicated prefix.
-
- /**
- * Prefix for slash commands.
- */
- SLASH_COMMAND(SlashCommand.class, "s-"),
- /**
- * Prefix for message context commands.
- */
- MESSAGE_CONTEXT_COMMAND(MessageContextCommand.class, "mc-"),
- /**
- * Prefix for user context commands.
- */
- USER_CONTEXT_COMMAND(UserContextCommand.class, "uc-");
-
- private final Class extends UserInteractor> classType;
- private final String prefix;
-
- UserInteractorPrefix(Class extends UserInteractor> classType, final String prefix) {
- this.classType = classType;
- this.prefix = prefix;
- }
-
- /**
- * The prefix for the command
- *
- * @return the command's prefix
- */
- public String getPrefix() {
- return prefix;
- }
-
- /**
- * Returns the name, attached with the prefix in front of it.
- *
- * @param name the name
- * @return the name, with the prefix in front of it.
- */
- public String getPrefixedName(String name) {
- return prefix + name;
- }
-
- /**
- * The class type that should receive the prefix
- *
- * @return a {@link Class} instance of the type
- */
- public Class extends UserInteractor> getClassType() {
- return classType;
- }
-
- /**
- * Checks what enum value the given instance collaborates to.
- *
- * This returns the name of the interactor, and adds the designated prefix to the name. As
- * example, a slash-command with the name "help" becomes "s-help".
- *
- * @param instance an instance to type check for a prefix
- * @param the type of the instance
- * @return the interactor's name, with its prefix
- */
- public static String getPrefixedNameFromInstance(final T instance) {
- String name = instance.getName();
-
- for (UserInteractorPrefix value : values()) {
- Class extends UserInteractor> valueClassType = value.getClassType();
-
- if (valueClassType.isInstance(instance)) {
- return value.getPrefix() + name;
- }
- }
-
- return name;
- }
-
- /**
- * Checks what enum value the given instance collaborates to.
- *
- * This combines the given name, with the interactor's prefix. As example, a slash-command with
- * the name "help" becomes "s-help".
- *
- * @param clazz the class to get the prefix from
- * @param name the name of the instance
- * @param the type of the instance
- * @return the prefixed {@link String}
- */
- public static String getPrefixedNameFromClass(final Class clazz,
- final String name) {
-
- for (UserInteractorPrefix value : values()) {
- Class extends UserInteractor> valueClassType = value.getClassType();
-
- if (valueClassType.isAssignableFrom(clazz)) {
- return value.getPrefix() + name;
- }
- }
-
- return name;
- }
-
- @Override
- @Contract(pure = true)
- public String toString() {
- return "UserInteractorPrefix{" + "prefix='" + prefix + '\'' + '}';
- }
-}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/basic/PingCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/basic/PingCommand.java
index fd5afa121a..0b287c151c 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/basic/PingCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/basic/PingCommand.java
@@ -1,6 +1,7 @@
package org.togetherjava.tjbot.commands.basic;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/basic/RoleSelectCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/basic/RoleSelectCommand.java
index 05a372eca1..d8e6970132 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/basic/RoleSelectCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/basic/RoleSelectCommand.java
@@ -16,13 +16,14 @@
import org.jetbrains.annotations.Contract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.componentids.Lifespan;
import java.awt.*;
-import java.util.List;
import java.util.*;
+import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java b/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java
index 3ca76e4ae3..d2eccaef77 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java
@@ -9,6 +9,7 @@
import net.dv8tion.jda.api.requests.ErrorResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.config.SuggestionsConfig;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java
index 033616ab34..f66cb77d68 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java
@@ -15,10 +15,12 @@
import org.jetbrains.annotations.Contract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import javax.annotation.Nullable;
+
import java.util.List;
import java.util.Map;
import java.util.Objects;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdGenerator.java b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdGenerator.java
index 0a746965d8..372e6ed54f 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdGenerator.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdGenerator.java
@@ -4,6 +4,7 @@
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
+
import org.togetherjava.tjbot.commands.SlashCommand;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdInteractor.java b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdInteractor.java
new file mode 100644
index 0000000000..77792aafad
--- /dev/null
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdInteractor.java
@@ -0,0 +1,91 @@
+package org.togetherjava.tjbot.commands.componentids;
+
+import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
+
+import org.togetherjava.tjbot.commands.SlashCommand;
+import org.togetherjava.tjbot.commands.UserInteractionType;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * Delegate class for interacting with component IDs. Provides methods to easily generate valid
+ * component IDs as accepted by the system.
+ *
+ * The method {@link #acceptComponentIdGenerator(ComponentIdGenerator)} must be used before
+ * attempting to generate IDs.
+ *
+ * Mostly used by classes implementing {@link org.togetherjava.tjbot.commands.UserInteractor}, to
+ * simplify handling with the IDs.
+ */
+public final class ComponentIdInteractor {
+ private final String name;
+ private final UserInteractionType userInteractionType;
+ private ComponentIdGenerator generator;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param userInteractionType The type of interaction component IDs are used by
+ * @param name The unique name of the interactor. Requirements for this are documented in
+ * {@link net.dv8tion.jda.api.interactions.commands.build.Commands#slash(String, String)}.
+ * After registration of the interactor, the name must not change anymore.
+ */
+ public ComponentIdInteractor(UserInteractionType userInteractionType, String name) {
+ this.name = Objects.requireNonNull(name);
+ this.userInteractionType = Objects.requireNonNull(userInteractionType);
+ }
+
+ /**
+ * Must be used before generating component IDs with {@link #generateComponentId(String...)} and
+ * similar.
+ *
+ * It will provide the interactor a component ID generator through this method, which can be
+ * used to generate component IDs, as used for button or selection menus. See
+ * {@link org.togetherjava.tjbot.commands.UserInteractor#acceptComponentIdGenerator(ComponentIdGenerator)}
+ * for details on how to use this.
+ *
+ * @param generator the provided component ID generator
+ */
+ public void acceptComponentIdGenerator(ComponentIdGenerator generator) {
+ this.generator = Objects.requireNonNull(generator);
+ }
+
+ /**
+ * Generates component IDs that are considered valid per
+ * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
+ *
+ * They can be used to create buttons or selection menus and transport additional data
+ * throughout the event (e.g., the user ID who created the button dialog).
+ *
+ * IDs generated by this method have a regular lifespan, meaning they might get evicted and
+ * expire after not being used for a long time. Use
+ * {@link #generateComponentId(Lifespan, String...)} to set other lifespans, if desired.
+ *
+ * @param args the extra arguments that should be part of the ID
+ * @return the generated component ID
+ */
+ @SuppressWarnings("OverloadedVarargsMethod")
+ public String generateComponentId(String... args) {
+ return generateComponentId(Lifespan.REGULAR, args);
+ }
+
+ /**
+ * Generates component IDs that are considered valid per
+ * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
+ *
+ * They can be used to create buttons or selection menus and transport additional data
+ * throughout the event (e.g., the user ID who created the button dialog).
+ *
+ * @param lifespan the lifespan of the component ID, controls when an ID that was not used for a
+ * long time might be evicted and expire
+ * @param args the extra arguments that should be part of the ID
+ * @return the generated component ID
+ */
+ @SuppressWarnings("OverloadedVarargsMethod")
+ public String generateComponentId(Lifespan lifespan, String... args) {
+ return generator.generate(
+ new ComponentId(userInteractionType.getPrefixedName(name), Arrays.asList(args)),
+ lifespan);
+ }
+}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdStore.java b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdStore.java
index 7883c280ae..223593526c 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdStore.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdStore.java
@@ -8,6 +8,7 @@
import org.jooq.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.SlashCommand;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.db.generated.tables.ComponentIds;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/filesharing/FileSharingMessageListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/filesharing/FileSharingMessageListener.java
index 9e145b6b2e..f4c0316ac5 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/filesharing/FileSharingMessageListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/filesharing/FileSharingMessageListener.java
@@ -10,6 +10,7 @@
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
import org.togetherjava.tjbot.config.Config;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java
index 59ce0f3fff..2b0c253e09 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java
@@ -16,6 +16,7 @@
import net.dv8tion.jda.api.requests.RestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
@@ -47,7 +48,7 @@
*/
public final class AskCommand extends SlashCommandAdapter {
private static final Logger logger = LoggerFactory.getLogger(AskCommand.class);
-
+ public static final String COMMAND_NAME = "ask";
private static final String TITLE_OPTION = "title";
private static final String CATEGORY_OPTION = "category";
private final HelpSystemHelper helper;
@@ -126,6 +127,7 @@ private RestAction handleEvent(InteractionHook eventHook, ThreadChannel
Member author, String title, String category, Guild guild) {
helper.writeHelpThreadToDatabase(author, threadChannel);
return sendInitialMessage(guild, threadChannel, author, title, category)
+ .flatMap(Message::pin)
.flatMap(any -> notifyUser(eventHook, threadChannel))
.flatMap(any -> helper.sendExplanationMessage(threadChannel));
}
@@ -136,10 +138,11 @@ private RestAction sendInitialMessage(Guild guild, ThreadChannel thread
.map(role -> " (%s)".formatted(role.getAsMention()))
.orElse("");
- String contentPattern = "%s has a question about '**%s**'%%s and will send the details now."
- .formatted(author.getAsMention(), title);
- String contentWithoutRole = contentPattern.formatted("");
- String contentWithRole = contentPattern.formatted(roleMentionDescription);
+ String contentPrefix =
+ "%s has a question about '**%s**'".formatted(author.getAsMention(), title);
+ String contentSuffix = " and will send the details now.";
+ String contentWithoutRole = contentPrefix + contentSuffix;
+ String contentWithRole = contentPrefix + roleMentionDescription + contentSuffix;
// We want to invite all members of a role, but without hard-pinging them. However,
// manually inviting them is cumbersome and can hit rate limits.
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AutoPruneHelperRoutine.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AutoPruneHelperRoutine.java
index 5d20b179e1..926595c270 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AutoPruneHelperRoutine.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AutoPruneHelperRoutine.java
@@ -7,6 +7,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Routine;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.db.Database;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java
index 768341fad0..514f2ebbbf 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java
@@ -9,6 +9,7 @@
import net.dv8tion.jda.internal.requests.CompletedRestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Routine;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.config.HelpSystemConfig;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java
index 2831d23400..4dce9512e0 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java
@@ -7,6 +7,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
+import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
@@ -16,6 +17,8 @@
import net.dv8tion.jda.internal.requests.CompletedRestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import org.togetherjava.tjbot.commands.utils.MessageUtils;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.config.HelpSystemConfig;
import org.togetherjava.tjbot.db.Database;
@@ -23,6 +26,7 @@
import org.togetherjava.tjbot.db.generated.tables.records.HelpThreadsRecord;
import javax.annotation.Nullable;
+
import java.awt.Color;
import java.io.InputStream;
import java.util.List;
@@ -90,7 +94,16 @@ public HelpSystemHelper(JDA jda, Config config, Database database) {
categoryRoleSuffix = helpConfig.getCategoryRoleSuffix();
}
- RestAction sendExplanationMessage(MessageChannel threadChannel) {
+ RestAction sendExplanationMessage(GuildMessageChannel threadChannel) {
+ return MessageUtils
+ .mentionSlashCommand(threadChannel.getGuild(), HelpThreadCommand.COMMAND_NAME,
+ HelpThreadCommand.Subcommand.CLOSE.getCommandName())
+ .flatMap(closeCommandMention -> sendExplanationMessage(threadChannel,
+ closeCommandMention));
+ }
+
+ private RestAction sendExplanationMessage(GuildMessageChannel threadChannel,
+ String closeCommandMention) {
boolean useCodeSyntaxExampleImage = true;
InputStream codeSyntaxExampleData =
AskCommand.class.getResourceAsStream("/" + CODE_SYNTAX_EXAMPLE_PATH);
@@ -115,7 +128,8 @@ RestAction sendExplanationMessage(MessageChannel threadChannel) {
**provide details**, context, more code, examples and maybe some screenshots. \
With enough info, someone knows the answer for sure."""),
HelpSystemHelper.embedWith(
- "Don't forget to close your thread using the command **/help-thread close** when your question has been answered, thanks."));
+ "Don't forget to close your thread using the command %s when your question has been answered, thanks."
+ .formatted(closeCommandMention)));
MessageCreateAction action = threadChannel.sendMessage(message);
if (useCodeSyntaxExampleImage) {
@@ -298,16 +312,24 @@ private void executeUncategorizedAdviceCheck(long threadChannelId, long authorId
}
// Still no category, send advice
- MessageEmbed embed = HelpSystemHelper.embedWith(
- """
- Hey there 👋 You have to select a category for your help thread, otherwise nobody can see your question.
- Please use the `/help-thread change category` slash-command and pick what fits best, thanks 🙂
- """);
- MessageCreateData message = new MessageCreateBuilder().setContent(author.getAsMention())
- .setEmbeds(embed)
- .build();
-
- return threadChannel.sendMessage(message);
+ return MessageUtils
+ .mentionSlashCommand(threadChannel.getGuild(), HelpThreadCommand.COMMAND_NAME,
+ HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP,
+ HelpThreadCommand.Subcommand.CHANGE_CATEGORY.getCommandName())
+ .flatMap(command -> {
+ MessageEmbed embed = HelpSystemHelper.embedWith(
+ """
+ Hey there 👋 You have to select a category for your help thread, otherwise nobody can see your question.
+ Please use the %s slash-command and pick what fits best, thanks 🙂
+ """
+ .formatted(command));
+ MessageCreateData message =
+ new MessageCreateBuilder().setContent(author.getAsMention())
+ .setEmbeds(embed)
+ .build();
+
+ return threadChannel.sendMessage(message);
+ });
}).queue();
}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java
index 75db5e8f1a..4f46f68e5d 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java
@@ -10,6 +10,7 @@
import net.dv8tion.jda.api.requests.RestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Routine;
import java.util.List;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadAutoArchiver.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadAutoArchiver.java
index ef98c5f523..e60341cbbc 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadAutoArchiver.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadAutoArchiver.java
@@ -10,6 +10,7 @@
import net.dv8tion.jda.api.utils.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Routine;
import java.time.Duration;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java
index b37c503537..b4e52339f6 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java
@@ -16,6 +16,7 @@
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
@@ -44,6 +45,8 @@ public final class HelpThreadCommand extends SlashCommandAdapter {
private static final String CHANGE_CATEGORY_OPTION = "category";
private static final String CHANGE_TITLE_OPTION = "title";
private static final String CHANGE_TITLE_SUBCOMMAND = "title";
+ public static final String CHANGE_SUBCOMMAND_GROUP = "change";
+ public static final String COMMAND_NAME = "help-thread";
private final HelpSystemHelper helper;
private final Map nameToSubcommand;
@@ -57,7 +60,7 @@ public final class HelpThreadCommand extends SlashCommandAdapter {
* @param helper the helper to use
*/
public HelpThreadCommand(Config config, HelpSystemHelper helper) {
- super("help-thread", "Help thread specific commands", CommandVisibility.GUILD);
+ super(COMMAND_NAME, "Help thread specific commands", CommandVisibility.GUILD);
OptionData categoryChoices =
new OptionData(OptionType.STRING, CHANGE_CATEGORY_OPTION, "new category", true);
@@ -71,9 +74,9 @@ public HelpThreadCommand(Config config, HelpSystemHelper helper) {
SubcommandData changeTitle = Subcommand.CHANGE_TITLE.toSubcommandData()
.addOption(OptionType.STRING, CHANGE_TITLE_OPTION, "new title", true);
- SubcommandGroupData changeCommands =
- new SubcommandGroupData("change", "Change the details of this help thread")
- .addSubcommands(changeCategory, changeTitle);
+ SubcommandGroupData changeCommands = new SubcommandGroupData(CHANGE_SUBCOMMAND_GROUP,
+ "Change the details of this help thread").addSubcommands(changeCategory,
+ changeTitle);
getData().addSubcommandGroups(changeCommands);
getData().addSubcommands(Subcommand.CLOSE.toSubcommandData());
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadMetadataPurger.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadMetadataPurger.java
index 929b5c5b6d..34c6d3c644 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadMetadataPurger.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadMetadataPurger.java
@@ -3,6 +3,7 @@
import net.dv8tion.jda.api.JDA;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.Routine;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.db.generated.tables.HelpThreads;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java
index 3337e18f6e..85e0a59fc2 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java
@@ -1,5 +1,6 @@
package org.togetherjava.tjbot.commands.help;
+import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
@@ -15,11 +16,13 @@
import net.dv8tion.jda.internal.requests.CompletedRestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
import org.togetherjava.tjbot.commands.Routine;
import org.togetherjava.tjbot.config.Config;
import javax.annotation.Nullable;
+
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -39,7 +42,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 static final AtomicInteger FIND_STATUS_MESSAGE_CONSECUTIVE_FAILURES =
new AtomicInteger(0);
@@ -120,7 +123,9 @@ private void updateOverview(TextChannel overviewChannel) {
logger.debug("Found {} active questions", activeThreads.size());
MessageEditData message = new MessageEditBuilder()
- .setContent(STATUS_TITLE + "\n\n" + createDescription(activeThreads))
+ .setEmbeds(new EmbedBuilder().setTitle(STATUS_TITLE)
+ .setDescription(createDescription(activeThreads))
+ .build())
.build();
getStatusMessage(overviewChannel)
@@ -163,12 +168,13 @@ private static RestAction> getStatusMessage(MessageChannel cha
}
private static boolean isStatusMessage(Message message) {
- if (!message.getAuthor().equals(message.getJDA().getSelfUser())) {
+ if (message.getEmbeds().isEmpty()
+ || !message.getAuthor().equals(message.getJDA().getSelfUser())) {
return false;
}
- String content = message.getContentRaw();
- return content.startsWith(STATUS_TITLE);
+ String messageEmbedTitle = message.getEmbeds().get(0).getTitle();
+ return STATUS_TITLE.equals(messageEmbedTitle);
}
private RestAction sendUpdatedOverview(@Nullable Message statusMessage,
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java
index 38289df454..3b550cb0b0 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java
@@ -10,12 +10,13 @@
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import net.dv8tion.jda.api.requests.ErrorResponse;
import net.dv8tion.jda.api.requests.RestAction;
-import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
+import org.togetherjava.tjbot.commands.utils.MessageUtils;
import org.togetherjava.tjbot.config.Config;
import java.time.Instant;
@@ -117,13 +118,15 @@ private boolean handleIsNotOnCooldown(Message message) {
String threadDescription = lastHelpThread == null ? "your previously created help thread"
: lastHelpThread.getAsMention();
- message.getChannel()
- .sendMessage("""
- %s Please use %s to follow up on your question, \
- or use `/ask` to ask a new questions, thanks."""
- .formatted(author.getAsMention(), threadDescription))
- .flatMap(any -> message.delete())
+ MessageUtils.mentionSlashCommand(message.getGuild(), AskCommand.COMMAND_NAME)
+ .flatMap(command -> message.getChannel()
+ .sendMessage("""
+ %s Please use %s to follow up on your question, \
+ or use %s to ask a new questions, thanks."""
+ .formatted(author.getAsMention(), threadDescription, command))
+ .flatMap(any -> message.delete()))
.queue();
+
return false;
}
@@ -170,7 +173,7 @@ private RestAction> handleEvent(ThreadChannel threadChannel, Message message,
author.getIdLong()));
}
- private static MessageCreateAction sendInitialMessage(ThreadChannel threadChannel,
+ private static RestAction sendInitialMessage(ThreadChannel threadChannel,
Message originalMessage, String title) {
String content = originalMessage.getContentRaw();
Member author = originalMessage.getMember();
@@ -181,27 +184,34 @@ private static MessageCreateAction sendInitialMessage(ThreadChannel threadChanne
.setColor(HelpSystemHelper.AMBIENT_COLOR)
.build();
- MessageCreateData threadMessage = new MessageCreateBuilder()
- .setContent(
- """
+ return MessageUtils
+ .mentionSlashCommand(originalMessage.getGuild(), HelpThreadCommand.COMMAND_NAME,
+ HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP,
+ HelpThreadCommand.Subcommand.CHANGE_CATEGORY.getCommandName())
+ .flatMap(command -> {
+ MessageCreateData threadMessage = new MessageCreateBuilder()
+ .setContent("""
%s has a question about '**%s**' and will send the details now.
- Please use `/help-thread change category` to greatly increase the visibility of the question."""
- .formatted(author, title))
- .setEmbeds(embed)
- .build();
+ Please use %s to greatly increase the visibility of the question."""
+ .formatted(author, title, command))
+ .setEmbeds(embed)
+ .build();
+
+ return threadChannel.sendMessage(threadMessage);
+ });
- return threadChannel.sendMessage(threadMessage);
}
- private static MessageCreateAction notifyUser(IMentionable threadChannel, Message message) {
- return message.getChannel()
- .sendMessage(
- """
- %s Please use `/ask` to ask questions. Don't worry though, I created %s for you. \
- Please continue there, thanks."""
- .formatted(message.getAuthor().getAsMention(),
- threadChannel.getAsMention()));
+ private static RestAction notifyUser(IMentionable threadChannel, Message message) {
+ return MessageUtils.mentionSlashCommand(message.getGuild(), AskCommand.COMMAND_NAME)
+ .flatMap(command -> message.getChannel()
+ .sendMessage(
+ """
+ %s Please use %s to ask questions. Don't worry though, I created %s for you. \
+ Please continue there, thanks."""
+ .formatted(message.getAuthor().getAsMention(), command,
+ threadChannel.getAsMention())));
}
private static void handleFailure(Throwable exception) {
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/OnGuildLeaveCloseThreadListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/OnGuildLeaveCloseThreadListener.java
index 0d68901753..19eb37b3d6 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/help/OnGuildLeaveCloseThreadListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/OnGuildLeaveCloseThreadListener.java
@@ -1,23 +1,27 @@
package org.togetherjava.tjbot.commands.help;
import net.dv8tion.jda.api.EmbedBuilder;
+import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.EventReceiver;
import org.togetherjava.tjbot.db.Database;
-import org.togetherjava.tjbot.db.generated.tables.HelpThreads;
import java.util.HashSet;
import java.util.Set;
+import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS;
+
/**
* Remove all thread channels associated to a user when they leave the guild.
*/
-public class OnGuildLeaveCloseThreadListener extends ListenerAdapter implements EventReceiver {
+public final class OnGuildLeaveCloseThreadListener extends ListenerAdapter
+ implements EventReceiver {
private static final Logger logger =
LoggerFactory.getLogger(OnGuildLeaveCloseThreadListener.class);
private final Database database;
@@ -33,28 +37,35 @@ public OnGuildLeaveCloseThreadListener(Database database) {
@Override
public void onGuildMemberRemove(GuildMemberRemoveEvent leaveEvent) {
- Set channelIds = getThreadsCreatedByLeaver(leaveEvent.getUser().getIdLong());
+ Set channelIds = fetchThreadsByLeaver(leaveEvent.getUser().getIdLong());
for (long channelId : channelIds) {
- closeThread(channelId, leaveEvent);
+ closeThread(channelId, leaveEvent.getGuild());
}
}
- private Set getThreadsCreatedByLeaver(long leaverId) {
- return new HashSet<>(database
- .readTransaction(context -> context.select(HelpThreads.HELP_THREADS.CHANNEL_ID))
- .from(HelpThreads.HELP_THREADS)
- .where(HelpThreads.HELP_THREADS.AUTHOR_ID.eq(leaverId))
- .fetch(databaseMapper -> databaseMapper.getValue(HelpThreads.HELP_THREADS.CHANNEL_ID)));
+ private Set fetchThreadsByLeaver(long leaverId) {
+ return new HashSet<>(
+ database.readTransaction(context -> context.select(HELP_THREADS.CHANNEL_ID))
+ .from(HELP_THREADS)
+ .where(HELP_THREADS.AUTHOR_ID.eq(leaverId))
+ .fetch(databaseMapper -> databaseMapper.getValue(HELP_THREADS.CHANNEL_ID)));
}
- private void closeThread(long channelId, GuildMemberRemoveEvent leaveEvent) {
- ThreadChannel threadChannel = leaveEvent.getGuild().getThreadChannelById(channelId);
+ private void closeThread(long channelId, Guild guild) {
+ ThreadChannel threadChannel = guild.getThreadChannelById(channelId);
if (threadChannel == null) {
logger.warn(
"Attempted to archive thread id: '{}' but could not find thread in guild: '{}'.",
- channelId, leaveEvent.getGuild().getName());
+ channelId, guild.getName());
return;
}
+ if (threadChannel.isArchived()) {
+ logger.debug(
+ "Attempted to archive thread id: '{}' in guild: '{}' but thread is already closed.",
+ channelId, guild.getName());
+ return;
+ }
+
MessageEmbed embed = new EmbedBuilder().setTitle("OP left")
.setDescription("Closing thread...")
.setColor(HelpSystemHelper.AMBIENT_COLOR)
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/TeXCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/TeXCommand.java
index ead51436f8..4bfd4ec0d2 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/TeXCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/TeXCommand.java
@@ -12,10 +12,12 @@
import org.scilab.forge.jlatexmath.TeXFormula;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import javax.imageio.ImageIO;
+
import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaCommand.java
index fb549df9ce..bd0884cf55 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaCommand.java
@@ -4,8 +4,9 @@
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback;
import net.dv8tion.jda.api.interactions.commands.OptionType;
-import org.togetherjava.tjbot.commands.CommandVisibility;
import net.dv8tion.jda.api.utils.FileUpload;
+
+import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaHandler.java b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaHandler.java
index 749ddee1fe..82a375ecc2 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaHandler.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaHandler.java
@@ -7,8 +7,9 @@
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.togetherjava.tjbot.commands.mathcommands.wolframalpha.api.Error;
+
import org.togetherjava.tjbot.commands.mathcommands.wolframalpha.api.*;
+import org.togetherjava.tjbot.commands.mathcommands.wolframalpha.api.Error;
import java.awt.Color;
import java.awt.image.BufferedImage;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaImages.java b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaImages.java
index b1287e2b2d..25cff2c349 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaImages.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/WolframAlphaImages.java
@@ -4,6 +4,7 @@
import org.togetherjava.tjbot.commands.mathcommands.wolframalpha.api.WolframAlphaImage;
import javax.imageio.ImageIO;
+
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/api/RelatedExamples.java b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/api/RelatedExamples.java
index f016a9f6b5..b7a3253573 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/api/RelatedExamples.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/wolframalpha/api/RelatedExamples.java
@@ -6,9 +6,9 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
/**
* See the Wolfram Alpha API.
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/mediaonly/MediaOnlyChannelListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/mediaonly/MediaOnlyChannelListener.java
index af29d1013f..e9fc277b5c 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/mediaonly/MediaOnlyChannelListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/mediaonly/MediaOnlyChannelListener.java
@@ -8,6 +8,7 @@
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
import org.togetherjava.tjbot.config.Config;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ActionRecord.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ActionRecord.java
index cf4c1075ba..080db80c14 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ActionRecord.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ActionRecord.java
@@ -3,6 +3,7 @@
import org.togetherjava.tjbot.db.generated.tables.records.ModerationActionsRecord;
import javax.annotation.Nullable;
+
import java.time.Instant;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java
index f8e9f560bc..0a173c63ed 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java
@@ -18,10 +18,12 @@
import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;
import net.dv8tion.jda.api.utils.messages.MessageRequest;
import net.dv8tion.jda.internal.requests.CompletedRestAction;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import javax.annotation.Nullable;
+
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.*;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java
index 01596d37a1..751c15679e 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java
@@ -16,11 +16,13 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.time.Instant;
import java.util.List;
import java.util.Objects;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java
index dc88789e44..696476a3e6 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java
@@ -14,11 +14,13 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationActionsStore.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationActionsStore.java
index 6d6e79f456..06248d51c5 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationActionsStore.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationActionsStore.java
@@ -1,11 +1,13 @@
package org.togetherjava.tjbot.commands.moderation;
import org.jooq.Condition;
+
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.db.generated.tables.ModerationActions;
import org.togetherjava.tjbot.db.generated.tables.records.ModerationActionsRecord;
import javax.annotation.Nullable;
+
import java.time.Instant;
import java.util.List;
import java.util.Objects;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
index b46f339767..58a2e232ce 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
@@ -4,11 +4,14 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
+import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.config.Config;
import javax.annotation.Nullable;
+
import java.awt.Color;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@@ -28,7 +31,7 @@ private ModerationUtils() {
private static final Logger logger = LoggerFactory.getLogger(ModerationUtils.class);
/**
* The maximal character limit for the reason of an auditable action, see for example
- * {@link Guild#ban(User, int, String)}.
+ * {@link AuditableRestAction#reason(String)}.
*/
private static final int REASON_MAX_LENGTH = 512;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java
index 8102a2e646..c925496ad1 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java
@@ -11,12 +11,14 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.time.Instant;
import java.util.List;
import java.util.Objects;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/NoteCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/NoteCommand.java
index 803a664302..12287abe45 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/NoteCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/NoteCommand.java
@@ -7,11 +7,13 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/QuarantineCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/QuarantineCommand.java
index 9599db922c..7dd2efdb5d 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/QuarantineCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/QuarantineCommand.java
@@ -10,12 +10,14 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/RejoinModerationRoleListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/RejoinModerationRoleListener.java
index cec8f35260..9ef3d59e75 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/RejoinModerationRoleListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/RejoinModerationRoleListener.java
@@ -8,6 +8,7 @@
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.EventReceiver;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java
index 0bc6d5746b..f4fdc0239e 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java
@@ -9,6 +9,7 @@
import net.dv8tion.jda.api.requests.ErrorResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnmuteCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnmuteCommand.java
index dfd77ac67e..0e388a2911 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnmuteCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnmuteCommand.java
@@ -10,12 +10,14 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnquarantineCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnquarantineCommand.java
index 6619c7ce12..2839d77b2f 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnquarantineCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnquarantineCommand.java
@@ -10,12 +10,14 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WarnCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WarnCommand.java
index ef7073dea3..0e52fea049 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WarnCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WarnCommand.java
@@ -9,11 +9,13 @@
import net.dv8tion.jda.api.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;
import javax.annotation.Nullable;
+
import java.util.Objects;
/**
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WhoIsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WhoIsCommand.java
index fe7bfaad8e..e039343544 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WhoIsCommand.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/WhoIsCommand.java
@@ -8,11 +8,13 @@
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
+
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.utils.DiscordClientAction;
import javax.annotation.CheckReturnValue;
+
import java.awt.*;
import java.time.Instant;
import java.time.OffsetDateTime;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/attachment/BlacklistedAttachmentListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/attachment/BlacklistedAttachmentListener.java
index 130cdbf2eb..cd42cc2d82 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/attachment/BlacklistedAttachmentListener.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/attachment/BlacklistedAttachmentListener.java
@@ -7,6 +7,7 @@
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.moderation.ModAuditLogWriter;
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/scam/ScamBlocker.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/scam/ScamBlocker.java
index f12e547944..de54d7e19a 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/scam/ScamBlocker.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/scam/ScamBlocker.java
@@ -15,11 +15,12 @@
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
+import org.togetherjava.tjbot.commands.UserInteractionType;
import org.togetherjava.tjbot.commands.UserInteractor;
-import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
-import org.togetherjava.tjbot.commands.componentids.Lifespan;
+import org.togetherjava.tjbot.commands.componentids.ComponentIdInteractor;
import org.togetherjava.tjbot.commands.moderation.ModerationAction;
import org.togetherjava.tjbot.commands.moderation.ModerationActionsStore;
import org.togetherjava.tjbot.commands.moderation.ModerationUtils;
@@ -57,7 +58,7 @@ public final class ScamBlocker extends MessageReceiverAdapter implements UserInt
private final ScamHistoryStore scamHistoryStore;
private final Predicate hasRequiredRole;
- private ComponentIdGenerator componentIdGenerator;
+ private final ComponentIdInteractor componentIdInteractor;
/**
* Creates a new listener to receive all message sent in any channel.
@@ -81,6 +82,8 @@ public ScamBlocker(ModerationActionsStore actionsStore, ScamHistoryStore scamHis
Pattern.compile(reportChannelPattern).asMatchPredicate();
isReportChannel = channel -> isReportChannelName.test(channel.getName());
hasRequiredRole = Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate();
+
+ componentIdInteractor = new ComponentIdInteractor(getInteractionType(), getName());
}
@Override
@@ -88,6 +91,11 @@ public String getName() {
return "scam-blocker";
}
+ @Override
+ public UserInteractionType getInteractionType() {
+ return UserInteractionType.OTHER;
+ }
+
@Override
public void onSelectionMenu(SelectMenuInteractionEvent event, List args) {
throw new UnsupportedOperationException("Not used");
@@ -95,7 +103,7 @@ public void onSelectionMenu(SelectMenuInteractionEvent event, List args)
@Override
public void acceptComponentIdGenerator(ComponentIdGenerator generator) {
- componentIdGenerator = generator;
+ componentIdInteractor.acceptComponentIdGenerator(generator);
}
@Override
@@ -265,8 +273,7 @@ private List