88import reactor .core .publisher .Mono ;
99import vc .api .model .ProfileData ;
1010import vc .util .PlayerLookup ;
11- import vc .util .TriFunction ;
1211import vc .util .Validator ;
1312
13+ import java .time .LocalDate ;
1414import java .util .Optional ;
15- import java .util .function .BiFunction ;
1615
1716public abstract class PlayerLookupCommand implements SlashCommand {
1817 protected final PlayerLookup playerLookup ;
@@ -28,7 +27,12 @@ EmbedCreateSpec.Builder populateIdentity(final EmbedCreateSpec.Builder builder,
2827 .addField ("\u200B " , "\u200B " , true );
2928 }
3029
31- Mono <Message > resolveData (ChatInputInteractionEvent event , BiFunction <ChatInputInteractionEvent , ProfileData , Mono <Message >> resolveFunction ) {
30+ @ FunctionalInterface
31+ public interface SimpleResolveFunction {
32+ Mono <Message > resolve (ChatInputInteractionEvent event , ProfileData identity );
33+ }
34+
35+ Mono <Message > resolveData (ChatInputInteractionEvent event , SimpleResolveFunction resolveFunction ) {
3236 Optional <String > playerNameOptional = event .getOption ("player" )
3337 .flatMap (ApplicationCommandInteractionOption ::getValue )
3438 .map (ApplicationCommandInteractionOptionValue ::asString );
@@ -45,11 +49,16 @@ Mono<Message> resolveData(ChatInputInteractionEvent event, BiFunction<ChatInputI
4549 return error (event , "Unable to find player" );
4650 }
4751 ProfileData identity = playerIdentityOptional .get ();
48- return resolveFunction .apply (event , identity );
52+ return resolveFunction .resolve (event , identity );
4953 });
5054 }
5155
52- Mono <Message > resolveData (ChatInputInteractionEvent event , TriFunction <ChatInputInteractionEvent , ProfileData , Integer , Mono <Message >> resolveFunction ) {
56+ @ FunctionalInterface
57+ public interface PaginatedResolveFunction {
58+ Mono <Message > resolve (ChatInputInteractionEvent event , ProfileData identity , int page , LocalDate startDate , LocalDate endDate );
59+ }
60+
61+ Mono <Message > resolveData (ChatInputInteractionEvent event , PaginatedResolveFunction resolveFunction ) {
5362 Optional <String > playerNameOptional = event .getOption ("player" )
5463 .flatMap (ApplicationCommandInteractionOption ::getValue )
5564 .map (ApplicationCommandInteractionOptionValue ::asString );
@@ -60,6 +69,17 @@ Mono<Message> resolveData(ChatInputInteractionEvent event, TriFunction<ChatInput
6069 if (!Validator .isValidPlayerName (playerName )) {
6170 return error (event , "Invalid player name" );
6271 }
72+ LocalDate startDate ;
73+ LocalDate endDate ;
74+ try {
75+ startDate = getLocalDateIfPresent (event , "startdate" );
76+ endDate = getLocalDateIfPresent (event , "enddate" );
77+ if (startDate != null && endDate != null && startDate .isAfter (endDate )) {
78+ return error (event , "Start Date must be before End Date" );
79+ }
80+ } catch (Exception e ) {
81+ return error (event , "Invalid date. Required format: YYYY-MM-DD" );
82+ }
6383 int page = event .getOption ("page" )
6484 .flatMap (ApplicationCommandInteractionOption ::getValue )
6585 .map (ApplicationCommandInteractionOptionValue ::asLong )
@@ -73,7 +93,7 @@ Mono<Message> resolveData(ChatInputInteractionEvent event, TriFunction<ChatInput
7393 return error (event , "Unable to find player" );
7494 }
7595 ProfileData identity = playerIdentityOptional .get ();
76- return resolveFunction .apply (event , identity , page );
96+ return resolveFunction .resolve (event , identity , page , startDate , endDate );
7797 });
7898 }
7999}
0 commit comments