<commit_before>package org.telegram.telegrambots.bots;

/**
 * @author <NAME>
 * @version 1.0
 * @brief TODO
 * @date 14 of January of 2016
 */
public abstract class TelegramLongPollingBot extends AbsSender implements ITelegramLongPollingBot {

}<commit_msg>Modify TelegramLongPollingBot to support commands<commit_after>package org.telegram.telegrambots.bots;

import org.telegram.telegrambots.BotLogger;
import org.telegram.telegrambots.TelegramApiException;
import org.telegram.telegrambots.api.commands.Command;
import org.telegram.telegrambots.api.commands.CommandRegistry;
import org.telegram.telegrambots.api.commands.ICommandRegistery;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;

import java.util.Collection;
import java.util.Map;

/**
 * @author <NAME>
 * @version 1.0
 * @brief TODO
 * @date 14 of January of 2016
 */
public abstract class TelegramLongPollingBot extends AbsSender implements ITelegramLongPollingBot, ICommandRegistery {

    public static final String LOGTAG = "TelegramLongPollingBot";
    private final CommandRegistry commandRegistry;

    public TelegramLongPollingBot() {
        this.commandRegistry = new CommandRegistry(getBotToken());
    }

    @Override
    public final void onUpdateReceived(Update update) {
        if (update.hasMessage()) {
            Message message = update.getMessage();
            if (message.isCommand()) {
                if (!commandRegistry.executeCommand(message)) {
                    SendMessage sendMessage = new SendMessage();
                    sendMessage.setChatId(message.getChatId());
                    sendMessage.setText("The command you provided is not registered for this bot");
                    try {
                        sendMessage(sendMessage);
                    } catch (TelegramApiException e) {
                        BotLogger.error("Cannot send message", LOGTAG, e);
                    }
                }
                return;
            }
        }
        processNonCommandUpdate(update);
    }

    @Override
    public final boolean register(Command command) {
        return commandRegistry.register(command);
    }

    @Override
    public final Map<Command, Boolean> registerAll(Command... commands) {
        return commandRegistry.registerAll(commands);
    }

    @Override
    public final boolean deregister(Command command) {
        return commandRegistry.deregister(command);
    }

    @Override
    public final Map<Command, Boolean> deregisterAll(Command... commands) {
        return commandRegistry.deregisterAll(commands);
    }

    @Override
    public final Collection<Command> getRegisteredCommands() {
        return commandRegistry.getRegisteredCommands();
    }

    public abstract void processNonCommandUpdate(Update update);
}
{'fraction_non_alphanumeric': 0.08635578583765112, 'fraction_numerical': 0.005526770293609672, 'mean_word_length': 2.978021978021978, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2372159', 'n_tokens_mistral': 788, 'n_tokens_neox': 747, 'n_words': 172}