EventDistributorService получил событие для обработки InlineQuery. Поправил SubscribeConvert
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-18 14:01:24 +03:00
parent 0e575cc09f
commit 9c2f04c483
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 31 additions and 7 deletions

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.telegram.domain.event.Subscribe;
import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
import org.telegram.telegrambots.meta.api.objects.User;
import java.time.LocalDateTime;
@ -15,13 +15,14 @@ public final class SubscribeConvert {
}
public static Subscribe apply(ChatMemberUpdated updated) {
final Chat chat = updated.getChat();
final User user = updated.getNewChatMember().getUser();
final Subscribe subscribe = new Subscribe();
subscribe.setTelegramId(chat.getId().toString());
subscribe.setLastName(chat.getLastName());
subscribe.setFirstName(chat.getFirstName());
subscribe.setTelegramId(user.getId().toString());
subscribe.setLastName(user.getLastName());
subscribe.setFirstName(user.getFirstName());
subscribe.setSubscriptionDate(LocalDateTime.now());
subscribe.setLogin(user.getUserName());
return subscribe;
}

View File

@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery;
import org.telegram.telegrambots.meta.api.objects.payments.PreCheckoutQuery;
import java.util.List;
@ -49,6 +50,19 @@ public class EventDistributorService implements EventDistributor {
final Message message = update.getMessage();
final CallbackQuery callbackQuery = update.getCallbackQuery();
final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery();
final InlineQuery inlineQuery = update.getInlineQuery();
// запросы к боту из чатов: https://core.telegram.org/bots/inline
if (checkNotNull(inlineQuery)) {
final Optional<List<EventHandler>> optHandlers = getHandler(inlineQuery.getClass().getSimpleName());
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
.onItem().transformToUni(
eventHandler -> eventHandler.handle(inlineQuery)
).concatenate().collect().asList().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
if (checkNotNull(preCheckoutQuery)) {
final Optional<List<EventHandler>> optHandlers = getHandler(preCheckoutQuery.getClass().getName());

View File

@ -12,13 +12,13 @@ import dev.struchkov.godfather.telegram.main.consumer.SubscribeConvert;
import dev.struchkov.godfather.telegram.main.consumer.UnsubscribeConvert;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
import dev.struchkov.haiti.utils.Checker;
import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery;
import org.telegram.telegrambots.meta.api.objects.payments.PreCheckoutQuery;
import java.util.List;
@ -26,6 +26,8 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
* TODO: Добавить описание класса.
*
@ -45,8 +47,14 @@ public class EventDistributorService implements EventDistributor {
final Message message = update.getMessage();
final CallbackQuery callbackQuery = update.getCallbackQuery();
final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery();
final InlineQuery inlineQuery = update.getInlineQuery();
if (Checker.checkNotNull(preCheckoutQuery)) {
if (checkNotNull(inlineQuery)) {
getHandler(inlineQuery.getClass().getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(inlineQuery)));
return;
}
if (checkNotNull(preCheckoutQuery)) {
getHandler(preCheckoutQuery.getClass().getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(preCheckoutQuery)));
return;
}

View File

@ -12,6 +12,7 @@ public class Subscribe {
private String telegramId;
private String firstName;
private String lastName;
private String login;
private LocalDateTime subscriptionDate;
}