Class AbilityUtils
Object
AbilityUtils
Helper and utility methods
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic Consumer<MessageContext>Commits to DB.static Stringstatic StringfullName(User user) The full name is identified as the concatenation of the first and last name, separated by a space.static LonggetChatId(Update update) Fetches the direct chat ID of the specified update.static StringgetLocalizedMessage(String messageCode, String languageCode, Object... arguments) static StringgetLocalizedMessage(String messageCode, Locale locale, Object... arguments) static UsergetUser(Update update) Fetches the user who caused the update.static booleanisGroupUpdate(Update update) A "best-effort" boolean stating whether the update is a group message or not.static Predicate<Update>static booleanisSuperGroupUpdate(Update update) A "best-effort" boolean stating whether the update is a super-group message or not.static booleanisUserMessage(Update update) static booleanisValidCommand(String command) Checks if the passed string is a valid bot command according to the requirements of Telegram Bot API: "A command must always start with the '/' symbol and may not be longer than 32 characters.static booleanisValidCommandName(String commandName) Checks if the passed String is a valid command name.static StringshortName(User user) The short name is one of the following: First name Last name Username The method will try to return the first valid name in the specified order.static String
-
Field Details
-
EMPTY_USER
public static User EMPTY_USER
-
-
Method Details
-
stripTag
- Parameters:
username- any username- Returns:
- the username with the preceding "@" stripped off
-
commitTo
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 User getUser(Update update) Fetches the user who caused the update.- Parameters:
update- a TelegramUpdate- Returns:
- the originating user
- Throws:
IllegalStateException- if the user could not be found
-
isGroupUpdate
public static boolean isGroupUpdate(Update update) A "best-effort" boolean stating whether the update is a group message or not.- Parameters:
update- a TelegramUpdate- Returns:
- whether the update is linked to a group
-
isSuperGroupUpdate
public static boolean isSuperGroupUpdate(Update update) A "best-effort" boolean stating whether the update is a super-group message or not.- Parameters:
update- a TelegramUpdate- Returns:
- whether the update is linked to a group
-
getChatId
Fetches the direct chat ID of the specified update.- Parameters:
update- a TelegramUpdate- Returns:
- the originating chat ID
- Throws:
IllegalStateException- if the chat ID could not be found
-
isUserMessage
public static boolean isUserMessage(Update update) - Parameters:
update- a TelegramUpdate- Returns:
- true if the update contains contains a private user message
-
addTag
- Parameters:
username- the username to add the tag to- Returns:
- the username prefixed with the "@" tag.
-
isReplyTo
- Parameters:
msg- the message to be replied to- Returns:
- a predicate that asserts that the update is a reply to the specified message.
-
getLocalizedMessage
-
getLocalizedMessage
-
shortName
The short name is one of the following:- First name
- Last name
- Username
- Returns:
- the short name of the user
-
fullName
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- User to use- Returns:
- the full name of the user
-
escape
-
isValidCommand
Checks if the passed string is a valid bot command according to the requirements of Telegram Bot API: "A command must always start with the '/' symbol and may not be longer than 32 characters. Commands can use latin letters, numbers and underscores." (https://core.telegram.org/bots#commands)- Parameters:
command- String representation of a command to be checked for validity- Returns:
- whether the command is valid
-
isValidCommandName
Checks if the passed String is a valid command name. Command name is text of a command without leading '/'- Parameters:
commandName- the command name to be checked for validity- Returns:
- whether the command name is valid
-