Class AbilityUtils
- java.lang.Object
-
- org.telegram.abilitybots.api.util.AbilityUtils
-
public final class AbilityUtils extends Object
Helper and utility methods
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaddTag(String username)static Consumer<MessageContext>commitTo(DBContext db)Commits to DB.static Stringescape(String username)static StringfullName(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.static LonggetChatId(org.telegram.telegrambots.meta.api.objects.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 org.telegram.telegrambots.meta.api.objects.UsergetUser(org.telegram.telegrambots.meta.api.objects.Update update)Fetches the user who caused the update.static booleanisGroupUpdate(org.telegram.telegrambots.meta.api.objects.Update update)A "best-effort" boolean stating whether the update is a group message or not.static Predicate<org.telegram.telegrambots.meta.api.objects.Update>isReplyTo(String msg)static booleanisSuperGroupUpdate(org.telegram.telegrambots.meta.api.objects.Update update)A "best-effort" boolean stating whether the update is a super-group message or not.static booleanisUserMessage(org.telegram.telegrambots.meta.api.objects.Update update)static StringshortName(org.telegram.telegrambots.meta.api.objects.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 StringstripTag(String username)
-
-
-
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 TelegramUpdate- 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 TelegramUpdate- 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 TelegramUpdate- 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 TelegramUpdate- 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 TelegramUpdate- 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:- First name
- Last name
- Username
- 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
-
-