Skip to content

Commit a226d33

Browse files
committed
feat(cooldown): use the proper word depending on count
1 parent 0291813 commit a226d33

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
121121
}
122122

123123
long remainingMinutes = applicationApplyHandler.getMemberCooldownMinutes(member);
124+
String correctMinutesWord = selectWordFromCount(remainingMinutes, "minute", "minutes");
125+
124126
if (remainingMinutes > 0) {
125127
event
126-
.reply("Please wait %d minutes before sending a new application form."
127-
.formatted(remainingMinutes))
128+
.reply("Please wait %d %s before sending a new application form."
129+
.formatted(remainingMinutes, correctMinutesWord))
128130
.setEphemeral(true)
129131
.queue();
130132
return;
@@ -157,6 +159,23 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
157159
event.replyModal(modal).queue();
158160
}
159161

162+
/**
163+
* Selects and returns the appropriate singular or plural form of a word based on the given
164+
* count.
165+
*
166+
* @param singularForm the word in its singular form
167+
* @param pluralForm the word in its plural form
168+
* @param count the number used to determine whether to return the singular or plural form
169+
* @return the singular form if count equals 1, otherwise the plural form
170+
*/
171+
private String selectWordFromCount(final Number count, final String singularForm,
172+
final String pluralForm) {
173+
if (count.intValue() == 1) {
174+
return singularForm;
175+
}
176+
return pluralForm;
177+
}
178+
160179
/**
161180
* Checks a given list of passed arguments (from a user) and calculates how many roles have
162181
* missing data.

0 commit comments

Comments
 (0)