Class BaseAbilityBot
Object
BaseAbilityBot
- All Implemented Interfaces:
AbilityExtension,LongPollingUpdateConsumer,LongPollingSingleThreadUpdateConsumer
- Direct Known Subclasses:
AbilityBot,AbilityWebhookBot
public abstract class BaseAbilityBot
extends Object
implements AbilityExtension, LongPollingSingleThreadUpdateConsumer
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 implements LongPollingSingleThreadUpdateConsumer.
All bots extending the BaseAbilityBot get 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 DBContext db and the TelegramClient sender.
All bots extending BaseAbilityBot can use both handles in their update consumers.
- Author:
- Abbas Abou Daya
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected final DBContextprotected static final Stringprotected SilentSenderstatic final Stringprotected TelegramClientstatic final Stringstatic final StringFields inherited from interface LongPollingSingleThreadUpdateConsumer
updatesProcessorExecutor -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseAbilityBot(TelegramClient telegramClient, String botUsername, DBContext db, AbilityToggle toggle) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddExtension(AbilityExtension extension) protected voidaddExtensions(Collection<AbilityExtension> extensions) protected voidaddExtensions(AbilityExtension... extensions) admins()protected booleanprotected booleancheckGlobalFlags(Update update) Test the update against the provided global flags.voidconsume(Update update) This method contains the stream of actions that are applied on any update.abstract longprotected Stringprotected StringgetPrivacy(Update update, long id) booleanisAdmin(long id) booleanisCreator(long id) booleanisGroupAdmin(long chatId, long id) booleanisGroupAdmin(Update update, long id) voiduserIds()users()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LongPollingSingleThreadUpdateConsumer
consume
-
Field Details
-
DEFAULT
- See Also:
-
ADMINS
- See Also:
-
USERS
- See Also:
-
USER_ID
- See Also:
-
BLACKLIST
- See Also:
-
STATS
- See Also:
-
db
-
telegramClient
protected TelegramClient telegramClient -
silent
-
-
Constructor Details
-
BaseAbilityBot
protected BaseAbilityBot(TelegramClient telegramClient, String botUsername, DBContext db, AbilityToggle toggle)
-
-
Method Details
-
creatorId
public abstract long creatorId() -
onRegister
public void onRegister() -
users
- Returns:
- the map of <ID,User>
-
userIds
- Returns:
- the map of <Username,ID>
-
blacklist
- Returns:
- a blacklist containing all the IDs of the banned users
-
admins
- Returns:
- an admin set of all the IDs of bot administrators
-
consume
public void consume(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.
- Specified by:
consumein interfaceLongPollingSingleThreadUpdateConsumer- Parameters:
update- the update received by Telegram's API
-
getPrivacy
-
isGroupAdmin
public boolean isGroupAdmin(Update update, long id) -
isGroupAdmin
public boolean isGroupAdmin(long chatId, long id) -
isCreator
public boolean isCreator(long id) -
isAdmin
public boolean isAdmin(long id) -
checkGlobalFlags
protected boolean checkGlobalFlags(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
-
getCommandRegexSplit
-
allowContinuousText
protected boolean allowContinuousText() -
addExtension
-
addExtensions
-
addExtensions
-