This commit is contained in:
Ruben Bermudez 2017-06-18 14:38:26 +02:00
parent 4dd8205974
commit 082942ac9a
3 changed files with 45 additions and 1 deletions

View File

@ -63,5 +63,7 @@
### <a id="3.0.2"></a>3.0.2 ### ### <a id="3.0.2"></a>3.0.2 ###
1. Bug Fixing: #250 1. Bug Fixing: #250
2. Added new module `telegrambots-extensions` that should contains any extensions of the API such as CommandBot or TimedBot. 2. Added new module `telegrambots-extensions` that should contains any extensions of the API such as CommandBot or TimedBot.
3. `TelegramLongPollingCommandBot` receives now the bot username as constructor parameters, all deprecated constructors will be removed in next mayor release.
4. `getUsername` method from `TelegramLongPollingCommandBot` can be considered `final` and will be so in next mayor release.
**[[How to update to version 3.0.2|How-To-Update#3.0.2]]** **[[How to update to version 3.0.2|How-To-Update#3.0.2]]**

View File

@ -26,4 +26,5 @@
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users. 1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.
### <a id="3.0.2"></a>To version 3.0.2 ### ### <a id="3.0.2"></a>To version 3.0.2 ###
1. If you were using `TelegramLongPollingCommandBot`, add the new [extensions dependency](https://github.com/rubenlagus/TelegramBots/tree/master/telegrambots-extensions) to your maven and fix import statements in your project. 1. If you were using `TelegramLongPollingCommandBot`, add the new [extensions dependency](https://github.com/rubenlagus/TelegramBots/tree/master/telegrambots-extensions) to your maven and fix import statements in your project.
2. If you were using `TelegramLongPollingCommandBot`, make sure you start using constructors with username and prevent overriding `getUsername` method.

View File

@ -22,32 +22,63 @@ import java.util.function.BiConsumer;
*/ */
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry { public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry {
private final CommandRegistry commandRegistry; private final CommandRegistry commandRegistry;
private String botUsername;
/** /**
* Creates a TelegramLongPollingCommandBot using default options * Creates a TelegramLongPollingCommandBot using default options
* Use ICommandRegistry's methods on this bot to register commands * Use ICommandRegistry's methods on this bot to register commands
*
* @deprecated Uses {@link #TelegramLongPollingCommandBot(String)} instead
*/ */
@Deprecated
public TelegramLongPollingCommandBot() { public TelegramLongPollingCommandBot() {
this(ApiContext.getInstance(DefaultBotOptions.class)); this(ApiContext.getInstance(DefaultBotOptions.class));
} }
/**
* Creates a TelegramLongPollingCommandBot using default options
* Use ICommandRegistry's methods on this bot to register commands
*
* @param botUsername Username of the bot
*/
public TelegramLongPollingCommandBot(String botUsername) {
this(ApiContext.getInstance(DefaultBotOptions.class), botUsername);
}
/** /**
* Creates a TelegramLongPollingCommandBot with custom options and allowing commands with * Creates a TelegramLongPollingCommandBot with custom options and allowing commands with
* usernames * usernames
* Use ICommandRegistry's methods on this bot to register commands * Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options * @param options Bot options
*
* @deprecated Use {@link #TelegramLongPollingCommandBot(DefaultBotOptions, String)} instead
*/ */
@Deprecated
public TelegramLongPollingCommandBot(DefaultBotOptions options) { public TelegramLongPollingCommandBot(DefaultBotOptions options) {
this(options, true); this(options, true);
} }
/**
* Creates a TelegramLongPollingCommandBot with custom options and allowing commands with
* usernames
* Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options
* @param botUsername Username of the bot
*/
public TelegramLongPollingCommandBot(DefaultBotOptions options, String botUsername) {
this(options, true, botUsername);
}
/** /**
* Creates a TelegramLongPollingCommandBot * Creates a TelegramLongPollingCommandBot
* Use ICommandRegistry's methods on this bot to register commands * Use ICommandRegistry's methods on this bot to register commands
* @param options Bot options * @param options Bot options
* @param allowCommandsWithUsername true to allow commands with parameters (default), * @param allowCommandsWithUsername true to allow commands with parameters (default),
* false otherwise * false otherwise
*
* @deprecated Use {@link #TelegramLongPollingCommandBot(DefaultBotOptions, boolean, String)} instead
*/ */
@Deprecated
public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) { public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) {
super(options); super(options);
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, getBotUsername()); this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, getBotUsername());
@ -63,6 +94,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
*/ */
public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botUsername) { public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botUsername) {
super(options); super(options);
this.botUsername = botUsername;
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, botUsername); this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, botUsername);
} }
@ -131,6 +163,15 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
return commandRegistry.getRegisteredCommand(commandIdentifier); return commandRegistry.getRegisteredCommand(commandIdentifier);
} }
/**
* TODO This method will become final in next mayor release, avoid overriding it
* @return Bot username
*/
@Override
public String getBotUsername() {
return botUsername;
}
/** /**
* Process all updates, that are not commands. * Process all updates, that are not commands.
* @warning Commands that have valid syntax but are not registered on this bot, * @warning Commands that have valid syntax but are not registered on this bot,