From 9c2f04c483e8fb774093a11f2c22013e20a0fdac Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 18 Mar 2023 14:01:24 +0300 Subject: [PATCH] =?UTF-8?q?EventDistributorService=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D0=B8=D0=BB=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20InlineQuery.=20=D0=9F=D0=BE=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20SubscribeConvert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telegram/main/consumer/SubscribeConvert.java | 11 ++++++----- .../quarkus/consumer/EventDistributorService.java | 14 ++++++++++++++ .../simple/consumer/EventDistributorService.java | 12 ++++++++++-- .../godfather/telegram/domain/event/Subscribe.java | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java b/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java index a8b0546..45630c0 100644 --- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java +++ b/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java @@ -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; } diff --git a/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java index 34096a6..059fe44 100644 --- a/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java +++ b/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java @@ -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> 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> optHandlers = getHandler(preCheckoutQuery.getClass().getName()); diff --git a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java index 701de9a..8f5619f 100644 --- a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java +++ b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java @@ -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; } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java index c11a3e1..d6dc978 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java @@ -12,6 +12,7 @@ public class Subscribe { private String telegramId; private String firstName; private String lastName; + private String login; private LocalDateTime subscriptionDate; }