From d68e278931d73922f3dcacecbb4963f72dbf00a6 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 18 Feb 2023 19:51:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 562 ++++++++---------- ...legramBotSpringBootStarterApplication.java | 13 - src/main/resources/application.yml | 1 - .../pom.xml | 48 ++ .../starter/TelegramBotAutoconfiguration.java | 182 ++++++ .../TelegramBotConfigAutoconfiguration.java | 29 + .../telegram/starter/UnitConfiguration.java | 5 + telegram-bot-spring-boot-starter/pom.xml | 33 + ...ot.autoconfigure.AutoConfiguration.imports | 2 + 9 files changed, 563 insertions(+), 312 deletions(-) delete mode 100644 src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotSpringBootStarterApplication.java delete mode 100644 src/main/resources/application.yml create mode 100644 telegram-bot-spring-boot-autoconfiguration/pom.xml create mode 100644 telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java create mode 100644 telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java create mode 100644 telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java create mode 100644 telegram-bot-spring-boot-starter/pom.xml create mode 100644 telegram-bot-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/pom.xml b/pom.xml index 14479d9..6c63857 100644 --- a/pom.xml +++ b/pom.xml @@ -1,314 +1,280 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.0.2 - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.2 + + - dev.struchkov.godfather.telegram - telegram-bot-spring-boot-starter - 0.0.1-SNAPSHOT + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-starter-parent + 0.0.1-SNAPSHOT + pom + + telegram-bot-spring-boot-autoconfiguration + telegram-bot-spring-boot-starter + - telegram-bot-spring-boot-starter - telegram-bot-spring-boot-starter + + 17 + ${java.version} + ${java.version} + UTF-8 + UTF-8 - - 17 - ${java.version} - ${java.version} - UTF-8 - UTF-8 + 0.0.49 - 0.0.49 + + 3.10.1 + + 1.6.13 + + 3.2.1 + + 3.5.0 + + 3.0.1 + + 3.0.0-M7 + - - 3.10.1 - - 1.6.13 - - 3.2.1 - - 3.5.0 - - 3.0.1 - - 3.0.0-M7 - + + + + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-autoconfiguration + 0.0.1-SNAPSHOT + + + - - - dev.struchkov.godfather.telegram - telegram-consumer-simple - ${telegram.bot.version} - - - dev.struchkov.godfather.telegram - telegram-core-simple - ${telegram.bot.version} - - - dev.struchkov.godfather.telegram - telegram-sender-simple - ${telegram.bot.version} - + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${plugin.nexus.staging.ver} + true + + + org.apache.maven.plugins + maven-source-plugin + ${plugin.maven.source.ver} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${plugin.maven.javadoc.ver} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${plugin.maven.gpg.ver} + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${plugin.maven.compiler.ver} + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-release-plugin + ${plugin.maven.release.ver} + + clean install + v.@{project.version} + true + false + true + true + + + + - - org.springframework.boot - spring-boot-starter - true - + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-release-plugin + + + - - org.springframework.boot - spring-boot-devtools - runtime - true - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${plugin.nexus.staging.ver} - true - - - org.apache.maven.plugins - maven-source-plugin - ${plugin.maven.source.ver} - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${plugin.maven.javadoc.ver} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${plugin.maven.gpg.ver} - - - sign-artifacts - verify - - sign - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${plugin.maven.compiler.ver} - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-release-plugin - ${plugin.maven.release.ver} - - clean install - v.@{project.version} - true - false - true - true - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-release-plugin - - - - - - - release - - - - org.sonatype.plugins - nexus-staging-maven-plugin - - ossrh - https://s01.oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-gpg-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - - release-struchkov-nexus - - - - org.sonatype.plugins - nexus-staging-maven-plugin - - struchkov-nexus - https://nexus.struchkov.dev/nexus/ - true - true - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-gpg-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - - snapshot - - - - org.sonatype.plugins - nexus-staging-maven-plugin - - struchkov-nexus - https://nexus.struchkov.dev/nexus/ - true - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - + + + release + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-gpg-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + + release-struchkov-nexus + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + struchkov-nexus + https://nexus.struchkov.dev/nexus/ + true + true + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-gpg-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + + snapshot + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + struchkov-nexus + https://nexus.struchkov.dev/nexus/ + true + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + - - - struchkov-nexus-release - https://nexus.struchkov.dev/repository/maven-releases/ - - true - always - fail - - - false - - - - struchkov-nexus-snapshot - https://nexus.struchkov.dev/repository/maven-snapshots/ - - false - - - true - always - warn - - - + + + struchkov-nexus-release + https://nexus.struchkov.dev/repository/maven-releases/ + + true + always + fail + + + false + + + + struchkov-nexus-snapshot + https://nexus.struchkov.dev/repository/maven-snapshots/ + + false + + + true + always + warn + + + - - - struchkov-nexus-release - https://nexus.struchkov.dev/repository/maven-releases/ - - - struchkov-nexus-snapshot - https://nexus.struchkov.dev/repository/maven-snapshots/ - - + + + struchkov-nexus-release + https://nexus.struchkov.dev/repository/maven-releases/ + + + struchkov-nexus-snapshot + https://nexus.struchkov.dev/repository/maven-snapshots/ + + - - - uPagge - Struchkov Mark - mark@struchkov.dev - https://mark.struchkov.dev - - + + + uPagge + Struchkov Mark + mark@struchkov.dev + https://mark.struchkov.dev + + diff --git a/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotSpringBootStarterApplication.java b/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotSpringBootStarterApplication.java deleted file mode 100644 index 36939cf..0000000 --- a/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotSpringBootStarterApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.struchkov.godfather.telegram.starter; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class TelegramBotSpringBootStarterApplication { - - public static void main(String[] args) { - SpringApplication.run(TelegramBotSpringBootStarterApplication.class, args); - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/telegram-bot-spring-boot-autoconfiguration/pom.xml b/telegram-bot-spring-boot-autoconfiguration/pom.xml new file mode 100644 index 0000000..d688327 --- /dev/null +++ b/telegram-bot-spring-boot-autoconfiguration/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-starter-parent + 0.0.1-SNAPSHOT + + + telegram-bot-spring-boot-autoconfiguration + + + 17 + 17 + UTF-8 + + + + + dev.struchkov.godfather.telegram + telegram-consumer-simple + ${telegram.bot.version} + + + dev.struchkov.godfather.telegram + telegram-core-simple + ${telegram.bot.version} + + + dev.struchkov.godfather.telegram + telegram-sender-simple + ${telegram.bot.version} + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + \ No newline at end of file diff --git a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java new file mode 100644 index 0000000..8d13916 --- /dev/null +++ b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java @@ -0,0 +1,182 @@ +package dev.struchkov.godfather.telegram.starter; + +import dev.struchkov.godfather.main.domain.content.Mail; +import dev.struchkov.godfather.simple.context.service.ErrorHandler; +import dev.struchkov.godfather.simple.context.service.EventHandler; +import dev.struchkov.godfather.simple.context.service.PersonSettingService; +import dev.struchkov.godfather.simple.context.service.UnitPointerService; +import dev.struchkov.godfather.simple.core.action.AnswerTextAction; +import dev.struchkov.godfather.simple.core.provider.StoryLineHandler; +import dev.struchkov.godfather.simple.core.service.PersonSettingServiceImpl; +import dev.struchkov.godfather.simple.core.service.StorylineContextMapImpl; +import dev.struchkov.godfather.simple.core.service.StorylineMailService; +import dev.struchkov.godfather.simple.core.service.StorylineService; +import dev.struchkov.godfather.simple.core.service.UnitPointerServiceImpl; +import dev.struchkov.godfather.simple.data.StorylineContext; +import dev.struchkov.godfather.simple.data.repository.PersonSettingRepository; +import dev.struchkov.godfather.simple.data.repository.StorylineRepository; +import dev.struchkov.godfather.simple.data.repository.UnitPointerRepository; +import dev.struchkov.godfather.simple.data.repository.impl.PersonSettingLocalRepository; +import dev.struchkov.godfather.simple.data.repository.impl.StorylineMapRepository; +import dev.struchkov.godfather.simple.data.repository.impl.UnitPointLocalRepository; +import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; +import dev.struchkov.godfather.telegram.main.context.TelegramConnect; +import dev.struchkov.godfather.telegram.simple.consumer.EventDistributorService; +import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository; +import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramService; +import dev.struchkov.godfather.telegram.simple.core.MailAutoresponderTelegram; +import dev.struchkov.godfather.telegram.simple.core.TelegramConnectBot; +import dev.struchkov.godfather.telegram.simple.core.service.SenderMapRepository; +import dev.struchkov.godfather.telegram.simple.core.service.TelegramServiceImpl; +import dev.struchkov.godfather.telegram.simple.sender.TelegramSender; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + +@Configuration +public class TelegramBotAutoconfiguration { + + @Bean + @ConditionalOnProperty(prefix = "telegram-bot", name = "bot-username") + public TelegramConnectBot telegramConnectBot(TelegramConnectConfig telegramConfig) { + return new TelegramConnectBot(telegramConfig); + } + +// @Bean +// @ConditionalOnMissingBean(TelegramConnectBot.class) +// @ConditionalOnProperty("telegram-bot.bot-username") +// public TelegramConnect telegramDefaultConnect(TelegramConnectConfig telegramConfig) { +// return new TelegramDefaultConnect(telegramConfig); +// } + + @Bean("messageExecutorService") + public ExecutorService executorService() { + return Executors.newFixedThreadPool(3); + } + + @Bean + @ConditionalOnBean(TelegramConnect.class) + public TelegramService telegramService(TelegramConnect telegramConnect) { + return new TelegramServiceImpl(telegramConnect); + } + + @Bean + public StorylineContext storylineContext() { + return new StorylineContextMapImpl(); + } + + @Bean + public UnitPointerRepository unitPointerRepository() { + return new UnitPointLocalRepository(); + } + + @Bean + public UnitPointerService unitPointerService(UnitPointerRepository unitPointerRepository) { + return new UnitPointerServiceImpl(unitPointerRepository); + } + + @Bean + public PersonSettingRepository personSettingRepository() { + return new PersonSettingLocalRepository(); + } + + @Bean + public PersonSettingService personSettingService(PersonSettingRepository personSettingRepository) { + return new PersonSettingServiceImpl(personSettingRepository); + } + + @Bean + public StorylineRepository storylineRepository() { + return new StorylineMapRepository(); + } + + @Bean + public MailAutoresponderTelegram messageAutoresponderTelegram( + @Qualifier("messageExecutorService") ObjectProvider executorServiceProvider, + TelegramSending sending, + PersonSettingService personSettingService, + ObjectProvider errorHandlerProvider, + ObjectProvider answerTextActionProvider, + + StorylineService storylineService + ) { + final MailAutoresponderTelegram autoresponder = new MailAutoresponderTelegram( + sending, personSettingService, storylineService + ); + + final ExecutorService executorService = executorServiceProvider.getIfAvailable(); + if (checkNotNull(executorService)) { + autoresponder.setExecutorService(executorService); + } + + final ErrorHandler errorHandler = errorHandlerProvider.getIfAvailable(); + if (checkNotNull(errorHandler)) { + autoresponder.setErrorHandler(errorHandler); + } + + final AnswerTextAction answerTextAction = answerTextActionProvider.getIfAvailable(); + if (checkNotNull(answerTextAction)) { + autoresponder.initTextAnswerActionUnit(answerTextAction); + } + return autoresponder; + } + + @Bean + public SenderRepository senderRepository() { + return new SenderMapRepository(); + } + + @Bean + @ConditionalOnBean(TelegramConnect.class) + public TelegramSending sending( + TelegramConnect telegramConnect, + ObjectProvider senderRepositoryProvider + ) { + final TelegramSender telegramSender = new TelegramSender(telegramConnect); + + final SenderRepository senderRepository = senderRepositoryProvider.getIfAvailable(); + if (checkNotNull(senderRepository)) { + telegramSender.setSenderRepository(senderRepository); + } + + return telegramSender; + } + + @Bean + public StoryLineHandler storyLineHandler(MailAutoresponderTelegram mailAutoresponderTelegram) { + return new StoryLineHandler(mailAutoresponderTelegram); + } + + @Bean + public EventDistributor eventDistributor( + TelegramConnectBot telegramConnect, List eventProviders + ) { + return new EventDistributorService(telegramConnect, eventProviders); + } + + @Bean + public StorylineService storylineService( + UnitPointerService unitPointerService, + StorylineRepository storylineRepository, + List unitConfigurations + ) { + return new StorylineMailService( + unitPointerService, + storylineRepository, + new ArrayList<>(unitConfigurations) + ); + } + +} diff --git a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java new file mode 100644 index 0000000..e637ae9 --- /dev/null +++ b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java @@ -0,0 +1,29 @@ +package dev.struchkov.godfather.telegram.starter; + +import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; +import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties +public class TelegramBotConfigAutoconfiguration { + + @Bean + @ConfigurationProperties("telegram-bot.proxy-config") + @ConditionalOnProperty(prefix = "telegram-bot.proxy-config", name = "enable", havingValue = "true") + public ProxyConfig proxyConfig() { + return new ProxyConfig(); + } + + @Bean + @ConfigurationProperties("telegram-bot") + @ConditionalOnProperty(prefix = "telegram-bot", name = "bot-username") + public TelegramConnectConfig telegramConfig() { + return new TelegramConnectConfig(); + } + +} diff --git a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java new file mode 100644 index 0000000..4113e02 --- /dev/null +++ b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java @@ -0,0 +1,5 @@ +package dev.struchkov.godfather.telegram.starter; + +public interface UnitConfiguration { + +} diff --git a/telegram-bot-spring-boot-starter/pom.xml b/telegram-bot-spring-boot-starter/pom.xml new file mode 100644 index 0000000..1d8d4f6 --- /dev/null +++ b/telegram-bot-spring-boot-starter/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-starter-parent + 0.0.1-SNAPSHOT + + + telegram-bot-spring-boot-starter + + + 17 + 17 + UTF-8 + + + + + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-autoconfiguration + + + + org.springframework.boot + spring-boot-starter + true + + + + \ No newline at end of file diff --git a/telegram-bot-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/telegram-bot-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..29d0d81 --- /dev/null +++ b/telegram-bot-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +dev.struchkov.godfather.telegram.starter.TelegramBotConfigAutoconfiguration +dev.struchkov.godfather.telegram.starter.TelegramBotAutoconfiguration \ No newline at end of file