public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension
It's important to note that this bot strictly extends TelegramLongPollingBot.
All bots extending the BaseAbilityBot get implicit abilities:
Privacy.CREATOR of the botcreatorId() can genuinely claim the bot@username - promotes user to bot admin@username - demotes bot admin to user@username - bans the user from accessing your bot commands and features@username - lifts the ban from the userAdditional 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 MessageSender sender.
All bots extending BaseAbilityBot can use both handles in their update consumers.
| Modifier and Type | Field and Description |
|---|---|
static String |
ADMINS |
protected static String |
BACKUP |
protected static String |
BAN |
static String |
BLACKLIST |
protected static String |
CLAIM |
protected static String |
COMMANDS |
protected DBContext |
db |
protected static String |
DEFAULT |
protected static String |
DEMOTE |
protected static String |
PROMOTE |
protected static String |
RECOVER |
protected static String |
REPORT |
protected MessageSender |
sender |
protected SilentSender |
silent |
protected static String |
UNBAN |
static String |
USER_ID |
static String |
USERS |
exe| Modifier | Constructor and Description |
|---|---|
protected |
BaseAbilityBot(String botToken,
String botUsername,
DBContext db,
DefaultBotOptions botOptions) |
| Modifier and Type | Method and Description |
|---|---|
Map<String,Ability> |
abilities() |
protected Set<Integer> |
admins() |
Ability |
backupDB()
This backup ability returns the object defined by
DBContext.backup() as a message document. |
Ability |
banUser()
Banned users are accumulated in the blacklist.
|
protected Set<Integer> |
blacklist() |
protected boolean |
checkGlobalFlags(org.telegram.telegrambots.meta.api.objects.Update update)
Test the update against the provided global flags.
|
Ability |
claimCreator()
Regular users and admins who try to claim the bot will get banned.
|
Ability |
commands()
Default format:
|
abstract int |
creatorId() |
Ability |
demoteAdmin() |
String |
getBotToken() |
String |
getBotUsername() |
protected org.telegram.telegrambots.meta.api.objects.User |
getUser(int id)
Gets the user with the specified ID.
|
protected org.telegram.telegrambots.meta.api.objects.User |
getUser(String username)
Gets the user with the specified username.
|
protected int |
getUserIdSendError(String username,
MessageContext ctx)
Gets the user with the specified username.
|
void |
onUpdateReceived(org.telegram.telegrambots.meta.api.objects.Update update)
This method contains the stream of actions that are applied on any update.
|
Ability |
promoteAdmin() |
Ability |
recoverDB()
Recovers the bot database using
DBContext.recover(Object). |
List<Reply> |
replies() |
Ability |
reportCommands()
Format of the report:
|
Ability |
unbanUser()
Usage:
/unban @username |
protected Map<String,Integer> |
userIds() |
protected Map<Integer,org.telegram.telegrambots.meta.api.objects.User> |
users() |
downloadFile, downloadFile, downloadFileAsync, downloadFileAsync, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, getBaseUrl, getOptions, sendApiMethod, sendApiMethodAsyncexecute, executeAsync, getMe, getMeAsync, getWebhookInfo, getWebhookInfoAsyncpublic static final String ADMINS
public static final String USERS
public static final String USER_ID
public static final String BLACKLIST
protected static final String DEFAULT
protected static final String CLAIM
protected static final String BAN
protected static final String PROMOTE
protected static final String DEMOTE
protected static final String UNBAN
protected static final String BACKUP
protected static final String RECOVER
protected static final String COMMANDS
protected static final String REPORT
protected final DBContext db
protected MessageSender sender
protected SilentSender silent
protected BaseAbilityBot(String botToken, String botUsername, DBContext db, DefaultBotOptions botOptions)
public abstract int creatorId()
protected Map<Integer,org.telegram.telegrambots.meta.api.objects.User> users()
protected Set<Integer> blacklist()
public void onUpdateReceived(org.telegram.telegrambots.meta.api.objects.Update update)
It will correctly handle addition of users into the DB and the execution of abilities and replies.
update - the update received by Telegram's APIpublic String getBotToken()
getBotToken in class DefaultAbsSenderpublic String getBotUsername()
protected boolean checkGlobalFlags(org.telegram.telegrambots.meta.api.objects.Update update)
This method should be overridden if the user wants to restrict bot usage to only certain updates.
update - a Telegram Updateprotected org.telegram.telegrambots.meta.api.objects.User getUser(String username)
username - the username of the required userprotected org.telegram.telegrambots.meta.api.objects.User getUser(int id)
id - the id of the required userprotected int getUserIdSendError(String username, MessageContext ctx)
username - the username of the required userctx - the message context with the originating userpublic Ability reportCommands()
Format of the report:
[command1] - [description1]
[command2] - [description2]
...
Once you invoke it, the bot will send the available commands to the chat. This is a public ability so anyone can invoke it.
Usage: /commands
public Ability commands()
PUBLIC
[command1] - [description1]
[command2] - [description2]
GROUP_ADMIN
[command1] - [description1]
...
public Ability backupDB()
DBContext.backup() as a message document.
This is a high-profile ability and is restricted to the CREATOR only.
Usage: /backup
public Ability recoverDB()
DBContext.recover(Object).
The bot recovery process hugely depends on the implementation of the recovery method of DBContext.
Usage: /recover
public Ability banUser()
DBContext.getSet(String) with name specified by BLACKLIST.
Usage: /ban @username
Note that admins who try to ban the creator, get banned.
public Ability unbanUser()
/unban @usernamepublic Ability promoteAdmin()
public Ability demoteAdmin()
public Ability claimCreator()
Copyright © 2019. All rights reserved.