From 041834150091c38604fa8a321584d134e31f01d0 Mon Sep 17 00:00:00 2001 From: christolis Date: Tue, 15 Oct 2024 02:02:39 +0300 Subject: [PATCH] feat: SquidXTV's changes - Slightly alter UI so that the title is the question and the text input field has the right placeholder. - Rename default application channel - Move certain variables to the bot's configuration - Use `Duration` instead of `TimeUnit` - Let the user know how long they need to wait to send another application --- application/config.json.template | 8 +++- .../tjbot/config/ApplicationFormConfig.java | 12 +++++- .../basic/ApplicationCreateCommand.java | 39 +++++++++++-------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 6c92cb1cbf..a212798ce7 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -116,7 +116,11 @@ "pollIntervalInMinutes": 10 }, "applicationForm": { - "applicationChannelPattern": "applications-log" - } + "applicationChannelPattern": "staff-applications", + "defaultQuestion": "What makes you a valuable addition to the team? 😎", + "minimumAnswerLength": 50, + "maximumAnswerLength": 500, + "applicationSubmitCooldownMinutes": 5 + }, "memberCountCategoryPattern": "Info" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/ApplicationFormConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/ApplicationFormConfig.java index b12c5df418..1203ad1a1a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/ApplicationFormConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/ApplicationFormConfig.java @@ -8,15 +8,23 @@ * Represents the configuration for an application form, including roles and application channel * pattern. */ -public record ApplicationFormConfig(@JsonProperty(value = "applicationChannelPattern", - required = true) String applicationChannelPattern) { +public record ApplicationFormConfig( + @JsonProperty(value = "applicationChannelPattern", + required = true) String applicationChannelPattern, + @JsonProperty(value = "defaultQuestion", required = true) String defaultQuestion, + @JsonProperty(value = "minimumAnswerLength", required = true) int minimumAnswerLength, + @JsonProperty(value = "maximumAnswerLength", required = true) int maximumAnswerLength, + @JsonProperty(value = "applicationSubmitCooldownMinutes", + required = true) int applicationSubmitCooldownMinutes) { /** * Constructs an instance of {@link ApplicationFormConfig} with the provided parameters. * * @param applicationChannelPattern the pattern used to identify the application channel + * @param defaultQuestion the default question for the form */ public ApplicationFormConfig { Objects.requireNonNull(applicationChannelPattern); + Objects.requireNonNull(defaultQuestion); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/ApplicationCreateCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/ApplicationCreateCommand.java index f5dfe9d3e8..6c3b533f12 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/ApplicationCreateCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/ApplicationCreateCommand.java @@ -42,7 +42,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.IntStream; @@ -57,11 +56,6 @@ public class ApplicationCreateCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(ApplicationCreateCommand.class); private static final Color AMBIENT_COLOR = new Color(24, 221, 136, 255); - private static final int MIN_REASON_LENGTH = 50; - private static final int MAX_REASON_LENGTH = 500; - private static final int APPLICATION_SUBMIT_COOLDOWN = 5; - private static final String DEFAULT_QUESTION = - "What makes you a valuable addition to the team? 😎"; private static final int OPTIONAL_ROLES_AMOUNT = 5; private static final String ROLE_COMPONENT_ID_HEADER = "application-create"; private static final String VALUE_DELIMITER = "_"; @@ -69,6 +63,8 @@ public class ApplicationCreateCommand extends SlashCommandAdapter { private final Cache applicationSubmitCooldown; private final Predicate applicationChannelPattern; + private final ApplicationFormConfig formConfig; + /** * Constructs a new {@link ApplicationCreateCommand} with the specified configuration. *

@@ -80,13 +76,14 @@ public ApplicationCreateCommand(Config config) { super("application-form", "Generates an application form for members to apply for roles.", CommandVisibility.GUILD); - final ApplicationFormConfig formConfig = config.getApplicationFormConfig(); + formConfig = config.getApplicationFormConfig(); this.applicationChannelPattern = Pattern.compile(formConfig.applicationChannelPattern()).asMatchPredicate(); + final Duration applicationSubmitCooldownDuration = + Duration.ofMinutes(formConfig.applicationSubmitCooldownMinutes()); - this.applicationSubmitCooldown = Caffeine.newBuilder() - .expireAfterWrite(APPLICATION_SUBMIT_COOLDOWN, TimeUnit.MINUTES) - .build(); + this.applicationSubmitCooldown = + Caffeine.newBuilder().expireAfterWrite(applicationSubmitCooldownDuration).build(); generateRoleOptions(getData()); } @@ -147,21 +144,30 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List TextInput.MAX_LABEL_LENGTH) { + questionLabel = questionLabel.substring(0, TextInput.MAX_LABEL_LENGTH); + } + TextInput body = TextInput - .create(generateComponentId(event.getUser().getId()), "Question", + .create(generateComponentId(event.getUser().getId()), questionLabel, TextInputStyle.PARAGRAPH) .setRequired(true) - .setRequiredRange(MIN_REASON_LENGTH, MAX_REASON_LENGTH) - .setPlaceholder(DEFAULT_QUESTION) + .setRequiredRange(formConfig.minimumAnswerLength(), formConfig.maximumAnswerLength()) + .setPlaceholder("Enter your answer here") .build(); EmojiUnion emoji = selectOption.getEmoji(); @@ -329,7 +335,8 @@ private void sendApplicationResult(final ModalInteractionEvent event, List