Небольшой рефакторинг
This commit is contained in:
parent
9b8bb4a800
commit
f1065301d7
34
.gitignore
vendored
34
.gitignore
vendored
@ -42,27 +42,7 @@ buildNumber.properties
|
|||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
# User-specific stuff
|
# User-specific stuff
|
||||||
.idea/**/workspace.xml
|
.idea/
|
||||||
.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
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
# Gradle and Maven with auto-import
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
@ -80,9 +60,6 @@ buildNumber.properties
|
|||||||
# CMake
|
# CMake
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
# File-based project format
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
@ -95,17 +72,8 @@ out/
|
|||||||
# JIRA plugin
|
# JIRA plugin
|
||||||
atlassian-ide-plugin.xml
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
.idea/replstate.xml
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
com_crashlytics_export_strings.xml
|
com_crashlytics_export_strings.xml
|
||||||
crashlytics.properties
|
crashlytics.properties
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
.idea/httpRequests
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
.idea/caches/build_file_checksums.ser
|
|
||||||
|
@ -42,26 +42,22 @@ public class EventDistributorService implements EventDistributor {
|
|||||||
final CallbackQuery callbackQuery = update.getCallbackQuery();
|
final CallbackQuery callbackQuery = update.getCallbackQuery();
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (!isEvent(message)) {
|
if (!isEvent(message)) {
|
||||||
getHandler(Mail.TYPE)
|
getHandler(Mail.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(MessageMailConvert.apply(message))));
|
||||||
.ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(MessageMailConvert.apply(message))));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (callbackQuery != null) {
|
if (callbackQuery != null) {
|
||||||
getHandler(Mail.TYPE)
|
getHandler(Mail.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(CallbackQueryConvert.apply(callbackQuery))));
|
||||||
.ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(CallbackQueryConvert.apply(callbackQuery))));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (update.getMyChatMember() != null) {
|
if (update.getMyChatMember() != null) {
|
||||||
final ChatMemberUpdated chatMember = update.getMyChatMember();
|
final ChatMemberUpdated chatMember = update.getMyChatMember();
|
||||||
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {
|
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {
|
||||||
getHandler(Unsubscribe.TYPE)
|
getHandler(Unsubscribe.TYPE).ifPresent(providers -> providers.forEach(provider -> provider.handle(UnsubscribeConvert.apply(chatMember))));
|
||||||
.ifPresent(providers -> providers.forEach(provider -> provider.handle(UnsubscribeConvert.apply(chatMember))));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("member".equals(chatMember.getNewChatMember().getStatus())) {
|
if ("member".equals(chatMember.getNewChatMember().getStatus())) {
|
||||||
getHandler(Subscribe.TYPE)
|
getHandler(Subscribe.TYPE).ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(SubscribeConvert.apply(chatMember))));
|
||||||
.ifPresent(eventProviders -> eventProviders.forEach(eventProvider -> eventProvider.handle(SubscribeConvert.apply(chatMember))));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
|||||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||||
|
|
||||||
|
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
*
|
*
|
||||||
@ -30,7 +32,7 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public void onUpdateReceived(Update update) {
|
||||||
if (update != null && eventDistributor != null) {
|
if (checkNotNull(update) && checkNotNull(eventDistributor)) {
|
||||||
eventDistributor.processing(update);
|
eventDistributor.processing(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.godfather.telegram.domain.keyboard.button.WebAppButton;
|
||||||
import dev.struchkov.haiti.context.exception.ConvertException;
|
import dev.struchkov.haiti.context.exception.ConvertException;
|
||||||
import dev.struchkov.haiti.utils.Exceptions;
|
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.InlineKeyboardMarkup;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
|
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 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 {
|
public final class KeyBoardConvert {
|
||||||
|
|
||||||
private KeyBoardConvert() {
|
private KeyBoardConvert() {
|
||||||
@ -31,16 +34,19 @@ public final class KeyBoardConvert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ReplyKeyboard convertKeyBoard(KeyBoard keyBoard) {
|
public static ReplyKeyboard convertKeyBoard(KeyBoard keyBoard) {
|
||||||
if (keyBoard != null) {
|
if (checkNotNull(keyBoard)) {
|
||||||
switch (keyBoard.getType()) {
|
switch (keyBoard.getType()) {
|
||||||
case InlineKeyBoard.TYPE:
|
case InlineKeyBoard.TYPE -> {
|
||||||
return convertInlineKeyBoard((InlineKeyBoard) keyBoard);
|
return convertInlineKeyBoard((InlineKeyBoard) keyBoard);
|
||||||
case MarkupKeyBoard.TYPE:
|
}
|
||||||
|
case MarkupKeyBoard.TYPE -> {
|
||||||
return convertMarkupKeyBoard((MarkupKeyBoard) keyBoard);
|
return convertMarkupKeyBoard((MarkupKeyBoard) keyBoard);
|
||||||
case SimpleKeyBoard.TYPE:
|
}
|
||||||
|
case SimpleKeyBoard.TYPE -> {
|
||||||
return convertSimpleKeyBoard((SimpleKeyBoard) keyBoard);
|
return convertSimpleKeyBoard((SimpleKeyBoard) keyBoard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +136,7 @@ public final class KeyBoardConvert {
|
|||||||
case SimpleButton.TYPE -> {
|
case SimpleButton.TYPE -> {
|
||||||
final SimpleButton simpleButton = (SimpleButton) keyBoardButton;
|
final SimpleButton simpleButton = (SimpleButton) keyBoardButton;
|
||||||
button.setText(simpleButton.getLabel());
|
button.setText(simpleButton.getLabel());
|
||||||
Inspector.isNull(simpleButton.getCallbackData(), ConvertException.convertException("CallbackData поддерживает только Inline клавитаура"));
|
isNull(simpleButton.getCallbackData(), convertException("CallbackData поддерживает только Inline клавитаура"));
|
||||||
}
|
}
|
||||||
case WebAppButton.TYPE -> {
|
case WebAppButton.TYPE -> {
|
||||||
final WebAppButton webAppButton = (WebAppButton) keyBoardButton;
|
final WebAppButton webAppButton = (WebAppButton) keyBoardButton;
|
||||||
|
Loading…
Reference in New Issue
Block a user