Class AbilityUtils


  • public final class AbilityUtils
    extends Object
    Helper and utility methods
    • Method Detail

      • stripTag

        public static String stripTag​(String username)
        Parameters:
        username - any username
        Returns:
        the username with the preceding "@" stripped off
      • commitTo

        public static Consumer<MessageContext> commitTo​(DBContext db)
        Commits to DB.
        Parameters:
        db - the database to commit on
        Returns:
        a lambda consumer that takes in a MessageContext, used in post actions for abilities
      • getUser

        public static org.telegram.telegrambots.meta.api.objects.User getUser​(org.telegram.telegrambots.meta.api.objects.Update update)
        Fetches the user who caused the update.
        Parameters:
        update - a Telegram Update
        Returns:
        the originating user
        Throws:
        IllegalStateException - if the user could not be found
      • isGroupUpdate

        public static boolean isGroupUpdate​(org.telegram.telegrambots.meta.api.objects.Update update)
        A "best-effort" boolean stating whether the update is a group message or not.
        Parameters:
        update - a Telegram Update
        Returns:
        whether the update is linked to a group
      • isSuperGroupUpdate

        public static boolean isSuperGroupUpdate​(org.telegram.telegrambots.meta.api.objects.Update update)
        A "best-effort" boolean stating whether the update is a super-group message or not.
        Parameters:
        update - a Telegram Update
        Returns:
        whether the update is linked to a group
      • getChatId

        public static Long getChatId​(org.telegram.telegrambots.meta.api.objects.Update update)
        Fetches the direct chat ID of the specified update.
        Parameters:
        update - a Telegram Update
        Returns:
        the originating chat ID
        Throws:
        IllegalStateException - if the chat ID could not be found
      • isUserMessage

        public static boolean isUserMessage​(org.telegram.telegrambots.meta.api.objects.Update update)
        Parameters:
        update - a Telegram Update
        Returns:
        true if the update contains contains a private user message
      • addTag

        public static String addTag​(String username)
        Parameters:
        username - the username to add the tag to
        Returns:
        the username prefixed with the "@" tag.
      • isReplyTo

        public static Predicate<org.telegram.telegrambots.meta.api.objects.Update> isReplyTo​(String msg)
        Parameters:
        msg - the message to be replied to
        Returns:
        a predicate that asserts that the update is a reply to the specified message.
      • getLocalizedMessage

        public static String getLocalizedMessage​(String messageCode,
                                                 Locale locale,
                                                 Object... arguments)
      • getLocalizedMessage

        public static String getLocalizedMessage​(String messageCode,
                                                 String languageCode,
                                                 Object... arguments)
      • shortName

        public static String shortName​(org.telegram.telegrambots.meta.api.objects.User user)
        The short name is one of the following:
        1. First name
        2. Last name
        3. Username
        The method will try to return the first valid name in the specified order.
        Returns:
        the short name of the user
      • fullName

        public static String fullName​(org.telegram.telegrambots.meta.api.objects.User user)
        The full name is identified as the concatenation of the first and last name, separated by a space. This method can return an empty name if both first and last name are empty.
        Parameters:
        user -
        Returns:
        the full name of the user