Доработка
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-24 01:26:11 +03:00
parent bef5f42eb4
commit b657d588bb
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
5 changed files with 31 additions and 23 deletions

View File

@ -15,7 +15,7 @@ public final class SubscribeConvert {
}
public static Subscribe apply(ChatMemberUpdated updated) {
final User user = updated.getNewChatMember().getUser();
final User user = updated.getFrom();
final Subscribe subscribe = new Subscribe();
subscribe.setTelegramId(user.getId().toString());

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.telegram.domain.event.Unsubscribe;
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,13 @@ public final class UnsubscribeConvert {
}
public static Unsubscribe apply(ChatMemberUpdated updated) {
final Chat chat = updated.getChat();
final User user = updated.getFrom();
final Unsubscribe unsubscribe = new Unsubscribe();
unsubscribe.setTelegramId(chat.getId().toString());
unsubscribe.setLastName(chat.getLastName());
unsubscribe.setFirstName(chat.getFirstName());
unsubscribe.setSubscriptionDate(LocalDateTime.now());
unsubscribe.setTelegramId(user.getId().toString());
unsubscribe.setLastName(user.getLastName());
unsubscribe.setFirstName(user.getFirstName());
unsubscribe.setUnsubscriptionDate(LocalDateTime.now());
return unsubscribe;
}

View File

@ -53,7 +53,7 @@ public class EventDistributorService implements EventDistributor {
final InlineQuery inlineQuery = update.getInlineQuery();
// запросы к боту из чатов: https://core.telegram.org/bots/inline
if (checkNotNull(inlineQuery)) {
if (update.hasInlineQuery()) {
final Optional<List<EventHandler>> optHandlers = getHandler(inlineQuery.getClass().getSimpleName());
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
@ -64,7 +64,7 @@ public class EventDistributorService implements EventDistributor {
return Uni.createFrom().voidItem();
}
if (checkNotNull(preCheckoutQuery)) {
if (update.hasPreCheckoutQuery()) {
final Optional<List<EventHandler>> optHandlers = getHandler(preCheckoutQuery.getClass().getName());
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
@ -75,7 +75,7 @@ public class EventDistributorService implements EventDistributor {
return Uni.createFrom().voidItem();
}
if (checkNotNull(message) && (!isEvent(message))) {
if (update.hasMessage()) {
final Optional<List<EventHandler>> optHandlers = getHandler(Mail.class.getName());
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
@ -86,7 +86,7 @@ public class EventDistributorService implements EventDistributor {
return Uni.createFrom().voidItem();
}
if (checkNotNull(callbackQuery)) {
if (update.hasCallbackQuery()) {
final Optional<List<EventHandler>> optHandlers = getHandler(Mail.class.getName());
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
@ -97,7 +97,7 @@ public class EventDistributorService implements EventDistributor {
return Uni.createFrom().voidItem();
}
if (checkNotNull(update.getMyChatMember())) {
if (update.hasMyChatMember()) {
final ChatMemberUpdated chatMember = update.getMyChatMember();
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
@ -49,25 +50,25 @@ public class EventDistributorService implements EventDistributor {
final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery();
final InlineQuery inlineQuery = update.getInlineQuery();
if (checkNotNull(inlineQuery)) {
if (update.hasInlineQuery()) {
getHandler(inlineQuery.getClass().getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(inlineQuery)));
return;
}
if (checkNotNull(preCheckoutQuery)) {
if (update.hasPreCheckoutQuery()) {
getHandler(preCheckoutQuery.getClass().getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(preCheckoutQuery)));
return;
}
if (message != null && (!isEvent(message))) {
if (update.hasMessage()) {
processionMessage(message);
return;
}
if (callbackQuery != null) {
if (update.hasCallbackQuery()) {
processionCallback(callbackQuery);
return;
}
if (update.getMyChatMember() != null) {
if (update.hasMyChatMember()) {
final ChatMemberUpdated chatMember = update.getMyChatMember();
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {
getHandler(Unsubscribe.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(UnsubscribeConvert.apply(chatMember))));
@ -81,12 +82,19 @@ public class EventDistributorService implements EventDistributor {
}
private void processionCallback(CallbackQuery callbackQuery) {
final Long fromId = callbackQuery.getMessage().getChat().getId();
if (fromId < 0) {
final Message message = callbackQuery.getMessage();
if (checkNotBlank(callbackQuery.getInlineMessageId())) {
} else {
final Mail mail = CallbackQueryConvert.apply(callbackQuery);
getHandler(Mail.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail)));
return;
}
if (checkNotNull(message)) {
final Long fromId = message.getChat().getId();
if (fromId < 0) {
} else {
final Mail mail = CallbackQueryConvert.apply(callbackQuery);
getHandler(Mail.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail)));
}
}
}

View File

@ -19,6 +19,6 @@ public class Unsubscribe {
private String telegramId;
private String firstName;
private String lastName;
private LocalDateTime subscriptionDate;
private LocalDateTime unsubscriptionDate;
}