Class MessageUtils


  • public final class MessageUtils
    extends Object
    Utility methods to process message content.
    • Method Detail

      • tokenize

        public static reactor.util.function.Tuple2<FlagSet,​List<String>> tokenize​(String flagPrefix,
                                                                                        String input)
        Splits the input into tokens. A token is delimited by double quotes or by whitespaces if there are none. A whitespace character can be escaped using a backslash to indicate that it should not delimit a token, and a double quote can be escaped the same way to indicate that it is intended to be a litteral character and not a token delimiter. Once tokens are extracted, they are separated into flags and arguments. A token starting with "--" followed by at least 1 character is treated as a flag, the rest are arguments.
        Parameters:
        flagPrefix - the prefix used to introduce command flags
        input - the input to tokenize
        Returns:
        a Tuple2 which first value is a FlagSet that contains the tokens that are flags, and second value is a List containing the tokens that are arguments
      • chunk

        public static List<String> chunk​(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 split
        maxCharacters - the max characters that a single chunk may have
        Returns:
        a List which elements are the chunks in the correct order
      • chunk

        public static List<String> chunk​(String superLongMessage)
        Splits a message into several chunks. Each chunk can have a max size of Message.MAX_CONTENT_LENGTH - 10.
        Parameters:
        superLongMessage - the message to split
        Returns:
        a List which elements are the chunks in the correct order