Class BotUtils


  • public class BotUtils
    extends Object
    Contains various utility methods.
    • Method Detail

      • generateDefaultDocumentation

        public static reactor.core.publisher.Mono<String> generateDefaultDocumentation​(Command cmd,
                                                                                       Context ctx,
                                                                                       String cmdName)
        Generates a default documentation for the command in a String format.
        Parameters:
        cmd - the command to generate the doc for
        ctx - the context to generate a more specific documentation according to the user permissions etc
        cmdName - the alias that should be used for the command name
        Returns:
        the documentation
      • occurrences

        public static int occurrences​(String str,
                                      String substr)
      • chunkMessage

        public static List<String> chunkMessage​(String superLongMessage,
                                                int maxCharacters)
        Splits a message into several chunks which size is specified.
        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
      • chunkMessage

        public static List<String> chunkMessage​(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
      • sendMultipleMessagesToOneChannel

        public static reactor.core.publisher.Flux<discord4j.core.object.entity.Message> sendMultipleMessagesToOneChannel​(reactor.core.publisher.Mono<discord4j.core.object.entity.Channel> channel,
                                                                                                                         Iterable<java.util.function.Consumer<discord4j.core.spec.MessageCreateSpec>> specs)
      • sendMultipleSimpleMessagesToOneChannel

        public static reactor.core.publisher.Flux<discord4j.core.object.entity.Message> sendMultipleSimpleMessagesToOneChannel​(reactor.core.publisher.Mono<discord4j.core.object.entity.Channel> channel,
                                                                                                                               Iterable<String> strings)
      • sendOneMessageToMultipleChannels

        public static reactor.core.publisher.Flux<discord4j.core.object.entity.Message> sendOneMessageToMultipleChannels​(reactor.core.publisher.Flux<discord4j.core.object.entity.Channel> channels,
                                                                                                                         java.util.function.Consumer<discord4j.core.spec.MessageCreateSpec> spec)
      • removeQuotesUnlessEscaped

        public static String removeQuotesUnlessEscaped​(String text)
      • escapeMarkdown

        public static String escapeMarkdown​(String text)
        Escapes characters used in Markdown syntax using a backslash
        Parameters:
        text - the Markdown text to escape
        Returns:
        String
      • formatDiscordUsername

        public static String formatDiscordUsername​(discord4j.core.object.entity.User user)
        Formats the username of the user specified as argument with the format username#discriminator
        Parameters:
        user - The user whom username will be formatted
        Returns:
        The formatted username as String.
      • convertStringToUser

        public static reactor.core.publisher.Mono<discord4j.core.object.entity.User> convertStringToUser​(Bot bot,
                                                                                                         String str)
      • formatTimeMillis

        public static String formatTimeMillis​(java.time.Duration time)
      • getGitPropertiesForPlugin

        public static Properties getGitPropertiesForPlugin​(Plugin plugin)