From f1065301d7667d3c557affaba61aa3a4ad80f1e4 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 17 Feb 2023 16:39:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 36 ++----------------- .../consumer/EventDistributorService.java | 12 +++---- .../simple/core/TelegramPollingBot.java | 4 ++- .../main/sender/util/KeyBoardConvert.java | 18 ++++++---- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index cb74627..0a7fb21 100644 --- a/.gitignore +++ b/.gitignore @@ -42,27 +42,7 @@ buildNumber.properties # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries +.idea/ # Gradle and Maven with auto-import # When using Gradle or Maven with auto-import, you should exclude module files, @@ -80,9 +60,6 @@ buildNumber.properties # CMake cmake-build-*/ -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - # File-based project format *.iws @@ -95,17 +72,8 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser +fabric.properties \ No newline at end of file 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 9589556..d83eb27 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 @@ -42,26 +42,22 @@ public class EventDistributorService implements EventDistributor { final CallbackQuery callbackQuery = update.getCallbackQuery(); if (message != null) { if (!isEvent(message)) { - getHandler(Mail.TYPE) - .ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(MessageMailConvert.apply(message)))); + getHandler(Mail.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(MessageMailConvert.apply(message)))); return; } } if (callbackQuery != null) { - getHandler(Mail.TYPE) - .ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(CallbackQueryConvert.apply(callbackQuery)))); + getHandler(Mail.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(CallbackQueryConvert.apply(callbackQuery)))); return; } if (update.getMyChatMember() != null) { final ChatMemberUpdated chatMember = update.getMyChatMember(); if ("kicked".equals(chatMember.getNewChatMember().getStatus())) { - getHandler(Unsubscribe.TYPE) - .ifPresent(providers -> providers.forEach(provider -> provider.handle(UnsubscribeConvert.apply(chatMember)))); + getHandler(Unsubscribe.TYPE).ifPresent(providers -> providers.forEach(provider -> provider.handle(UnsubscribeConvert.apply(chatMember)))); return; } if ("member".equals(chatMember.getNewChatMember().getStatus())) { - getHandler(Subscribe.TYPE) - .ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(SubscribeConvert.apply(chatMember)))); + getHandler(Subscribe.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(SubscribeConvert.apply(chatMember)))); return; } } diff --git a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingBot.java b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingBot.java index f776a8b..e34e359 100644 --- a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingBot.java +++ b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingBot.java @@ -9,6 +9,8 @@ import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.bots.AbsSender; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + /** * TODO: Добавить описание класса. * @@ -30,7 +32,7 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr @Override public void onUpdateReceived(Update update) { - if (update != null && eventDistributor != null) { + if (checkNotNull(update) && checkNotNull(eventDistributor)) { eventDistributor.processing(update); } } diff --git a/telegram-sender/telegram-sender-main/src/main/java/dev/struchkov/godfather/telegram/main/sender/util/KeyBoardConvert.java b/telegram-sender/telegram-sender-main/src/main/java/dev/struchkov/godfather/telegram/main/sender/util/KeyBoardConvert.java index e928365..762642d 100644 --- a/telegram-sender/telegram-sender-main/src/main/java/dev/struchkov/godfather/telegram/main/sender/util/KeyBoardConvert.java +++ b/telegram-sender/telegram-sender-main/src/main/java/dev/struchkov/godfather/telegram/main/sender/util/KeyBoardConvert.java @@ -12,7 +12,6 @@ import dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton; import dev.struchkov.godfather.telegram.domain.keyboard.button.WebAppButton; import dev.struchkov.haiti.context.exception.ConvertException; import dev.struchkov.haiti.utils.Exceptions; -import dev.struchkov.haiti.utils.Inspector; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup; @@ -24,6 +23,10 @@ import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo; import java.util.List; +import static dev.struchkov.haiti.context.exception.ConvertException.convertException; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; +import static dev.struchkov.haiti.utils.Inspector.isNull; + public final class KeyBoardConvert { private KeyBoardConvert() { @@ -31,14 +34,17 @@ public final class KeyBoardConvert { } public static ReplyKeyboard convertKeyBoard(KeyBoard keyBoard) { - if (keyBoard != null) { + if (checkNotNull(keyBoard)) { switch (keyBoard.getType()) { - case InlineKeyBoard.TYPE: + case InlineKeyBoard.TYPE -> { return convertInlineKeyBoard((InlineKeyBoard) keyBoard); - case MarkupKeyBoard.TYPE: + } + case MarkupKeyBoard.TYPE -> { return convertMarkupKeyBoard((MarkupKeyBoard) keyBoard); - case SimpleKeyBoard.TYPE: + } + case SimpleKeyBoard.TYPE -> { return convertSimpleKeyBoard((SimpleKeyBoard) keyBoard); + } } } return null; @@ -130,7 +136,7 @@ public final class KeyBoardConvert { case SimpleButton.TYPE -> { final SimpleButton simpleButton = (SimpleButton) keyBoardButton; button.setText(simpleButton.getLabel()); - Inspector.isNull(simpleButton.getCallbackData(), ConvertException.convertException("CallbackData поддерживает только Inline клавитаура")); + isNull(simpleButton.getCallbackData(), convertException("CallbackData поддерживает только Inline клавитаура")); } case WebAppButton.TYPE -> { final WebAppButton webAppButton = (WebAppButton) keyBoardButton;