Skip to content

Commit

Permalink
feat(cooldown): use the proper word depending on count
Browse files Browse the repository at this point in the history
  • Loading branch information
christolis committed Oct 19, 2024
1 parent 0291813 commit a226d33
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
}

long remainingMinutes = applicationApplyHandler.getMemberCooldownMinutes(member);
String correctMinutesWord = selectWordFromCount(remainingMinutes, "minute", "minutes");

if (remainingMinutes > 0) {
event
.reply("Please wait %d minutes before sending a new application form."
.formatted(remainingMinutes))
.reply("Please wait %d %s before sending a new application form."
.formatted(remainingMinutes, correctMinutesWord))
.setEphemeral(true)
.queue();
return;
Expand Down Expand Up @@ -157,6 +159,23 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
event.replyModal(modal).queue();
}

/**
* Selects and returns the appropriate singular or plural form of a word based on the given
* count.
*
* @param singularForm the word in its singular form
* @param pluralForm the word in its plural form
* @param count the number used to determine whether to return the singular or plural form
* @return the singular form if count equals 1, otherwise the plural form
*/
private String selectWordFromCount(final Number count, final String singularForm,
final String pluralForm) {
if (count.intValue() == 1) {
return singularForm;
}
return pluralForm;
}

/**
* Checks a given list of passed arguments (from a user) and calculates how many roles have
* missing data.
Expand Down

0 comments on commit a226d33

Please sign in to comment.