Java Code Examples for com.pengrad.telegrambot.model.Message#text()

The following examples show how to use com.pengrad.telegrambot.model.Message#text() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandHelper.java    From Telephoto with Apache License 2.0 6 votes vote down vote up
public void executeCommand(Message message, Prefs prefs) throws NoCommandException {
    final long chatId = message.chat().id();
    String text = message.text();
    Prefs.UserPrefs user = prefs.getUser(message.from());

    ICommand command = findCommand(text);
    if (command == null) {
        command = lastUserCommand.get(user);
        lastUserCommand.remove(user);
        if (command == null) {
            throw new NoCommandException(text);
        }
    }

    L.i("Message from " + message.from().username() + ": " + command.getCommand());
    if (command.execute(message, prefs)) {
        lastUserCommand.put(user, command);
    } else {
        telegramService.sendMessage(chatId, botService.getString(R.string.please_select_command), mainKeyboard);
    }
}
 
Example 2
Source File: AlarmSettingsCommand.java    From Telephoto with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean execute(Message message, Prefs prefs) {
        final long chatId = message.chat().id();
        String text = message.text();
        AlarmType alarmType = AlarmType.getByName(text);

        if (alarmType == null) {
            telegramService.sendMessage(chatId, "Choose alarm type", KeyboardUtils.getKeyboard(AlarmType.values()));
            return true;
        } else {
            prefs.alarmType = alarmType;

            telegramService.notifyToOthers(message.from().id(), "set alarm mode to: " + alarmType);
            telegramService.sendMessage(chatId, "Alarm mode now: " + alarmType);
            // TODO: 09.04.2017 mainKeyb
//            telegramService.sendMessage(chatId, "Alarm mode now: " + alarmType, mainKeyBoard);

            PrefsController.instance.setPrefs(prefs);
            return false;
        }
    }
 
Example 3
Source File: CameraModeCommand.java    From Telephoto with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean execute(Message message, Prefs prefs) {
        final long chatId = message.chat().id();
        String text = message.text();
        final CameraMode mode = CameraMode.getByName(text);
        if (mode != null) {
            if (FabricUtils.isAvailable(mode)) {
                prefs.cameraMode = mode;
                PrefsController.instance.setPrefs(prefs);
                telegramService.sendMessage(chatId, botService.getString(R.string.camera_mode_changed) + mode);
                // TODO: 09.04.2017 mainK
//                telegramService.sendMessage(chatId, botService.getString(R.string.camera_mode_changed) + mode, mainKeyBoard);
                telegramService.notifyToOthers(message.from().id(), botService.getString(R.string.user_changed_camera_mode) + mode);
            } else {
                telegramService.sendMessage(chatId, botService.getString(R.string.camera_not_supported));
                // TODO: 09.04.2017 mainK
//                telegramService.sendMessage(chatId, botService.getString(R.string.camera_not_supported), mainKeyBoard);
            }
            return false;
        } else {
            telegramService.sendMessage(chatId, botService.getString(R.string.select_camera_mode), KeyboardUtils.getKeyboard(CameraMode.values()));
            return true;
        }
    }
 
Example 4
Source File: MdModeCommand.java    From Telephoto with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean execute(Message message, Prefs prefs) {
        final long chatId = message.chat().id();
        if (!PrefsController.instance.isPro()) {
            telegramService.sendMessage(chatId, botService.getString(R.string.only_pro));
            return false;
        } else {
            String text = message.text();
            final CameraMode mode = CameraMode.getByName(text);
            if (mode != null) {
                if (FabricUtils.isAvailable(mode)) {
                    if (mode == CameraMode.ALL) {
                        telegramService.sendMessage(chatId, "Sorry, but ALL mode is not supported yet for motion detection!");
                        // TODO: 09.04.2017 mainK
//                        telegramService.sendMessage(chatId, "Sorry, but ALL mode is not supported yet for motion detection!", mainKeyboard);
                    } else {
                        prefs.mdMode = mode;
                        PrefsController.instance.setPrefs(prefs);
                        telegramService.sendMessage(chatId, "Camera motion detector mode was successful changed to " + mode);
                        telegramService.notifyToOthers(message.from().id(), "changed camera motion detector mode to " + mode);
                    }
                } else {
                    telegramService.sendMessage(chatId, botService.getString(R.string.camera_not_supported));
                }
                return false;
            } else {
                telegramService.sendMessage(chatId, botService.getString(R.string.select_camera_mode),
                        KeyboardUtils.getKeyboard(CameraMode.values()));
                return true;
            }
        }
    }
 
Example 5
Source File: TaskerCommand.java    From Telephoto with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean execute(Message message, Prefs prefs) {
        final long chatId = message.chat().id();

        String cmd = message.text();
        if (cmd.toLowerCase().startsWith("/tasker")) {
            cmd = cmd.substring(7).trim();
        }
        if (cmd.toLowerCase().startsWith("tasker")) {
            cmd = cmd.substring(6).trim();
        }

        if (!Strings.isNullOrEmpty(cmd)) {
            if ( TaskerIntent.testStatus(botService).equals(TaskerIntent.Status.OK) ) {
                TaskerIntent i = new TaskerIntent(cmd);
                botService.sendBroadcast(i);

                telegramService.sendMessage(chatId, "Command '" + cmd + "' was sent to Tasker.");
                // TODO: 09.04.2017 mainK
//                telegramService.sendMessage(chatId, "Command '" + cmd + "' was sent to Tasker.", mainKeyBoard);
                telegramService.notifyToOthers(message.from().id(), " sent command '" + cmd + "' to tasker.");
            } else {
                telegramService.sendMessage(chatId, "Tasker not ready. Please install it and enable external control.");
                // TODO: 09.04.2017 mainK
//                telegramService.sendMessage(chatId, "Tasker not ready. Please install it and enable external control.", mainKeyBoard);
            }
            return false;
        } else {
            telegramService.sendMessage(chatId, "Type command name:");
            return true;
        }
    }
 
Example 6
Source File: CameraSettingsCommand.java    From Telephoto with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean execute(Message message, Prefs prefs) {
        final long chatId = message.chat().id();

        String text = message.text();

        SelectCamera cameraType = SelectCamera.getByName(text);
        SettingsType settingsType = SettingsType.getByName(text);

        if ((cameraType != null && cameraType.equals(SelectCamera.CANCEL)) ||
                (settingsType != null && settingsType.equals(SettingsType.CANCEL))) {
            telegramService.sendMessage(chatId, botService.getString(R.string.operation_cancel));
            // TODO: 09.04.2017 mainK
//            telegramService.sendMessage(chatId, botService.getString(R.string.operation_cancel), mainKeyBoard);
            selectedSetting = null;
            selectedCamera = null;
            return false;
        } else if (cameraType == null && settingsType == null && selectedSetting != null) {
            return processSelectedSetting(chatId, text);
        } else if (settingsType != null) {
            boolean isProc = processSettings(chatId, settingsType);
            if (!isProc) {
                selectedSetting = null;
                selectedCamera = null;
            }
            return isProc;
        } else {
            // Если у нас только одна камера - выбираем её
            if (cameraType == null && Camera.getNumberOfCameras() == 1) {
                cameraType = SelectCamera.BACK;
            }

            if (cameraType == null) {
                selectedSetting = null;
                StringBuilder settingsStr = new StringBuilder();
                settingsStr.append(botService.getString(R.string.settings_camera));
                int[] availCameras = FabricUtils.getAvailableCameras();
                for (int i = 0; i < availCameras.length; i++) {
                    SelectCamera camera = SelectCamera.getByNum(i);
                    if (camera != null) {
                        settingsStr.append("\n\n").append(camera.getName()).append(":");

                        Prefs.CameraPrefs cameraPrefs = prefs.getCameraPrefs(camera.getNumber());
                        settingsStr.append(String.format(botService.getString(R.string.resolution), cameraPrefs.width, cameraPrefs.height));
                        settingsStr.append(botService.getString(R.string.flash_mode)).append(cameraPrefs.flashMode);
                        settingsStr.append(botService.getString(R.string.white_balance)).append(cameraPrefs.wb).append("\n");
                        settingsStr.append("Rotation angle: ").append(cameraPrefs.angle);
                    }
                }
                settingsStr.append("\n");
                settingsStr.append(botService.getString(R.string.camera_settings_choose));
                telegramService.sendMessage(chatId, settingsStr.toString(),
                        KeyboardUtils.getKeyboard(SelectCamera.values()));
                return true;
            } else {
                selectedCamera = cameraType;
                selectedSetting = null;
                telegramService.sendMessage(chatId, botService.getString(R.string.camera_settings_what_command),
                        KeyboardUtils.getKeyboard(SettingsType.values()));
                return true;
            }
        }
    }
 
Example 7
Source File: BotHandler.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
private boolean isStartMessage(Message message) {
    return message != null && message.text() != null && message.text().startsWith("/start");
}