44import discord4j .core .event .domain .interaction .ButtonInteractionEvent ;
55import discord4j .core .event .domain .interaction .ChatInputInteractionEvent ;
66import discord4j .core .event .domain .interaction .DeferrableInteractionEvent ;
7- import discord4j .core .object .command .ApplicationCommandInteractionOption ;
8- import discord4j .core .object .command .ApplicationCommandInteractionOptionValue ;
97import discord4j .core .object .entity .Message ;
108import discord4j .core .spec .EmbedCreateSpec ;
119import discord4j .rest .util .Color ;
1210import org .slf4j .Logger ;
1311import org .springframework .stereotype .Component ;
1412import reactor .core .publisher .Mono ;
1513import vc .api .model .ProfileDataImpl ;
14+ import vc .openapi .handler .ApiException ;
1615import vc .openapi .handler .ChatsApi ;
1716import vc .openapi .model .ChatSearchResponse ;
1817
@@ -40,9 +39,7 @@ public String getName() {
4039
4140 @ Override
4241 public Mono <Message > handle (final ChatInputInteractionEvent event ) {
43- Optional <String > wordOptional = event .getOption ("word" )
44- .flatMap (ApplicationCommandInteractionOption ::getValue )
45- .map (ApplicationCommandInteractionOptionValue ::asString );
42+ Optional <String > wordOptional = event .getOptionAsString ("word" );
4643 if (wordOptional .isEmpty ()) {
4744 return error (event , "No word supplied" );
4845 }
@@ -61,9 +58,7 @@ public Mono<Message> handle(final ChatInputInteractionEvent event) {
6158 } catch (Exception e ) {
6259 return error (event , "Invalid date. Required format: YYYY-MM-DD" );
6360 }
64- int page = event .getOption ("page" )
65- .flatMap (ApplicationCommandInteractionOption ::getValue )
66- .map (ApplicationCommandInteractionOptionValue ::asLong )
61+ int page = event .getOptionAsLong ("page" )
6762 .map (Long ::intValue )
6863 .orElse (1 );
6964 if (page <= 0 )
@@ -73,13 +68,16 @@ public Mono<Message> handle(final ChatInputInteractionEvent event) {
7368
7469 public Mono <Message > resolve (DeferrableInteractionEvent event , String word , int page , LocalDate startDate , LocalDate endDate ) {
7570 return Mono .defer (() -> {
76- ChatSearchResponse response ;
71+ ChatSearchResponse response = null ;
7772 try {
7873 response = chatsApi .chatSearch (word , startDate , endDate , 25 , page );
7974 } catch (final Exception e ) {
80- LOGGER .error ("Error searching chats for word: {}" , word , e );
81- return error (event , "Error during search" );
75+ if (!(e instanceof ApiException apiException ) || apiException .getCode () != 204 ) {
76+ LOGGER .error ("Error searching for word: {}" , word , e );
77+ }
8278 }
79+ if (response == null || response .getChats () == null || response .getChats ().isEmpty ())
80+ return error (event , "No chats found" );
8381 var chatStrings = response .getChats ().stream ()
8482 .map (c -> SHORT_DATE_TIME .format (c .getTime ().toInstant ()) + " **" + escape (c .getPlayerName ()) + ":** " + escape (c .getChat ()))
8583 .toList ();
0 commit comments