Class BotUtils
java.lang.Object
com.github.alex1304.ultimategdbot.api.utils.BotUtils
public class BotUtils
extends java.lang.Object
Contains various utility methods.
-
Method Summary
Modifier and Type Method Description static reactor.core.publisher.Flux<discord4j.core.object.entity.Message>
debugError(java.lang.String header, Context ctx, java.lang.Throwable error)
Sends an error report to the debug log channel.static java.lang.String
formatDuration(java.time.Duration time)
Formats a Duration into a human readable String.static reactor.core.publisher.Mono<java.lang.Void>
sendPaginatedMessage(Context ctx, java.lang.String text)
static reactor.core.publisher.Mono<java.lang.Void>
sendPaginatedMessage(Context ctx, java.lang.String text, PaginationControls controls)
static reactor.core.publisher.Mono<java.lang.Void>
sendPaginatedMessage(Context ctx, java.lang.String text, PaginationControls controls, int pageLength)
static java.util.List<java.lang.String>
splitMessage(java.lang.String superLongMessage)
Splits a message into several chunks.static java.util.List<java.lang.String>
splitMessage(java.lang.String superLongMessage, int maxCharacters)
Splits a message into several chunks which size is specified.
-
Method Details
-
splitMessage
public static java.util.List<java.lang.String> splitMessage(java.lang.String superLongMessage, int maxCharacters)Splits a message into several chunks which size is specified. If the chunk ends while the text is inside a codeblock or a blockquote, proper markdown is added to make the message continuous across chunks. This does not apply to inline markdown such as bold, italic or spoilers.- Parameters:
superLongMessage
- the message to splitmaxCharacters
- the max characters that a single chunk may have- Returns:
- a List which elements are the chunks in the correct order
-
splitMessage
public static java.util.List<java.lang.String> splitMessage(java.lang.String superLongMessage)Splits a message into several chunks. Each chunk can have a max size ofMessage.MAX_CONTENT_LENGTH
- 10.- Parameters:
superLongMessage
- the message to split- Returns:
- a List which elements are the chunks in the correct order
-
formatDuration
public static java.lang.String formatDuration(java.time.Duration time)Formats a Duration into a human readable String.- Parameters:
time
- the duration to format- Returns:
- the formatted duration
-
debugError
public static reactor.core.publisher.Flux<discord4j.core.object.entity.Message> debugError(java.lang.String header, Context ctx, java.lang.Throwable error)Sends an error report to the debug log channel.- Parameters:
header
- the first sentence to write on the reportctx
- the context of the errorerror
- the error itself- Returns:
- a Flux of messages that were sent in the debug log channel. If the
error report exceeds
Message.MAX_CONTENT_LENGTH
characters, it will be split usingsplitMessage(String)
, in this case the Flux may emit more than one message instance.
-
sendPaginatedMessage
public static reactor.core.publisher.Mono<java.lang.Void> sendPaginatedMessage(Context ctx, java.lang.String text, PaginationControls controls, int pageLength) -
sendPaginatedMessage
public static reactor.core.publisher.Mono<java.lang.Void> sendPaginatedMessage(Context ctx, java.lang.String text, PaginationControls controls) -
sendPaginatedMessage
public static reactor.core.publisher.Mono<java.lang.Void> sendPaginatedMessage(Context ctx, java.lang.String text)
-