Package org.telegram.abilitybots.api.bot
Class BaseAbilityBot
- java.lang.Object
-
- org.telegram.telegrambots.meta.bots.AbsSender
-
- org.telegram.telegrambots.bots.DefaultAbsSender
-
- org.telegram.abilitybots.api.bot.BaseAbilityBot
-
- All Implemented Interfaces:
AbilityExtension
- Direct Known Subclasses:
AbilityBot,AbilityWebhookBot
public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension
The father of all ability bots. Bots that need to utilize abilities need to extend this bot.It's important to note that this bot strictly extends
DefaultAbsSender.All bots extending the
BaseAbilityBotget implicit abilities:- /claim - Claims this bot
- Sets the user as the
Privacy.CREATORof the bot - Only the user with the ID returned by
creatorId()can genuinely claim the bot - /report - reports all user-defined commands (abilities)
- The same format acceptable by BotFather
- /commands - returns a list of all possible bot commands based on the privacy of the requesting user
- /backup - returns a backup of the bot database
- /recover - recovers the database
- /promote
@username- promotes user to bot admin - /demote
@username- demotes bot admin to user - /ban
@username- bans the user from accessing your bot commands and features - /unban
@username- lifts the ban from the user
Additional information of the implicit abilities are present in the methods that declare them.
The two most important handles in the BaseAbilityBot are the
DBContextdband theMessageSendersender. All bots extending BaseAbilityBot can use both handles in their update consumers.- Author:
- Abbas Abou Daya
-
-
Field Summary
Fields Modifier and Type Field Description static StringADMINSstatic StringBLACKLISTprotected DBContextdbprotected static StringDEFAULTprotected MessageSendersenderprotected SilentSendersilentstatic StringSTATSstatic StringUSER_IDstatic StringUSERS-
Fields inherited from class org.telegram.telegrambots.bots.DefaultAbsSender
exe
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseAbilityBot(String botToken, String botUsername, DBContext db, AbilityToggle toggle, DefaultBotOptions botOptions)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Map<String,Ability>abilities()protected voidaddExtension(AbilityExtension extension)protected voidaddExtensions(Collection<AbilityExtension> extensions)protected voidaddExtensions(AbilityExtension... extensions)Set<Integer>admins()protected booleanallowContinuousText()Set<Integer>blacklist()protected booleancheckGlobalFlags(org.telegram.telegrambots.meta.api.objects.Update update)Test the update against the provided global flags.abstract intcreatorId()DBContextdb()StringgetBotToken()StringgetBotUsername()protected StringgetCommandPrefix()protected StringgetCommandRegexSplit()PrivacygetPrivacy(org.telegram.telegrambots.meta.api.objects.Update update, int id)booleanisAdmin(Integer id)booleanisCreator(int id)booleanisGroupAdmin(long chatId, int id)booleanisGroupAdmin(org.telegram.telegrambots.meta.api.objects.Update update, int id)voidonRegister()voidonUpdateReceived(org.telegram.telegrambots.meta.api.objects.Update update)This method contains the stream of actions that are applied on any update.List<Reply>replies()MessageSendersender()SilentSendersilent()Map<String,Stats>stats()Map<String,Integer>userIds()Map<Integer,org.telegram.telegrambots.meta.api.objects.User>users()-
Methods inherited from class org.telegram.telegrambots.bots.DefaultAbsSender
downloadFile, downloadFile, downloadFile, downloadFile, downloadFileAsStream, downloadFileAsStream, downloadFileAsync, downloadFileAsync, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, getBaseUrl, getOptions, sendApiMethod, sendApiMethodAsync, sendApiMethodAsync
-
-
-
-
Field Detail
-
DEFAULT
protected static final String DEFAULT
- See Also:
- Constant Field Values
-
ADMINS
public static final String ADMINS
- See Also:
- Constant Field Values
-
USERS
public static final String USERS
- See Also:
- Constant Field Values
-
USER_ID
public static final String USER_ID
- See Also:
- Constant Field Values
-
BLACKLIST
public static final String BLACKLIST
- See Also:
- Constant Field Values
-
STATS
public static final String STATS
- See Also:
- Constant Field Values
-
db
protected final DBContext db
-
sender
protected MessageSender sender
-
silent
protected SilentSender silent
-
-
Constructor Detail
-
BaseAbilityBot
protected BaseAbilityBot(String botToken, String botUsername, DBContext db, AbilityToggle toggle, DefaultBotOptions botOptions)
-
-
Method Detail
-
creatorId
public abstract int creatorId()
-
onRegister
public void onRegister()
-
db
public DBContext db()
- Returns:
- the database of this bot
-
sender
public MessageSender sender()
- Returns:
- the message sender for this bot
-
silent
public SilentSender silent()
- Returns:
- the silent sender for this bot
-
users
public Map<Integer,org.telegram.telegrambots.meta.api.objects.User> users()
- Returns:
- the map of
-
blacklist
public Set<Integer> blacklist()
- Returns:
- a blacklist containing all the IDs of the banned users
-
stats
public Map<String,Stats> stats()
- Returns:
- a mapping of ability and reply names to their corresponding statistics
-
onUpdateReceived
public void onUpdateReceived(org.telegram.telegrambots.meta.api.objects.Update update)
This method contains the stream of actions that are applied on any update.It will correctly handle addition of users into the DB and the execution of abilities and replies.
- Parameters:
update- the update received by Telegram's API
-
getBotToken
public String getBotToken()
- Specified by:
getBotTokenin classDefaultAbsSender
-
getBotUsername
public String getBotUsername()
-
getPrivacy
public Privacy getPrivacy(org.telegram.telegrambots.meta.api.objects.Update update, int id)
-
isGroupAdmin
public boolean isGroupAdmin(org.telegram.telegrambots.meta.api.objects.Update update, int id)
-
isGroupAdmin
public boolean isGroupAdmin(long chatId, int id)
-
isCreator
public boolean isCreator(int id)
-
isAdmin
public boolean isAdmin(Integer id)
-
checkGlobalFlags
protected boolean checkGlobalFlags(org.telegram.telegrambots.meta.api.objects.Update update)
Test the update against the provided global flags. The default implementation is a passthrough to all updates.This method should be overridden if the user wants to restrict bot usage to only certain updates.
- Parameters:
update- a TelegramUpdate- Returns:
- true if the update satisfies the global flags
-
getCommandPrefix
protected String getCommandPrefix()
-
getCommandRegexSplit
protected String getCommandRegexSplit()
-
allowContinuousText
protected boolean allowContinuousText()
-
addExtension
protected void addExtension(AbilityExtension extension)
-
addExtensions
protected void addExtensions(AbilityExtension... extensions)
-
addExtensions
protected void addExtensions(Collection<AbilityExtension> extensions)
-
-