public abstract class AbilityBot extends TelegramLongPollingBot
It's important to note that this bot strictly extends TelegramLongPollingBot.
All bots extending the AbilityBot 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 AbilityBot are the DBContext db and the MessageSender sender.
All bots extending AbilityBot 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 |
RECOVER_SUCCESS |
protected static String |
RECOVERY_MESSAGE |
protected MessageSender |
sender |
protected static String |
UNBAN |
static String |
USER_ID |
static String |
USERS |
| Modifier | Constructor and Description |
|---|---|
protected |
AbilityBot(String botToken,
String botUsername) |
protected |
AbilityBot(String botToken,
String botUsername,
DBContext db) |
protected |
AbilityBot(String botToken,
String botUsername,
DBContext db,
DefaultBotOptions botOptions) |
protected |
AbilityBot(String botToken,
String botUsername,
DefaultBotOptions botOptions) |
| Modifier and Type | Method and Description |
|---|---|
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.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.
|
abstract int |
creatorId() |
Ability |
demoteAdmin() |
String |
getBotToken() |
String |
getBotUsername() |
protected EndUser |
getUser(int id)
Gets the user with the specified ID.
|
protected EndUser |
getUser(String username)
Gets the user with the specified username.
|
protected int |
getUserIdSendError(String username,
long chatId)
Gets the user with the specified username.
|
void |
onUpdateReceived(org.telegram.telegrambots.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). |
Ability |
reportCommands()
Format of the report:
|
Ability |
unbanUser()
Usage:
/unban @username |
protected Map<String,Integer> |
userIds() |
protected Map<Integer,EndUser> |
users() |
clearWebhookaddStickerToSet, createNewStickerSet, downloadFile, downloadFile, downloadFileAsync, downloadFileAsync, getBaseUrl, sendApiMethod, sendApiMethodAsync, sendAudio, sendDocument, sendPhoto, sendSticker, sendVideo, sendVideoNote, sendVoice, setChatPhoto, uploadStickerFileanswerCallbackQuery, answerCallbackQueryAsync, answerInlineQuery, answerInlineQueryAsync, answerPreCheckoutQuery, answerPreCheckoutQuery, answerShippingQuery, answerShippingQuery, deleteChatPhoto, deleteChatPhoto, deleteMessage, deleteMessage, deleteWebhook, deleteWebhook, editMessageCaption, editMessageCaptionAsync, editMessageReplyMarkup, editMessageReplyMarkup, editMessageText, editMessageTextAsync, execute, executeAsync, exportChatInviteLink, exportChatInviteLinkAsync, forwardMessage, forwardMessageAsync, getChat, getChatAdministrators, getChatAdministratorsAsync, getChatAsync, getChatMember, getChatMemberAsync, getChatMemberCount, getChatMemberCountAsync, getFile, getFileAsync, getGameHighScores, getGameHighScoresAsync, getMe, getMeAsync, getUserProfilePhotos, getUserProfilePhotosAsync, getWebhookInfo, getWebhookInfoAsync, kickMember, kickMemberAsync, leaveChat, leaveChatAsync, pinChatMessage, pinChatMessage, promoteChatMember, promoteChatMember, restrictChatMember, restrictChatMember, sendChatAction, sendChatActionAsync, sendContact, sendContactAsync, sendGame, sendGameAsync, sendInvoice, sendInvoice, sendLocation, sendLocationAsync, sendMessage, sendMessageAsync, sendVenue, sendVenueAsync, setChatDescription, setChatDescription, setChatTitle, setChatTitle, setGameScore, setGameScoreAsync, unbanMember, unbanMemberAsync, unpinChatMessage, unpinChatMessageclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonClosing, onUpdatesReceivedpublic 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 RECOVERY_MESSAGE
protected static final String RECOVER_SUCCESS
protected final DBContext db
protected MessageSender sender
protected AbilityBot(String botToken, String botUsername, DBContext db, DefaultBotOptions botOptions)
protected AbilityBot(String botToken, String botUsername, DefaultBotOptions botOptions)
public abstract int creatorId()
protected Set<Integer> blacklist()
public void onUpdateReceived(org.telegram.telegrambots.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 interface org.telegram.telegrambots.generics.LongPollingBotgetBotToken in class DefaultAbsSenderpublic String getBotUsername()
protected boolean checkGlobalFlags(org.telegram.telegrambots.api.objects.Update update)
Flag.MESSAGE.
This method should be overridden if the user wants updates that don't require a MESSAGE to pass through.
update - a Telegram Updateprotected EndUser getUser(String username)
username - the username of the required userprotected EndUser getUser(int id)
id - the id of the required userprotected int getUserIdSendError(String username, long chatId)
username - the username of the required 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 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 © 2017. All rights reserved.