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,36 +57,36 @@ 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 ));
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 )
68
68
.addOption (OptionType .STRING , CONTENT_OPTION , "what to remind you about" , true );
69
69
70
70
this .database = database ;
71
71
}
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 timeAmount = Math .toIntExact (event .getOption (TIME_AMOUNT_OPTION ).getAsLong ());
76
+ String timeUnit = event .getOption (TIME_UNIT_OPTION ).getAsString ();
77
77
String content = event .getOption (CONTENT_OPTION ).getAsString ();
78
78
79
- Instant when = parseWhen (whenAmount , whenUnit );
79
+ Instant remindAt = parseWhen (timeAmount , timeUnit );
80
80
User author = event .getUser ();
81
81
82
- if (!handleIsWhenWithinLimits ( when , event )) {
82
+ if (!handleIsRemindAtWithinLimits ( remindAt , event )) {
83
83
return ;
84
84
}
85
85
if (!handleIsUserBelowMaxPendingReminders (author , event )) {
86
86
return ;
87
87
}
88
88
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 ))
90
90
.setEphemeral (true )
91
91
.queue ();
92
92
@@ -95,7 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
95
95
.setGuildId (event .getGuild ().getIdLong ())
96
96
.setChannelId (event .getChannel ().getIdLong ())
97
97
.setAuthorId (author .getIdLong ())
98
- .setRemindAt (when )
98
+ .setRemindAt (remindAt )
99
99
.setContent (content )
100
100
.insert ());
101
101
}
@@ -115,17 +115,17 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
115
115
return ZonedDateTime .now (ZoneOffset .UTC ).plus (period ).toInstant ();
116
116
}
117
117
118
- private static boolean handleIsWhenWithinLimits (@ NotNull Instant when ,
118
+ private static boolean handleIsRemindAtWithinLimits (@ NotNull Instant remindAt ,
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
- if (when .atZone (ZoneOffset .UTC ).isBefore (maxWhen )) {
122
+ if (remindAt .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