Небольшой рефакторинг

This commit is contained in:
Struchkov Mark 2023-02-17 16:39:28 +03:00
parent 9b8bb4a800
commit f1065301d7
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 21 additions and 49 deletions

36
.gitignore vendored
View File

@ -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

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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;