diff --git a/pom.xml b/pom.xml index 161e53c..6d808b0 100644 --- a/pom.xml +++ b/pom.xml @@ -10,13 +10,8 @@ dev.struchkov.godfather.telegram - telegram-bot-spring-boot-starter-parent + telegram-bot-spring-boot-starter 0.0.50-SNAPSHOT - pom - - telegram-bot-spring-boot-autoconfiguration - telegram-bot-spring-boot-starter - 17 @@ -26,6 +21,7 @@ UTF-8 0.0.50-SNAPSHOT + 0.0.52-SNAPSHOT 3.10.1 @@ -41,31 +37,45 @@ 3.0.0-M7 - - - - dev.struchkov.godfather.telegram - telegram-bot-spring-boot-autoconfiguration - 0.0.50-SNAPSHOT - + + + dev.struchkov.godfather.telegram + telegram-bot-spring-boot-autoconfiguration + 0.0.50-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} - - - + + 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} + + + + dev.struchkov.godfather + bot-data-simple + ${godfather.version} + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-configuration-processor + true + + @@ -287,7 +297,8 @@ scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter - scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git + scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git + HEAD diff --git a/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotBeanName.java b/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotBeanName.java new file mode 100644 index 0000000..bc71f27 --- /dev/null +++ b/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotBeanName.java @@ -0,0 +1,13 @@ +package dev.struchkov.godfather.telegram.starter; + +import dev.struchkov.haiti.utils.Exceptions; + +public class TelegramBotBeanName { + + public static final String AUTORESPONDER_EXECUTORS_SERVICE = "autoresponderExecutorService"; + + private TelegramBotBeanName() { + Exceptions.utilityClass(); + } + +} diff --git a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java b/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java similarity index 100% rename from telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java rename to src/main/java/dev/struchkov/godfather/telegram/starter/UnitConfiguration.java diff --git a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotAutoconfiguration.java similarity index 75% rename from telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java rename to src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotAutoconfiguration.java index 539cf14..d7fbe64 100644 --- a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotAutoconfiguration.java +++ b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotAutoconfiguration.java @@ -1,8 +1,7 @@ -package dev.struchkov.godfather.telegram.starter; +package dev.struchkov.godfather.telegram.starter.config; import dev.struchkov.godfather.main.domain.content.Mail; import dev.struchkov.godfather.simple.context.repository.PersonSettingRepository; -import dev.struchkov.godfather.simple.context.repository.StorylineContext; import dev.struchkov.godfather.simple.context.repository.StorylineRepository; import dev.struchkov.godfather.simple.context.repository.UnitPointerRepository; import dev.struchkov.godfather.simple.context.service.ErrorHandler; @@ -12,15 +11,12 @@ 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.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.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.main.context.TelegramConnect; +import dev.struchkov.godfather.telegram.main.core.TelegramDefaultConnect; 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; @@ -28,42 +24,48 @@ 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 dev.struchkov.godfather.telegram.starter.UnitConfiguration; +import dev.struchkov.godfather.telegram.starter.property.TelegramBotAutoresponderProperty; 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 org.springframework.context.annotation.Primary; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static dev.struchkov.godfather.telegram.starter.TelegramBotBeanName.AUTORESPONDER_EXECUTORS_SERVICE; 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) { + @Primary + @ConditionalOnProperty(prefix = "telegram.bot", name = "username") + public TelegramConnectBot telegramConnectBot(TelegramBotConfig telegramConfig) { return new TelegramConnectBot(telegramConfig); } -// @Bean -// @ConditionalOnMissingBean(TelegramConnectBot.class) -// @ConditionalOnProperty("telegram-bot.bot-username") -// public TelegramConnect telegramDefaultConnect(TelegramConnectConfig telegramConfig) { -// return new TelegramDefaultConnect(telegramConfig); -// } + @Bean + @ConditionalOnProperty(prefix = "telegram.bot", name = "token") + public TelegramDefaultConnect telegramDefaultConnect(TelegramBotConfig telegramConfig) { + return new TelegramDefaultConnect(telegramConfig); + } - @Bean("messageExecutorService") - public ExecutorService executorService() { - return Executors.newFixedThreadPool(3); + @ConditionalOnBean(TelegramConnectBot.class) + @Bean(AUTORESPONDER_EXECUTORS_SERVICE) + public ExecutorService executorService( + TelegramBotAutoresponderProperty autoresponderProperty + ) { + return Executors.newFixedThreadPool(autoresponderProperty.getThreads()); } @Bean @@ -72,39 +74,20 @@ public class TelegramBotAutoconfiguration { 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 + @ConditionalOnBean(TelegramConnectBot.class) public MailAutoresponderTelegram messageAutoresponderTelegram( - @Qualifier("messageExecutorService") ObjectProvider executorServiceProvider, + @Qualifier(AUTORESPONDER_EXECUTORS_SERVICE) ObjectProvider executorServiceProvider, TelegramSending sending, PersonSettingService personSettingService, ObjectProvider errorHandlerProvider, @@ -133,11 +116,6 @@ public class TelegramBotAutoconfiguration { return autoresponder; } - @Bean - public SenderRepository senderRepository() { - return new SenderMapRepository(); - } - @Bean @ConditionalOnBean(TelegramConnect.class) public TelegramSending sending( diff --git a/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotDataConfiguration.java b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotDataConfiguration.java new file mode 100644 index 0000000..62b4da4 --- /dev/null +++ b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotDataConfiguration.java @@ -0,0 +1,49 @@ +package dev.struchkov.godfather.telegram.starter.config; + +import dev.struchkov.godfather.simple.context.repository.PersonSettingRepository; +import dev.struchkov.godfather.simple.context.repository.StorylineContext; +import dev.struchkov.godfather.simple.context.repository.StorylineRepository; +import dev.struchkov.godfather.simple.context.repository.UnitPointerRepository; +import dev.struchkov.godfather.simple.core.service.StorylineContextMapImpl; +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.simple.context.repository.SenderRepository; +import dev.struchkov.godfather.telegram.simple.core.service.SenderMapRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TelegramBotDataConfiguration { + + @Bean + @ConditionalOnMissingBean(UnitPointerRepository.class) + public UnitPointerRepository unitPointerRepository() { + return new UnitPointLocalRepository(); + } + + @Bean + @ConditionalOnMissingBean(PersonSettingRepository.class) + public PersonSettingRepository personSettingRepository() { + return new PersonSettingLocalRepository(); + } + + @Bean + @ConditionalOnMissingBean(StorylineRepository.class) + public StorylineRepository storylineRepository() { + return new StorylineMapRepository(); + } + + @Bean + @ConditionalOnMissingBean(SenderRepository.class) + public SenderRepository senderRepository() { + return new SenderMapRepository(); + } + + @Bean + public StorylineContext storylineContext() { + return new StorylineContextMapImpl(); + } + +} diff --git a/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotPropertyConfiguration.java b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotPropertyConfiguration.java new file mode 100644 index 0000000..944e31b --- /dev/null +++ b/src/main/java/dev/struchkov/godfather/telegram/starter/config/TelegramBotPropertyConfiguration.java @@ -0,0 +1,46 @@ +package dev.struchkov.godfather.telegram.starter.config; + +import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; +import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; +import dev.struchkov.godfather.telegram.starter.property.TelegramBotAutoresponderProperty; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + +@Configuration +public class TelegramBotPropertyConfiguration { + + @Bean + @ConfigurationProperties("telegram.proxy") + @ConditionalOnProperty(prefix = "telegram.proxy", name = "enable", havingValue = "true") + public ProxyConfig proxyConfig() { + return new ProxyConfig(); + } + + @Bean + @ConfigurationProperties("telegram.bot") + @ConditionalOnProperty(prefix = "telegram.bot", name = "token") + public TelegramBotConfig telegramConfig( + ObjectProvider proxyConfigProvider + ) { + final TelegramBotConfig telegramBotConfig = new TelegramBotConfig(); + + final ProxyConfig proxyConfig = proxyConfigProvider.getIfAvailable(); + if (checkNotNull(proxyConfig)) { + telegramBotConfig.setProxyConfig(proxyConfig); + } + + return telegramBotConfig; + } + + @Bean + @ConfigurationProperties("telegram.bot.autoresponder") + public TelegramBotAutoresponderProperty telegramBotAutoresponderProperty() { + return new TelegramBotAutoresponderProperty(); + } + +} diff --git a/src/main/java/dev/struchkov/godfather/telegram/starter/property/TelegramBotAutoresponderProperty.java b/src/main/java/dev/struchkov/godfather/telegram/starter/property/TelegramBotAutoresponderProperty.java new file mode 100644 index 0000000..f3416e6 --- /dev/null +++ b/src/main/java/dev/struchkov/godfather/telegram/starter/property/TelegramBotAutoresponderProperty.java @@ -0,0 +1,15 @@ +package dev.struchkov.godfather.telegram.starter.property; + +public class TelegramBotAutoresponderProperty { + + private Integer threads = 8; + + public Integer getThreads() { + return threads; + } + + public void setThreads(Integer threads) { + this.threads = threads; + } + +} diff --git a/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..ef5f2bf --- /dev/null +++ b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,3 @@ +dev.struchkov.godfather.telegram.starter.config.TelegramBotPropertyConfiguration +dev.struchkov.godfather.telegram.starter.config.TelegramBotDataConfiguration +dev.struchkov.godfather.telegram.starter.config.TelegramBotAutoconfiguration \ No newline at end of file diff --git a/telegram-bot-spring-boot-autoconfiguration/pom.xml b/telegram-bot-spring-boot-autoconfiguration/pom.xml deleted file mode 100644 index 23206b0..0000000 --- a/telegram-bot-spring-boot-autoconfiguration/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - 4.0.0 - - dev.struchkov.godfather.telegram - telegram-bot-spring-boot-starter-parent - 0.0.50-SNAPSHOT - - - telegram-bot-spring-boot-autoconfiguration - - - 17 - 17 - UTF-8 - - - - - dev.struchkov.godfather.telegram - telegram-consumer-simple - - - dev.struchkov.godfather.telegram - telegram-core-simple - - - dev.struchkov.godfather.telegram - telegram-sender-simple - - - - 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/TelegramBotConfigAutoconfiguration.java b/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java deleted file mode 100644 index e637ae9..0000000 --- a/telegram-bot-spring-boot-autoconfiguration/src/main/java/dev/struchkov/godfather/telegram/starter/TelegramBotConfigAutoconfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -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-starter/pom.xml b/telegram-bot-spring-boot-starter/pom.xml deleted file mode 100644 index f6488a5..0000000 --- a/telegram-bot-spring-boot-starter/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - 4.0.0 - - dev.struchkov.godfather.telegram - telegram-bot-spring-boot-starter-parent - 0.0.50-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 deleted file mode 100644 index 29d0d81..0000000 --- a/telegram-bot-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,2 +0,0 @@ -dev.struchkov.godfather.telegram.starter.TelegramBotConfigAutoconfiguration -dev.struchkov.godfather.telegram.starter.TelegramBotAutoconfiguration \ No newline at end of file