Skip to content

Commit 3fb788a

Browse files
committed
application-create: hardcode certain config values
Certain configuration values pertaining to the application form creating and handling for custom roles do not need to be there and are deemed more appropriate as hardcoded values inside the code itself. Remove the configuration entries from the `config.json.template` as well as references to such keys in the codebase and introduce them as static constants in the appropriate class files. Suggested-by: Zabuzard <zabuza.dev@gmail.com> Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent f46c983 commit 3fb788a

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

application/config.json.template

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@
177177
},
178178
"roleApplicationSystem": {
179179
"submissionsChannelPattern": "staff-applications",
180-
"defaultQuestion": "What makes you a good addition to the team?",
181-
"minimumAnswerLength": 50,
182-
"maximumAnswerLength": 500,
183-
"applicationSubmitCooldownMinutes": 5
180+
"defaultQuestion": "What makes you a good addition to the team?"
184181
},
185182
"memberCountCategoryPattern": "Info"
186183
}

application/src/main/java/org/togetherjava/tjbot/config/RoleApplicationSystemConfig.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@
1212
* @param submissionsChannelPattern the pattern used to identify the submissions channel where
1313
* applications are sent
1414
* @param defaultQuestion the default question that will be asked in the role application form
15-
* @param minimumAnswerLength the minimum number of characters required for the applicant's answer
16-
* @param maximumAnswerLength the maximum number of characters allowed for the applicant's answer
17-
* @param applicationSubmitCooldownMinutes the cooldown time in minutes before the user can submit
18-
* another application
1915
*/
2016
public record RoleApplicationSystemConfig(
2117
@JsonProperty(value = "submissionsChannelPattern",
2218
required = true) String submissionsChannelPattern,
23-
@JsonProperty(value = "defaultQuestion", required = true) String defaultQuestion,
24-
@JsonProperty(value = "minimumAnswerLength", required = true) int minimumAnswerLength,
25-
@JsonProperty(value = "maximumAnswerLength", required = true) int maximumAnswerLength,
26-
@JsonProperty(value = "applicationSubmitCooldownMinutes",
27-
required = true) int applicationSubmitCooldownMinutes) {
19+
@JsonProperty(value = "defaultQuestion", required = true) String defaultQuestion) {
2820

2921
/**
3022
* Constructs an instance of {@link RoleApplicationSystemConfig} with the provided parameters.

application/src/main/java/org/togetherjava/tjbot/features/roleapplication/ApplicationApplyHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* users to prevent spamming.
3030
*/
3131
public class ApplicationApplyHandler {
32+
private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5;
33+
3234
private final Cache<Member, OffsetDateTime> applicationSubmitCooldown;
3335
private final Predicate<String> applicationChannelPattern;
3436
private final RoleApplicationSystemConfig roleApplicationSystemConfig;
@@ -46,7 +48,7 @@ public ApplicationApplyHandler(RoleApplicationSystemConfig roleApplicationSystem
4648
.asMatchPredicate();
4749

4850
final Duration applicationSubmitCooldownDuration =
49-
Duration.ofMinutes(roleApplicationSystemConfig.applicationSubmitCooldownMinutes());
51+
Duration.ofMinutes(APPLICATION_SUBMIT_COOLDOWN_MINUTES);
5052
applicationSubmitCooldown =
5153
Caffeine.newBuilder().expireAfterWrite(applicationSubmitCooldownDuration).build();
5254
}
@@ -134,8 +136,7 @@ protected long getMemberCooldownMinutes(Member member) {
134136
OffsetDateTime timeSentCache = getApplicationSubmitCooldown().getIfPresent(member);
135137
if (timeSentCache != null) {
136138
Duration duration = Duration.between(timeSentCache, OffsetDateTime.now());
137-
return roleApplicationSystemConfig.applicationSubmitCooldownMinutes()
138-
- duration.toMinutes();
139+
return APPLICATION_SUBMIT_COOLDOWN_MINUTES - duration.toMinutes();
139140
}
140141
return 0L;
141142
}

application/src/main/java/org/togetherjava/tjbot/features/roleapplication/ApplicationCreateCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ApplicationCreateCommand extends SlashCommandAdapter {
4747
private static final String ROLE_COMPONENT_ID_HEADER = "application-create";
4848
private static final String VALUE_DELIMITER = "_";
4949
private static final int ARG_COUNT = 3;
50+
private static final int MINIMUM_ANSWER_LENGTH = 50;
51+
private static final int MAXIMUM_ANSWER_LENGTH = 500;
5052

5153
private final ApplicationApplyHandler applicationApplyHandler;
5254
private final RoleApplicationSystemConfig roleApplicationSystemConfig;
@@ -136,8 +138,7 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
136138
.create(generateComponentId(event.getUser().getId()),
137139
roleApplicationSystemConfig.defaultQuestion(), TextInputStyle.PARAGRAPH)
138140
.setRequired(true)
139-
.setRequiredRange(roleApplicationSystemConfig.minimumAnswerLength(),
140-
roleApplicationSystemConfig.maximumAnswerLength())
141+
.setRequiredRange(MINIMUM_ANSWER_LENGTH, MAXIMUM_ANSWER_LENGTH)
141142
.setPlaceholder("Enter your answer here")
142143
.build();
143144

0 commit comments

Comments
 (0)