3333 */
3434public final class RemindCommand extends SlashCommandAdapter {
3535 private static final String COMMAND_NAME = "remind" ;
36- private static final String WHEN_AMOUNT_OPTION = "when -amount" ;
37- private static final String WHEN_UNIT_OPTION = "when -unit" ;
36+ private static final String TIME_AMOUNT_OPTION = "time -amount" ;
37+ private static final String TIME_UNIT_OPTION = "time -unit" ;
3838 private static final String CONTENT_OPTION = "content" ;
3939
40- private static final int MIN_WHEN_AMOUNT = 1 ;
41- private static final int MAX_WHEN_AMOUNT = 1_000 ;
42- private static final List <String > WHEN_UNITS =
40+ private static final int MIN_TIME_AMOUNT = 1 ;
41+ private static final int MAX_TIME_AMOUNT = 1_000 ;
42+ private static final List <String > TIME_UNITS =
4343 List .of ("minutes" , "hours" , "days" , "weeks" , "months" , "years" );
44- private static final Period MAX_WHEN_PERIOD = Period .ofYears (3 );
44+ private static final Period MAX_TIME_PERIOD = Period .ofYears (3 );
4545 private static final int MAX_PENDING_REMINDERS_PER_USER = 100 ;
4646
4747 private final Database database ;
@@ -57,36 +57,36 @@ public RemindCommand(@NotNull Database database) {
5757
5858 // TODO As soon as JDA offers date/time selector input, this should also offer
5959 // "/remind at" next to "/remind in" and use subcommands then
60- OptionData whenAmount = new OptionData (OptionType .INTEGER , WHEN_AMOUNT_OPTION ,
61- "when to remind you, the amount of the time period (e.g. [5] weeks)" , true )
62- .setRequiredRange (MIN_WHEN_AMOUNT , MAX_WHEN_AMOUNT );
63- OptionData whenUnit = new OptionData (OptionType .STRING , WHEN_UNIT_OPTION ,
64- "when to remind you, the unit of the time period (e.g. 5 [weeks])" , true );
65- WHEN_UNITS .forEach (unit -> whenUnit .addChoice (unit , unit ));
66-
67- getData ().addOptions (whenUnit , whenAmount )
60+ OptionData timeAmount = new OptionData (OptionType .INTEGER , TIME_AMOUNT_OPTION ,
61+ "period to remind you in , the amount of time (e.g. [5] weeks)" , true )
62+ .setRequiredRange (MIN_TIME_AMOUNT , MAX_TIME_AMOUNT );
63+ OptionData timeUnit = new OptionData (OptionType .STRING , TIME_UNIT_OPTION ,
64+ "period to remind you in , the unit of time (e.g. 5 [weeks])" , true );
65+ TIME_UNITS .forEach (unit -> timeUnit .addChoice (unit , unit ));
66+
67+ getData ().addOptions (timeUnit , timeAmount )
6868 .addOption (OptionType .STRING , CONTENT_OPTION , "what to remind you about" , true );
6969
7070 this .database = database ;
7171 }
7272
7373 @ Override
7474 public void onSlashCommand (@ NotNull SlashCommandEvent event ) {
75- int whenAmount = Math .toIntExact (event .getOption (WHEN_AMOUNT_OPTION ).getAsLong ());
76- String whenUnit = event .getOption (WHEN_UNIT_OPTION ).getAsString ();
75+ int timeAmount = Math .toIntExact (event .getOption (TIME_AMOUNT_OPTION ).getAsLong ());
76+ String timeUnit = event .getOption (TIME_UNIT_OPTION ).getAsString ();
7777 String content = event .getOption (CONTENT_OPTION ).getAsString ();
7878
79- Instant when = parseWhen (whenAmount , whenUnit );
79+ Instant remindAt = parseWhen (timeAmount , timeUnit );
8080 User author = event .getUser ();
8181
82- if (!handleIsWhenWithinLimits ( when , event )) {
82+ if (!handleIsRemindAtWithinLimits ( remindAt , event )) {
8383 return ;
8484 }
8585 if (!handleIsUserBelowMaxPendingReminders (author , event )) {
8686 return ;
8787 }
8888
89- event .reply ("Will remind you about '%s' in %d %s." .formatted (content , whenAmount , whenUnit ))
89+ event .reply ("Will remind you about '%s' in %d %s." .formatted (content , timeAmount , timeUnit ))
9090 .setEphemeral (true )
9191 .queue ();
9292
@@ -95,7 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
9595 .setGuildId (event .getGuild ().getIdLong ())
9696 .setChannelId (event .getChannel ().getIdLong ())
9797 .setAuthorId (author .getIdLong ())
98- .setRemindAt (when )
98+ .setRemindAt (remindAt )
9999 .setContent (content )
100100 .insert ());
101101 }
@@ -115,17 +115,17 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
115115 return ZonedDateTime .now (ZoneOffset .UTC ).plus (period ).toInstant ();
116116 }
117117
118- private static boolean handleIsWhenWithinLimits (@ NotNull Instant when ,
118+ private static boolean handleIsRemindAtWithinLimits (@ NotNull Instant remindAt ,
119119 @ NotNull Interaction event ) {
120- ZonedDateTime maxWhen = ZonedDateTime .now (ZoneOffset .UTC ).plus (MAX_WHEN_PERIOD );
120+ ZonedDateTime maxWhen = ZonedDateTime .now (ZoneOffset .UTC ).plus (MAX_TIME_PERIOD );
121121
122- if (when .atZone (ZoneOffset .UTC ).isBefore (maxWhen )) {
122+ if (remindAt .atZone (ZoneOffset .UTC ).isBefore (maxWhen )) {
123123 return true ;
124124 }
125125
126126 event
127127 .reply ("The reminder is set too far in the future. The maximal allowed period is '%s'."
128- .formatted (MAX_WHEN_PERIOD ))
128+ .formatted (MAX_TIME_PERIOD ))
129129 .setEphemeral (true )
130130 .queue ();
131131
0 commit comments