Class BotUtils
java.lang.Object
com.github.alex1304.ultimategdbot.api.utils.BotUtils
public class BotUtils extends Object
Contains various utility methods.
-
Method Summary
Modifier and Type Method Description static reactor.core.publisher.Flux<discord4j.core.object.entity.Message>
debugError(String header, Context ctx, Throwable error)
Sends an error report to the debug log channel.static String
formatDuration(Duration time)
Formats a Duration into a human readable String.static reactor.core.publisher.Mono<Void>
sendPaginatedMessage(Context ctx, String text)
static reactor.core.publisher.Mono<Void>
sendPaginatedMessage(Context ctx, String text, PaginationControls controls)
static reactor.core.publisher.Mono<Void>
sendPaginatedMessage(Context ctx, String text, PaginationControls controls, int pageLength)
static List<String>
splitMessage(String superLongMessage)
Splits a message into several chunks.static List<String>
splitMessage(String superLongMessage, int maxCharacters)
Splits a message into several chunks which size is specified.
-
Method Details
-
splitMessage
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
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
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(String header, Context ctx, 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<Void> sendPaginatedMessage(Context ctx, String text, PaginationControls controls, int pageLength) -
sendPaginatedMessage
public static reactor.core.publisher.Mono<Void> sendPaginatedMessage(Context ctx, String text, PaginationControls controls) -
sendPaginatedMessage
-