33
33
*/
34
34
public final class RemindCommand extends SlashCommandAdapter {
35
35
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" ;
38
38
private static final String CONTENT_OPTION = "content" ;
39
39
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 =
43
43
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 );
45
45
private static final int MAX_PENDING_REMINDERS_PER_USER = 100 ;
46
46
47
47
private final Database database ;
@@ -57,12 +57,12 @@ public RemindCommand(@NotNull Database database) {
57
57
58
58
// TODO As soon as JDA offers date/time selector input, this should also offer
59
59
// "/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 ));
60
+ OptionData whenAmount = 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 whenUnit = 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 -> whenUnit .addChoice (unit , unit ));
66
66
67
67
getData ().addOptions (whenUnit , whenAmount )
68
68
.addOption (OptionType .STRING , CONTENT_OPTION , "what to remind you about" , true );
@@ -72,8 +72,8 @@ public RemindCommand(@NotNull Database database) {
72
72
73
73
@ Override
74
74
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 whenAmount = Math .toIntExact (event .getOption (TIME_AMOUNT_OPTION ).getAsLong ());
76
+ String whenUnit = event .getOption (TIME_UNIT_OPTION ).getAsString ();
77
77
String content = event .getOption (CONTENT_OPTION ).getAsString ();
78
78
79
79
Instant when = parseWhen (whenAmount , whenUnit );
@@ -117,15 +117,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
117
117
118
118
private static boolean handleIsWhenWithinLimits (@ NotNull Instant when ,
119
119
@ 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 );
121
121
122
122
if (when .atZone (ZoneOffset .UTC ).isBefore (maxWhen )) {
123
123
return true ;
124
124
}
125
125
126
126
event
127
127
.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 ))
129
129
.setEphemeral (true )
130
130
.queue ();
131
131
0 commit comments