This commit is contained in:
parent
1bb026f9d1
commit
4c522c01ae
29
pom.xml
29
pom.xml
@ -10,13 +10,8 @@
|
||||
</parent>
|
||||
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-bot-spring-boot-starter-parent</artifactId>
|
||||
<artifactId>telegram-bot-spring-boot-starter</artifactId>
|
||||
<version>0.0.50-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>telegram-bot-spring-boot-autoconfiguration</module>
|
||||
<module>telegram-bot-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
@ -26,6 +21,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<telegram.bot.version>0.0.50-SNAPSHOT</telegram.bot.version>
|
||||
<godfather.version>0.0.52-SNAPSHOT</godfather.version>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
|
||||
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
|
||||
@ -41,7 +37,6 @@
|
||||
<plugin.maven.release.ver>3.0.0-M7</plugin.maven.release.ver>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
@ -64,8 +59,23 @@
|
||||
<artifactId>telegram-sender-simple</artifactId>
|
||||
<version>${telegram.bot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-data-simple</artifactId>
|
||||
<version>${godfather.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
@ -287,7 +297,8 @@
|
||||
<scm>
|
||||
<connection>scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git</connection>
|
||||
<url>https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter</url>
|
||||
<developerConnection>scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git</developerConnection>
|
||||
<developerConnection>scm:git:https://git.struchkov.dev/Godfather-Bots/telegram-bot-spring-boot-starter.git
|
||||
</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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<ExecutorService> executorServiceProvider,
|
||||
@Qualifier(AUTORESPONDER_EXECUTORS_SERVICE) ObjectProvider<ExecutorService> executorServiceProvider,
|
||||
TelegramSending sending,
|
||||
PersonSettingService personSettingService,
|
||||
ObjectProvider<ErrorHandler> errorHandlerProvider,
|
||||
@ -133,11 +116,6 @@ public class TelegramBotAutoconfiguration {
|
||||
return autoresponder;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SenderRepository senderRepository() {
|
||||
return new SenderMapRepository();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(TelegramConnect.class)
|
||||
public TelegramSending sending(
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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<ProxyConfig> 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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-bot-spring-boot-starter-parent</artifactId>
|
||||
<version>0.0.50-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegram-bot-spring-boot-autoconfiguration</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-consumer-simple</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-core-simple</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-sender-simple</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-bot-spring-boot-starter-parent</artifactId>
|
||||
<version>0.0.50-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegram-bot-spring-boot-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||
<artifactId>telegram-bot-spring-boot-autoconfiguration</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,2 +0,0 @@
|
||||
dev.struchkov.godfather.telegram.starter.TelegramBotConfigAutoconfiguration
|
||||
dev.struchkov.godfather.telegram.starter.TelegramBotAutoconfiguration
|
Loading…
x
Reference in New Issue
Block a user