Merge branch 'dev' of github.com:rubenlagus/TelegramBots into dev
This commit is contained in:
commit
c9c2b0c187
@ -21,7 +21,7 @@ In order to use Long Polling mode, just create your own bot extending `org.teleg
|
||||
If you like to use Webhook, extend `org.telegram.telegrambots.bots.TelegramWebhookBot`
|
||||
|
||||
|
||||
Once done, you just need to creat a `org.telegram.telegrambots.TelegramBotsApi`and register your bots:
|
||||
Once done, you just need to create a `org.telegram.telegrambots.TelegramBotsApi`and register your bots:
|
||||
|
||||
```java
|
||||
|
||||
@ -59,6 +59,8 @@ https://telegram.me/TGlanguagesbot (**Send files uploding them**)
|
||||
|
||||
https://telegram.me/RaeBot (**Inline support**)
|
||||
|
||||
https://telegram.me/SnowcrashBot (**Webhook support**)
|
||||
|
||||
You can see code for those bots at [TelegramBotsExample](https://github.com/rubenlagus/TelegramBotsExample) project.
|
||||
|
||||
## Telegram Bot API
|
||||
|
@ -14,7 +14,7 @@ import java.util.function.BiConsumer;
|
||||
/**
|
||||
* This class adds command functionality to the TelegramLongPollingBot
|
||||
*
|
||||
* @author tschulz
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry {
|
||||
private final CommandRegistry commandRegistry;
|
||||
|
@ -1,12 +1,13 @@
|
||||
package org.telegram.telegrambots.bots.commands;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.Chat;
|
||||
import org.telegram.telegrambots.api.objects.User;
|
||||
import org.telegram.telegrambots.bots.AbsSender;
|
||||
|
||||
/**
|
||||
* Representation of a command, which can be executed
|
||||
*
|
||||
* @author tschulz
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public abstract class BotCommand {
|
||||
public final static String COMMAND_INIT_CHARACTER = "/";
|
||||
@ -69,8 +70,9 @@ public abstract class BotCommand {
|
||||
* Execute the command
|
||||
*
|
||||
* @param absSender absSender to send messages over
|
||||
* @param user the user who sent the command
|
||||
* @param chat the chat, to be able to send replies
|
||||
* @param arguments passed arguments
|
||||
*/
|
||||
public abstract void execute(AbsSender absSender, Chat chat, String[] arguments);
|
||||
public abstract void execute(AbsSender absSender, User user, Chat chat, String[] arguments);
|
||||
}
|
@ -10,16 +10,15 @@ import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* @author tschulz
|
||||
* This class manages all the commands for a bot. You can register and deregister commands on demand
|
||||
*
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public final class CommandRegistry implements ICommandRegistry {
|
||||
|
||||
private final Map<String, BotCommand> commandRegistryMap = new HashMap<>();
|
||||
private BiConsumer<AbsSender, Message> defaultConsumer;
|
||||
|
||||
public CommandRegistry() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDefaultAction(BiConsumer<AbsSender, Message> defaultConsumer) {
|
||||
this.defaultConsumer = defaultConsumer;
|
||||
@ -87,7 +86,7 @@ public final class CommandRegistry implements ICommandRegistry {
|
||||
|
||||
if (commandRegistryMap.containsKey(command)) {
|
||||
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
|
||||
commandRegistryMap.get(command).execute(absSender, message.getChat(), parameters);
|
||||
commandRegistryMap.get(command).execute(absSender, message.getFrom(), message.getChat(), parameters);
|
||||
return true;
|
||||
} else if (defaultConsumer != null) {
|
||||
defaultConsumer.accept(absSender, message);
|
||||
|
@ -8,7 +8,9 @@ import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* This Interface represents the gateway for registering and deregistering commands.
|
||||
*
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public interface ICommandRegistry {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user