code Copy code
private static final Logger log = LoggerFactory.getLogger(ArtiTapBot.class);
private final PlayerService playerService;
private final PlayerRepository playerRepository;
@Value("${telegram.bot.creator-id}")
private Long telegramBotCreatorId;
@Value("${telegram.web-app-url}")
private String telegramWebAppUrl;
@Value("${telegram.channel-url}")
private String telegramChannelUrl;
ResourceBundleMessageSource messageSource;
PaymentService paymentService;
SupportApplicationService supportApplicationService;
SupportApplicationRepository supportApplicationRepository;
PartnershipApplicationService partnershipApplicationService;
PartnershipApplicationRepository partnershipApplicationRepository;
MailingMessageRepository mailingMessageRepository;
RabbitTemplate rabbitTemplate;
private Map<Long, Long> chatIdSupportApplicationIdMap = new HashMap<>();
private Map<Long, Long> chatIdPartnershipApplicationIdMap = new HashMap<>();
private Map<Long, String> chatIdMailingLangMap = new HashMap<>();
private Map<Long, MailingType> chatIdMailingTypeMap = new HashMap<>();
private Map<Long, Long> chatIdMailingMessageIdMap = new HashMap<>();
private static final CustomToggle toggle = new CustomToggle()
.turnOff("commands")
.turnOff("stats");
public ArtiTapBot(
TelegramClient telegramClient,
@Value("${telegram.bot.username}") String botUsername,
ResourceBundleMessageSource messageSource,
PaymentService paymentService,
SupportApplicationService supportApplicationService,
SupportApplicationRepository supportApplicationRepository,
PartnershipApplicationService partnershipApplicationService,
PartnershipApplicationRepository partnershipApplicationRepository,
MailingMessageRepository mailingMessageRepository,
PlayerService playerService,
PlayerRepository playerRepository,
RabbitTemplate rabbitTemplate
) {
super(telegramClient, botUsername, MapDBContext.onlineInstance("tg_context"), toggle);
this.messageSource = messageSource;
this.paymentService = paymentService;
this.supportApplicationService = supportApplicationService;
this.supportApplicationRepository = supportApplicationRepository;
this.partnershipApplicationService = partnershipApplicationService;
this.partnershipApplicationRepository = partnershipApplicationRepository;
this.mailingMessageRepository = mailingMessageRepository;
this.playerService = playerService;
this.playerRepository = playerRepository;
this.rabbitTemplate = rabbitTemplate;
}
@[Redacted Person]
public long creatorId() {
return telegramBotCreatorId;
}
public Ability start() {
return Ability
.builder()
.name("start")
.locality(ALL)
.privacy(PUBLIC)
.action(ctx -> {
Locale locale = getLocale(ctx.user().getLanguageCode());
String welcomeText = messageSource.getMessage("welcome", null, locale);
String buttonPlayText = messageSource.getMessage("button_play", null, locale);
String buttonHowToPlay = messageSource.getMessage("button_how_to_play", null, locale);
String buttonSubscribeToChannelText = messageSource.getMessage("button_subscribe_to_channel", null, locale);
SendMessage sendMessage = SendMessage.builder()
.chatId(ctx.chatId())
.text(welcomeText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.webApp(new WebAppInfo(telegramWebAppUrl))
.text(buttonPlayText)
.build()
)
)
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonSubscribeToChannelText)
.url(telegramChannelUrl)
.build()
)
)
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonHowToPlay)
.callbackData("help")
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
})
.build();
}
public Ability help() {
return Ability
.builder()
.name("help")
.locality(ALL)
.privacy(PUBLIC)
.action(ctx -> helpAction(ctx.user(), ctx.chatId()))
.build();
}
private void helpAction(User user, Long chatId) {
Locale locale = getLocale(user.getLanguageCode());
String helpText = messageSource.getMessage("help", null, locale);
String buttonPlayText = messageSource.getMessage("button_play", null, locale);
SendMessage sendMessage = SendMessage.builder()
.chatId(chatId)
.text(helpText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.webApp(new WebAppInfo(telegramWebAppUrl))
.text(buttonPlayText)
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
}
public Reply sendHelp() {
BiConsumer<BaseAbilityBot, Update> action = (consumer, upd) -> {
CallbackQuery callbackQuery = upd.getCallbackQuery();
helpAction(callbackQuery.getFrom(), callbackQuery.getMessage().getChatId());
};
return Reply.of(action, hasCallbackData("help"));
}
@PostConstruct
@[Redacted Person]
public void onRegister() {
super.onRegister();
}
private Predicate<Update> hasCallbackData(String data) {
return upd -> {
CallbackQuery callbackQuery = upd.getCallbackQuery();
return upd.hasCallbackQuery() && callbackQuery.getData().equalsIgnoreCase(data);
};
}
private Predicate<Update> hasCallbackData(Pattern pattern) {
return upd -> {
CallbackQuery callbackQuery = upd.getCallbackQuery();
if (!upd.hasCallbackQuery()) {
return false;
}
Matcher matcher = pattern.matcher(callbackQuery.getData());
return matcher.find();
};
}
public Reply replyToSuccessfulPayment() {
return Reply.of((bot, update) -> {
handleSuccessfulPayment(update);
}, update -> update.hasMessage() && update.getMessage().hasSuccessfulPayment());
}
public Reply replyToPreCheckoutQuery() {
return Reply.of((bot, update) -> {
AnswerPreCheckoutQuery answerPreCheckoutQuery = AnswerPreCheckoutQuery.builder()
.preCheckoutQueryId(update.getPreCheckoutQuery().getId())
.ok(true)
.build();
silent.execute(answerPreCheckoutQuery);
}, Update::hasPreCheckoutQuery);
}
private void handleSuccessfulPayment(Update update) {
SuccessfulPayment payment = update.getMessage().getSuccessfulPayment();
try {
paymentService.handleSuccessfulPayment(payment);
} catch (Exception e) {
log.error("Handle successful payment: ", e);
}
}
public ReplyFlow supportFlow() {
Reply sent = Reply.of(
(bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = chatIdSupportApplicationIdMap.get(chatId);
SupportApplication supportApplication = supportApplicationService.getById(supportApplicationId);
Locale locale = getLocale(supportApplication.getPlayer().getLanguageCode());
String supportServiceText = messageSource.getMessage("support_service", null, locale);
String applicationText = messageSource.getMessage("application", null, locale);
String replySentText = messageSource.getMessage("reply_sent", null, locale);
String buttonReply = messageSource.getMessage("button_reply", null, locale);
String messageText = supportServiceText
+ "\n\n"
+ update.getMessage().getText()
+ "\n\n"
+ applicationText + " №" + supportApplicationId;
SendMessage sendMessage = SendMessage.builder()
.chatId(supportApplication.getPlayer().getTelegramId())
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonReply)
.callbackData("RSA:" + supportApplication.getId())
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
silent.send(replySentText, getChatId(update));
},
hasMessageNonEmpty()
);
return ReplyFlow.builder(db)
.action((bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = Long.parseLong(update.getCallbackQuery().getData().substring(3));
SupportApplication supportApplication = supportApplicationService.getById(supportApplicationId);
Locale locale = getLocale(supportApplication.getPlayer().getLanguageCode());
String writeYourReplyText = messageSource.getMessage("write_your_reply", null, locale);
String alreadyBeenAnsweredText = messageSource.getMessage("already_been_answered", null, locale);
Player player = playerService.getPlayerByTelegramId(chatId);
if (supportApplication.getReplyingPlayer() != null && !Objects.equals(supportApplication.getReplyingPlayer().getId(), player.getId())) {
silent.send(alreadyBeenAnsweredText, getChatId(update));
return;
}
supportApplication.setReplyingPlayer(player);
supportApplicationService.save(supportApplication);
chatIdSupportApplicationIdMap.put(chatId, supportApplicationId);
silent.send(writeYourReplyText, getChatId(update));
})
.onlyIf(hasCallbackData(Pattern.compile("^SA:\\d+")))
.next(sent)
.build();
}
public ReplyFlow replyToSupportFlow() {
Reply sent = Reply.of(
(bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = chatIdSupportApplicationIdMap.get(chatId);
SupportApplication supportApplication = supportApplicationService.getById(supportApplicationId);
Locale locale = getLocale(update.getMessage().getFrom().getLanguageCode());
String replySentText = messageSource.getMessage("reply_sent", null, locale);
String buttonReply = messageSource.getMessage("button_reply", null, locale);
String supportApplicationText = messageSource.getMessage("support_application", null, locale);
String messageText = supportApplicationText + " №"
+ supportApplication.getId()
+ "\n\n"
+ update.getMessage().getText()
+ "\n\n"
+ supportApplication.getPlayer().getFirstName();
SendMessage sendMessage = SendMessage.builder()
.chatId(supportApplication.getReplyingPlayer().getTelegramId())
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonReply)
.callbackData("SA:" + supportApplication.getId())
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
silent.send(replySentText, chatId);
},
hasMessageNonEmpty()
);
return ReplyFlow.builder(db)
.action((bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = Long.parseLong(update.getCallbackQuery().getData().substring(4));
chatIdSupportApplicationIdMap.put(chatId, supportApplicationId);
Locale locale = getLocale(update.getCallbackQuery().getFrom().getLanguageCode());
String writeYourReplyText = messageSource.getMessage("write_your_reply", null, locale);
silent.send(writeYourReplyText, getChatId(update));
})
.onlyIf(hasCallbackData(Pattern.compile("^RSA:\\d+")))
.next(sent)
.build();
}
public ReplyFlow partnershipApplicationFlow() {
Reply sent = Reply.of(
(bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = chatIdPartnershipApplicationIdMap.get(chatId);
PartnershipApplication partnershipApplication = partnershipApplicationService.getById(supportApplicationId);
Locale locale = getLocale(partnershipApplication.getPlayer().getLanguageCode());
String partnershipApplicationText = messageSource.getMessage("partnership_application", null, locale);
String applicationText = messageSource.getMessage("application", null, locale);
String replySentText = messageSource.getMessage("reply_sent", null, locale);
String buttonReply = messageSource.getMessage("button_reply", null, locale);
String messageText = partnershipApplicationText
+ "\n\n"
+ update.getMessage().getText()
+ "\n\n"
+ applicationText + " №" + supportApplicationId;
SendMessage sendMessage = SendMessage.builder()
.chatId(partnershipApplication.getPlayer().getTelegramId())
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonReply)
.callbackData("RPA:" + partnershipApplication.getId())
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
silent.send(replySentText, getChatId(update));
},
hasMessageNonEmpty()
);
return ReplyFlow.builder(db)
.action((bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = Long.parseLong(update.getCallbackQuery().getData().substring(3));
PartnershipApplication partnershipApplication = partnershipApplicationService.getById(supportApplicationId);
Locale locale = getLocale(partnershipApplication.getPlayer().getLanguageCode());
String writeYourReplyText = messageSource.getMessage("write_your_reply", null, locale);
String alreadyBeenAnsweredText = messageSource.getMessage("already_been_answered", null, locale);
Player player = playerService.getPlayerByTelegramId(chatId);
if (partnershipApplication.getReplyingPlayer() != null && !Objects.equals(partnershipApplication.getReplyingPlayer().getId(), player.getId())) {
silent.send(alreadyBeenAnsweredText, getChatId(update));
return;
}
partnershipApplication.setReplyingPlayer(player);
partnershipApplicationService.save(partnershipApplication);
chatIdPartnershipApplicationIdMap.put(chatId, supportApplicationId);
silent.send(writeYourReplyText, getChatId(update));
})
.onlyIf(hasCallbackData(Pattern.compile("^PA:\\d+")))
.next(sent)
.build();
}
public ReplyFlow replyToPartnershipApplicationFlow() {
Reply sent = Reply.of(
(bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = chatIdPartnershipApplicationIdMap.get(chatId);
PartnershipApplication partnershipApplication = partnershipApplicationService.getById(supportApplicationId);
Locale locale = getLocale(update.getMessage().getFrom().getLanguageCode());
String replySentText = messageSource.getMessage("reply_sent", null, locale);
String buttonReply = messageSource.getMessage("button_reply", null, locale);
String partnershipApplicationText = messageSource.getMessage("partnership_application", null, locale);
String messageText = partnershipApplicationText + " №"
+ partnershipApplication.getId()
+ "\n\n"
+ update.getMessage().getText()
+ "\n\n"
+ partnershipApplication.getPlayer().getFirstName();
SendMessage sendMessage = SendMessage.builder()
.chatId(partnershipApplication.getReplyingPlayer().getTelegramId())
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonReply)
.callbackData("PA:" + partnershipApplication.getId())
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
silent.send(replySentText, chatId);
},
hasMessageNonEmpty()
);
return ReplyFlow.builder(db)
.action((bot, update) -> {
long chatId = getChatId(update);
long supportApplicationId = Long.parseLong(update.getCallbackQuery().getData().substring(4));
chatIdPartnershipApplicationIdMap.put(chatId, supportApplicationId);
Locale locale = getLocale(update.getCallbackQuery().getFrom().getLanguageCode());
String writeYourReplyText = messageSource.getMessage("write_your_reply", null, locale);
silent.send(writeYourReplyText, getChatId(update));
})
.onlyIf(hasCallbackData(Pattern.compile("^RPA:\\d+")))
.next(sent)
.build();
}
public ReplyFlow paySupportFlow() {
Reply send = Reply.of(
(bot, update) -> {
long chatId = getChatId(update);
Player player = playerService.getPlayerByTelegramId(chatId);
ZonedDateTime now = ZonedDateTime.now();
SupportApplication supportApplication = SupportApplication.builder()
.player(player)
.text(update.getMessage().getText())
.createdAt(now)
.build();
try {
supportApplicationRepository.save(supportApplication);
} catch (Exception e) {
return;
}
List<Player> supporters = playerService.getPlayersByRole(Role.SUPPORT);
for (Player supporter : supporters) {
Locale locale = getLocale(supporter.getLanguageCode());
String supportApplicationText = messageSource.getMessage("support_application", null, locale);
String buttonReply = messageSource.getMessage("button_reply", null, locale);
String messageText = supportApplicationText + " №"
+ supportApplication.getId()
+ "\n\n"
+ supportApplication.getText()
+ "\n\n"
+ player.getFirstName();
SendMessage sendMessage = SendMessage.builder()
.chatId(supporter.getTelegramId())
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(
new InlineKeyboardRow(InlineKeyboardButton
.builder()
.text(buttonReply)
.callbackData("SA:" + supportApplication.getId())
.build()
)
)
.build())
.build();
silent.execute(sendMessage);
}
},
hasMessageNonEmpty(),
hasMessageWithout("/paysupport")
);
return ReplyFlow
.builder(db)
.onlyIf(hasMessageWith("/paysupport"))
.action((bot, update) -> {
long chatId = getChatId(update);
Locale locale = getLocale(update.getMessage().getFrom().getLanguageCode());
String writeYourReplyText = messageSource.getMessage("describe_your_problem", null, locale);
silent.send(writeYourReplyText, chatId);
})
.next(send)
.build();
}
public ReplyFlow mailingFlow() {
Reply startMailing = Reply.of((bot, update) -> {
long chatId = getChatId(update);
Locale locale = getLocale(update.getCallbackQuery().getFrom().getLanguageCode());
ZonedDateTime now = ZonedDateTime.now();
long mailingMessageId = Long.parseLong(update.getCallbackQuery().getData().substring(14));
MailingMessage mailingMessage = mailingMessageRepository.findById(mailingMessageId).orElseThrow(RuntimeException::new);
List<Long> playerTelegramIds = List.of();
switch (mailingMessage.getType()) {
case ALL: {
if (Objects.equals(mailingMessage.getLanguageCode(), "ru")) {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndLanguageCode(now, "ru");
} else {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndNotLanguageCode(now, "ru");
}
break;
}
case MORE_THAN_TWO_DAYS_OFFLINE: {
if (Objects.equals(mailingMessage.getLanguageCode(), "ru")) {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndLanguageCode(now.minusDays(2), "ru");
} else {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndNotLanguageCode(now.minusDays(2), "ru");
}
break;
}
case MORE_THAN_SEVEN_DAYS_OFFLINE: {
if (Objects.equals(mailingMessage.getLanguageCode(), "ru")) {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndLanguageCode(now.minusDays(7), "ru");
} else {
playerTelegramIds = playerRepository.findTelegramIdsByLastSyncLessThanAndNotLanguageCode(now.minusDays(7), "ru");
}
break;
}
}
for (Long playerTelegramId : playerTelegramIds) {
rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING_KEY, new MailingData(playerTelegramId, mailingMessageId));
}
log.info(update.getCallbackQuery().getData());
String mailingHasStartedText = messageSource.getMessage("mailing_has_started", new Object[]{playerTelegramIds.size()}, locale);
silent.send(mailingHasStartedText, chatId);
}, hasCallbackData(Pattern.compile("^MAILING_START:\\d+")));
ReplyFlow prepareMessage = ReplyFlow.builder(db)
.onlyIf(hasMessageNonEmpty())
.onlyIf(isNotCommandMessage())
.action((bot, update) -> {
long chatId = getChatId(update);
Locale locale = getLocale(update.getMessage().getFrom().getLanguageCode());
String messageText = "";
if (Objects.equals(chatIdMailingLangMap.get(chatId), "ru")) {
messageText += messageSource.getMessage("russian", null, locale);
} else {
messageText += messageSource.getMessage("english_and_others", null, locale);
}
messageText += "\n";
switch (chatIdMailingTypeMap.get(chatId)) {
case ALL -> messageText += messageSource.getMessage("for_all", null, locale);
case MORE_THAN_TWO_DAYS_OFFLINE ->
messageText += messageSource.getMessage("more_than_two_days_offline", null, locale);
case MORE_THAN_SEVEN_DAYS_OFFLINE ->
messageText += messageSource.getMessage("more_than_seven_days_offline", null, locale);
}
messageText += "\n------------------------------\n" + update.getMessage().getText();
MailingMessage mailingMessage = mailingMessageRepository.save(MailingMessage.builder()
.text(update.getMessage().getText())
.languageCode(chatIdMailingLangMap.get(chatId))
.type(chatIdMailingTypeMap.get(chatId))
.build());
chatIdMailingMessageIdMap.put(chatId, mailingMessage.getId());
String buttonStartMailing = messageSource.getMessage("button_start_mailing", null, locale);
SendMessage sendMessage = SendMessage.builder()
.chatId(chatId)
.text(messageText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(new InlineKeyboardRow(
InlineKeyboardButton
.builder()
.text(buttonStartMailing)
.callbackData("MAILING_START:" + mailingMessage.getId())
.build()
))
.build())
.build();
silent.execute(sendMessage);
})
.next(startMailing)
.build();
ReplyFlow selectType = ReplyFlow.builder(db)
.onlyIf(hasCallbackData(Pattern.compile("^" + MailingType.ALL + "|" + MailingType.MORE_THAN_TWO_DAYS_OFFLINE + "|" + MailingType.MORE_THAN_SEVEN_DAYS_OFFLINE)))
.action((bot, update) -> {
long chatId = getChatId(update);
chatIdMailingTypeMap.put(chatId, MailingType.valueOf(update.getCallbackQuery().getData()));
Locale locale = getLocale(update.getCallbackQuery().getFrom().getLanguageCode());
String writeAPostText = messageSource.getMessage("write_a_post", null, locale);
silent.send(writeAPostText, chatId);
})
.next(prepareMessage)
.build();
ReplyFlow selectLanguage = ReplyFlow.builder(db)
.onlyIf(hasCallbackData(Pattern.compile("^MSL:.+")))
.action((bot, update) -> {
long chatId = getChatId(update);
String langCode = update.getCallbackQuery().getData().substring(4);
chatIdMailingLangMap.put(chatId, langCode);
Locale locale = getLocale(update.getCallbackQuery().getFrom().getLanguageCode());
String selectMailingLangText = messageSource.getMessage("select_the_type_of_mailing", null, locale);
String forAllText = messageSource.getMessage("for_all", null, locale);
String moreThanTwoDaysOfflineText = messageSource.getMessage("more_than_two_days_offline", null, locale);
String moreThanSevenDaysOfflineText = messageSource.getMessage("more_than_seven_days_offline", null, locale);
SendMessage sendMessage = SendMessage.builder()
.chatId(chatId)
.text(selectMailingLangText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(new InlineKeyboardRow(
InlineKeyboardButton
.builder()
.text(forAllText)
.callbackData(String.valueOf(MailingType.ALL))
.build()
))
.keyboardRow(new InlineKeyboardRow(
InlineKeyboardButton
.builder()
.text(moreThanTwoDaysOfflineText)
.callbackData(String.valueOf(MailingType.MORE_THAN_TWO_DAYS_OFFLINE))
.build()
))
.keyboardRow(new InlineKeyboardRow(
InlineKeyboardButton
.builder()
.text(moreThanSevenDaysOfflineText)
.callbackData(String.valueOf(MailingType.MORE_THAN_SEVEN_DAYS_OFFLINE))
.build()
))
.build())
.build();
silent.execute(sendMessage);
})
.next(selectType)
.build();
return ReplyFlow
.builder(db)
.onlyIf(hasMessageWith("/mailing"))
.action((bot, update) -> {
long chatId = getChatId(update);
Player player = playerService.getPlayerByTelegramId(chatId);
if (!player.getRoles().contains(Role.ADMIN)) {
return;
}
Locale locale = getLocale(update.getMessage().getFrom().getLanguageCode());
String selectMailingLangText = messageSource.getMessage("select_mailing_lang", null, locale);
String selectRuText = messageSource.getMessage("russian", null, locale);
String selectEnAndOtherText = messageSource.getMessage("english_and_others", null, locale);
SendMessage sendMessage = SendMessage.builder()
.chatId(chatId)
.text(selectMailingLangText)
.replyMarkup(InlineKeyboardMarkup
.builder()
.keyboardRow(new InlineKeyboardRow(
InlineKeyboardButton
.builder()
.text(selectRuText)
.callbackData("MSL:ru")
.build(),
InlineKeyboardButton
.builder()
.text(selectEnAndOtherText)
.callbackData("MSL:en")
.build()
))
.build())
.build();
silent.execute(sendMessage);
})
.next(selectLanguage)
.build();
}
@NotNull
private Predicate<Update> hasMessageWith(String msg) {
return upd -> upd.hasMessage() && upd.getMessage().getText().equalsIgnoreCase(msg);
}
@NotNull
private Predicate<Update> hasMessageWithout(String msg) {
return upd -> upd.hasMessage() && !upd.getMessage().getText().equalsIgnoreCase(msg);
}
@NotNull
private Predicate<Update> hasMessageNonEmpty() {
return upd -> upd.hasMessage() && !upd.getMessage().getText().isEmpty();
}
@NotNull
private Predicate<Update> isNotCommandMessage() {
return upd -> {
if (!upd.hasMessage()) {
return false;
}
Matcher matcher = Pattern.compile("^/.+").matcher(upd.getMessage().getText());
return !matcher.find();
};
}