This commit is contained in:
parent
bef5f42eb4
commit
b657d588bb
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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())) {
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,6 @@ public class Unsubscribe {
|
||||
private String telegramId;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private LocalDateTime subscriptionDate;
|
||||
private LocalDateTime unsubscriptionDate;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user