public static CompletableFuture < MessageSet > getMessagesAroundUntil ( TextChannel channel , Predicate < Message > condition , long around ) { CompletableFuture < MessageSet > future = new CompletableFuture <> ( ) ; channel . getApi ( ) . getThreadPool ( ) . getExecutorService ( ) . submit ( ( ) -> { try { List < Message > messages = new ArrayList <> ( ) ; Optional < Message > untilMessage = getMessagesAroundAsStream ( channel , around ) . peek ( messages :: add ) . filter ( condition ) . findFirst ( ) ; future . complete ( new MessageSetImpl ( untilMessage . map ( message -> messages ) . orElse ( Collections . emptyList ( ) ) ) ) ; } catch ( Throwable t ) { future . completeExceptionally ( t ) ; } } ) ; return future ; }
Gets messages in the given channel around a given message in any channel until one that meets the given condition is found . If no message matches the condition an empty set is returned . The given message will be part of the result in addition to the messages around if it was sent in the given channel and is matched against the condition and will abort retrieval . Half of the messages will be older than the given message and half of the messages will be newer . If there aren t enough older or newer messages the halves will not be same - sized . It s also not guaranteed to be perfectly balanced .