本文整理汇总了Java中org.telegram.telegrambots.api.objects.Message.hasText方法的典型用法代码示例。如果您正苦于以下问题:Java Message.hasText方法的具体用法?Java Message.hasText怎么用?Java Message.hasText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.objects.Message
的用法示例。
在下文中一共展示了Message.hasText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
/**
* Executes a command action if the command is registered.
*
* @note If the command is not registered and there is a default consumer,
* that action will be performed
*
* @param absSender absSender
* @param message input message
* @return True if a command or default action is executed, false otherwise
*/
public final boolean executeCommand(AbsSender absSender, Message message) {
if (message.hasText()) {
String text = message.getText();
if (text.startsWith(BotCommand.COMMAND_INIT_CHARACTER)) {
String commandMessage = text.substring(1);
String[] commandSplit = commandMessage.split(BotCommand.COMMAND_PARAMETER_SEPARATOR);
String command = removeUsernameFromCommandIfNeeded(commandSplit[0]);
if (commandRegistryMap.containsKey(command)) {
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
commandRegistryMap.get(command).execute(absSender, message.getFrom(), message.getChat(), parameters);
return true;
} else if (defaultConsumer != null) {
defaultConsumer.accept(absSender, message);
return true;
}
}
}
return false;
}
示例2: executeCommand
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
/**
* Executes a command action if the command is registered.
*
* @note If the command is not registered and there is a default consumer,
* that action will be performed
*
* @param absSender absSender
* @param message input message
* @return True if a command or default action is executed, false otherwise
*/
public final boolean executeCommand(AbsSender absSender, Message message) {
if (message.hasText()) {
String text = message.getText();
if (text.startsWith(BotCommand.COMMAND_INIT_CHARACTER)) {
String commandMessage = text.substring(1);
String[] commandSplit = commandMessage.split(BotCommand.COMMAND_PARAMETER_SEPARATOR_REGEXP);
String command = removeUsernameFromCommandIfNeeded(commandSplit[0]);
if (commandRegistryMap.containsKey(command)) {
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
commandRegistryMap.get(command).processMessage(absSender, message, parameters);
return true;
} else if (defaultConsumer != null) {
defaultConsumer.accept(absSender, message);
return true;
}
}
}
return false;
}
示例3: processNonCommandUpdate
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void processNonCommandUpdate(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (!DatabaseManager.getInstance().getUserStateForCommandsBot(message.getFrom().getId())) {
return;
}
if (message.hasText()) {
SendMessage echoMessage = new SendMessage();
echoMessage.setChatId(message.getChatId());
echoMessage.setText("Hey heres your message:\n" + message.getText());
try {
sendMessage(echoMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
}
示例4: onAlertNewOptionSelected
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage onAlertNewOptionSelected(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().equals(getCancelCommand(language))) {
SendMessage sendMessage = new SendMessage();
sendMessage.enableMarkdown(true);
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
sendMessageRequest = sendMessage;
} else {
sendMessageRequest = onNewAlertCityReceived(message, language);
}
}
return sendMessageRequest;
}
示例5: onAlertOptionSelected
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage onAlertOptionSelected(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().equals(getNewCommand(language))) {
sendMessageRequest = onNewAlertCommand(message, language);
} else if (message.getText().equals(getDeleteCommand(language))) {
sendMessageRequest = onDeleteAlertCommand(message, language);
} else if (message.getText().equals(getListCommand(language))) {
sendMessageRequest = onListAlertCommand(message, language);
} else if (message.getText().equals(getBackCommand(language))) {
sendMessageRequest = onBackAlertCommand(message, language);
} else {
sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
getAlertsKeyboard(language), language);
}
}
return sendMessageRequest;
}
示例6: messageOnSetting
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage messageOnSetting(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().startsWith(getLanguagesCommand(language))) {
sendMessageRequest = onLanguageCommand(message, language);
} else if (message.getText().startsWith(getUnitsCommand(language))) {
sendMessageRequest = onUnitsCommand(message, language);
} else if (message.getText().startsWith(getAlertsCommand(language))) {
sendMessageRequest = onAlertsCommand(message, language);
} else if (message.getText().startsWith(getBackCommand(language))) {
sendMessageRequest = sendMessageDefault(message, language);
} else {
sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
getSettingsKeyboard(language), language);
}
}
return sendMessageRequest;
}
示例7: messageOnUnits
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage messageOnUnits(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().trim().equals(getCancelCommand(language))) {
sendMessageRequest = onBackUnitsCommand(message, language);
} else if (message.getText().trim().equals(LocalisationService.getString("metricSystem", language))) {
sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(),
message.getMessageId(), WeatherService.METRICSYSTEM, language);
} else if (message.getText().trim().equals(LocalisationService.getString("imperialSystem", language))) {
sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(),
message.getMessageId(), WeatherService.IMPERIALSYSTEM, language);
} else {
sendMessageRequest = onUnitsError(message.getChatId(), message.getMessageId(), language);
}
}
return sendMessageRequest;
}
示例8: onForecastWeather
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage onForecastWeather(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().startsWith(getNewCommand(language))) {
sendMessageRequest = onNewForecastWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language);
} else if (message.getText().startsWith(getLocationCommand(language))) {
sendMessageRequest = onLocationForecastWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language);
} else if (message.getText().startsWith(getCancelCommand(language))) {
sendMessageRequest = onCancelCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(),
getMainMenuKeyboard(language), language);
} else {
sendMessageRequest = onForecastWeatherCityReceived(message.getChatId(), message.getFrom().getId(), message.getMessageId(),
message.getText(), language);
}
}
return sendMessageRequest;
}
示例9: onCurrentWeather
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage onCurrentWeather(Message message, String language) {
SendMessage sendMessageRequest = null;
if (message.hasText()) {
if (message.getText().startsWith(getNewCommand(language))) {
sendMessageRequest = onNewCurrentWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language);
} else if (message.getText().startsWith(getLocationCommand(language))) {
sendMessageRequest = onLocationCurrentWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language);
} else if (message.getText().startsWith(getCancelCommand(language))) {
sendMessageRequest = onCancelCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(),
getMainMenuKeyboard(language), language);
} else {
sendMessageRequest = onCurrentWeatherCityReceived(message.getChatId(), message.getFrom().getId(), message.getMessageId(),
message.getText(), language);
}
}
return sendMessageRequest;
}
示例10: messageOnMainMenu
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
private static SendMessage messageOnMainMenu(Message message, String language) {
SendMessage sendMessageRequest;
if (message.hasText()) {
if (message.getText().equals(getCurrentCommand(language))) {
sendMessageRequest = onCurrentChoosen(message, language);
} else if (message.getText().equals(getForecastCommand(language))) {
sendMessageRequest = onForecastChoosen(message, language);
} else if (message.getText().equals(getSettingsCommand(language))) {
sendMessageRequest = onSettingsChoosen(message, language);
} else if (message.getText().equals(getRateCommand(language))) {
sendMessageRequest = sendRateMessage(message.getChatId(), message.getMessageId(), null, language);
} else {
sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
getMainMenuKeyboard(language), language);
}
} else {
sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
getMainMenuKeyboard(language), language);
}
return sendMessageRequest;
}
示例11: processNonCommandUpdate
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void processNonCommandUpdate(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.hasText()) {
SendMessage echoMessage = new SendMessage();
echoMessage.setChatId(message.getChatId());
echoMessage.setText("Hey heres your message:\n" + message.getText());
try {
sendMessage(echoMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
}
示例12: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
logger.info("Received update: " + update.toString());
logger.info("Has message: " + update.hasMessage());
if (!update.hasMessage()) {
return;
}
Message message = update.getMessage();
String username = Optional.ofNullable(message.getFrom().getUserName())
.orElse(
MessageFormat.format(
"{0} {1}",
message.getFrom().getFirstName(),
message.getFrom().getLastName())
);
FirehoseMessage firehoseMessage = new FirehoseMessage("telegram",
"post",
username,
message.getChat().getId().toString(),
message.getChat().getTitle(),
message.getText());
logger.info("Got event from service: " + firehoseMessage.toLogString());
logger.info("Timestamp: " + message.getDate() + " vs local " + startTimestamp);
if (message.getDate() < startTimestamp) {
return;
}
if (!message.hasText()) {
return;
}
callback.execute(firehoseMessage);
}
示例13: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
public void onUpdateReceived(final Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.hasText() || message.hasLocation()) {
executor.execute(() -> {
try {
handleIncomingMessage(message);
} catch (Throwable t) {
// чтобы не умер поток из пула ловим вообще всё
LOGGER.error(t);
}
});
}
}
}
示例14: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.hasText() || message.hasLocation()) {
handleIncomingMessage(message);
}
}
}
示例15: onUpdateReceived
import org.telegram.telegrambots.api.objects.Message; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
try {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.hasText() || message.hasLocation()) {
handleIncomingMessage(message);
}
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
}
}