Первая версия стартера

This commit is contained in:
2023-02-18 19:51:52 +03:00
parent 621a4549cb
commit d68e278931
9 changed files with 563 additions and 312 deletions

54
pom.xml
View File

@@ -10,11 +10,13 @@
</parent> </parent>
<groupId>dev.struchkov.godfather.telegram</groupId> <groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-bot-spring-boot-starter</artifactId> <artifactId>telegram-bot-spring-boot-starter-parent</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>telegram-bot-spring-boot-starter</name> <modules>
<description>telegram-bot-spring-boot-starter</description> <module>telegram-bot-spring-boot-autoconfiguration</module>
<module>telegram-bot-spring-boot-starter</module>
</modules>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
@@ -39,51 +41,15 @@
<plugin.maven.release.ver>3.0.0-M7</plugin.maven.release.ver> <plugin.maven.release.ver>3.0.0-M7</plugin.maven.release.ver>
</properties> </properties>
<dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>dev.struchkov.godfather.telegram</groupId> <groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId> <artifactId>telegram-bot-spring-boot-autoconfiguration</artifactId>
<version>${telegram.bot.version}</version> <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<version>${telegram.bot.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
<version>${telegram.bot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement>
<build> <build>
<pluginManagement> <pluginManagement>

View File

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

View File

@@ -1 +0,0 @@

View File

@@ -0,0 +1,48 @@
<?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.1-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>
<version>${telegram.bot.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<version>${telegram.bot.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
<version>${telegram.bot.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>
</project>

View File

@@ -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<ExecutorService> executorServiceProvider,
TelegramSending sending,
PersonSettingService personSettingService,
ObjectProvider<ErrorHandler> errorHandlerProvider,
ObjectProvider<AnswerTextAction> answerTextActionProvider,
StorylineService<Mail> 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<SenderRepository> 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<EventHandler> eventProviders
) {
return new EventDistributorService(telegramConnect, eventProviders);
}
@Bean
public StorylineService<Mail> storylineService(
UnitPointerService unitPointerService,
StorylineRepository storylineRepository,
List<UnitConfiguration> unitConfigurations
) {
return new StorylineMailService(
unitPointerService,
storylineRepository,
new ArrayList<>(unitConfigurations)
);
}
}

View File

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

View File

@@ -0,0 +1,5 @@
package dev.struchkov.godfather.telegram.starter;
public interface UnitConfiguration {
}

View File

@@ -0,0 +1,33 @@
<?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.1-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>

View File

@@ -0,0 +1,2 @@
dev.struchkov.godfather.telegram.starter.TelegramBotConfigAutoconfiguration
dev.struchkov.godfather.telegram.starter.TelegramBotAutoconfiguration