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

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

562
pom.xml
View File

@@ -1,314 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?> <?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" <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version> <version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</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>
<modules>
<module>telegram-bot-spring-boot-autoconfiguration</module>
<module>telegram-bot-spring-boot-starter</module>
</modules>
<name>telegram-bot-spring-boot-starter</name> <properties>
<description>telegram-bot-spring-boot-starter</description> <java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<properties> <telegram.bot.version>0.0.49</telegram.bot.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegram.bot.version>0.0.49</telegram.bot.version> <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
<!-- https://mvnrepository.com/artifact/org.sonatype.plugins/nexus-staging-maven-plugin -->
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-source-plugin -->
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
<plugin.maven.javadoc.ver>3.5.0</plugin.maven.javadoc.ver>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-gpg-plugin -->
<plugin.maven.gpg.ver>3.0.1</plugin.maven.gpg.ver>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-release-plugin -->
<plugin.maven.release.ver>3.0.0-M7</plugin.maven.release.ver>
</properties>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin --> <dependencyManagement>
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver> <dependencies>
<!-- https://mvnrepository.com/artifact/org.sonatype.plugins/nexus-staging-maven-plugin --> <dependency>
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver> <groupId>dev.struchkov.godfather.telegram</groupId>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-source-plugin --> <artifactId>telegram-bot-spring-boot-autoconfiguration</artifactId>
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver> <version>0.0.1-SNAPSHOT</version>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin --> </dependency>
<plugin.maven.javadoc.ver>3.5.0</plugin.maven.javadoc.ver> </dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-gpg-plugin --> </dependencyManagement>
<plugin.maven.gpg.ver>3.0.1</plugin.maven.gpg.ver>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-release-plugin -->
<plugin.maven.release.ver>3.0.0-M7</plugin.maven.release.ver>
</properties>
<dependencies> <build>
<dependency> <pluginManagement>
<groupId>dev.struchkov.godfather.telegram</groupId> <plugins>
<artifactId>telegram-consumer-simple</artifactId> <plugin>
<version>${telegram.bot.version}</version> <groupId>org.sonatype.plugins</groupId>
</dependency> <artifactId>nexus-staging-maven-plugin</artifactId>
<dependency> <version>${plugin.nexus.staging.ver}</version>
<groupId>dev.struchkov.godfather.telegram</groupId> <extensions>true</extensions>
<artifactId>telegram-core-simple</artifactId> </plugin>
<version>${telegram.bot.version}</version> <plugin>
</dependency> <groupId>org.apache.maven.plugins</groupId>
<dependency> <artifactId>maven-source-plugin</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId> <version>${plugin.maven.source.ver}</version>
<artifactId>telegram-sender-simple</artifactId> <executions>
<version>${telegram.bot.version}</version> <execution>
</dependency> <id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${plugin.maven.javadoc.ver}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${plugin.maven.gpg.ver}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.maven.compiler.ver}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${plugin.maven.release.ver}</version>
<configuration>
<preparationGoals>clean install</preparationGoals>
<tagNameFormat>v.@{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<signTag>true</signTag>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<dependency> <plugins>
<groupId>org.springframework.boot</groupId> <plugin>
<artifactId>spring-boot-starter</artifactId> <groupId>org.apache.maven.plugins</groupId>
<optional>true</optional> <artifactId>maven-compiler-plugin</artifactId>
</dependency> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependency> <profiles>
<groupId>org.springframework.boot</groupId> <profile>
<artifactId>spring-boot-devtools</artifactId> <id>release</id>
<scope>runtime</scope> <build>
<optional>true</optional> <plugins>
</dependency> <plugin>
<dependency> <groupId>org.sonatype.plugins</groupId>
<groupId>org.springframework.boot</groupId> <artifactId>nexus-staging-maven-plugin</artifactId>
<artifactId>spring-boot-configuration-processor</artifactId> <configuration>
<optional>true</optional> <serverId>ossrh</serverId>
</dependency> <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<dependency> <autoReleaseAfterClose>true</autoReleaseAfterClose>
<groupId>org.projectlombok</groupId> </configuration>
<artifactId>lombok</artifactId> </plugin>
<optional>true</optional> <plugin>
</dependency> <groupId>org.apache.maven.plugins</groupId>
<dependency> <artifactId>maven-source-plugin</artifactId>
<groupId>org.springframework.boot</groupId> </plugin>
<artifactId>spring-boot-starter-test</artifactId> <plugin>
<scope>test</scope> <groupId>org.apache.maven.plugins</groupId>
</dependency> <artifactId>maven-gpg-plugin</artifactId>
</dependencies> </plugin>
<plugin>
<build> <groupId>org.apache.maven.plugins</groupId>
<pluginManagement> <artifactId>maven-javadoc-plugin</artifactId>
<plugins> </plugin>
<plugin> </plugins>
<groupId>org.sonatype.plugins</groupId> </build>
<artifactId>nexus-staging-maven-plugin</artifactId> </profile>
<version>${plugin.nexus.staging.ver}</version> <profile>
<extensions>true</extensions> <id>release-struchkov-nexus</id>
</plugin> <build>
<plugin> <plugins>
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-source-plugin</artifactId> <groupId>org.sonatype.plugins</groupId>
<version>${plugin.maven.source.ver}</version> <artifactId>nexus-staging-maven-plugin</artifactId>
<executions> <configuration>
<execution> <serverId>struchkov-nexus</serverId>
<id>attach-sources</id> <nexusUrl>https://nexus.struchkov.dev/nexus/</nexusUrl>
<goals> <autoReleaseAfterClose>true</autoReleaseAfterClose>
<goal>jar-no-fork</goal> <skipStaging>true</skipStaging>
</goals> </configuration>
</execution> </plugin>
</executions> <plugin>
</plugin> <groupId>org.apache.maven.plugins</groupId>
<plugin> <artifactId>maven-source-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId> </plugin>
<artifactId>maven-javadoc-plugin</artifactId> <plugin>
<version>${plugin.maven.javadoc.ver}</version> <groupId>org.apache.maven.plugins</groupId>
<executions> <artifactId>maven-gpg-plugin</artifactId>
<execution> </plugin>
<id>attach-javadocs</id> <plugin>
<goals> <groupId>org.apache.maven.plugins</groupId>
<goal>jar</goal> <artifactId>maven-javadoc-plugin</artifactId>
</goals> </plugin>
</execution> </plugins>
</executions> </build>
</plugin> </profile>
<plugin> <profile>
<groupId>org.apache.maven.plugins</groupId> <id>snapshot</id>
<artifactId>maven-gpg-plugin</artifactId> <build>
<version>${plugin.maven.gpg.ver}</version> <plugins>
<executions> <plugin>
<execution> <groupId>org.sonatype.plugins</groupId>
<id>sign-artifacts</id> <artifactId>nexus-staging-maven-plugin</artifactId>
<phase>verify</phase> <configuration>
<goals> <serverId>struchkov-nexus</serverId>
<goal>sign</goal> <nexusUrl>https://nexus.struchkov.dev/nexus/</nexusUrl>
</goals> <autoReleaseAfterClose>true</autoReleaseAfterClose>
</execution> </configuration>
</executions> </plugin>
</plugin> <plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId> </plugin>
<version>${plugin.maven.compiler.ver}</version> <plugin>
<configuration> <groupId>org.apache.maven.plugins</groupId>
<source>${java.version}</source> <artifactId>maven-javadoc-plugin</artifactId>
<target>${java.version}</target> </plugin>
</configuration> </plugins>
</plugin> </build>
<plugin> </profile>
<groupId>org.apache.maven.plugins</groupId> </profiles>
<artifactId>maven-release-plugin</artifactId>
<version>${plugin.maven.release.ver}</version>
<configuration>
<preparationGoals>clean install</preparationGoals>
<tagNameFormat>v.@{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<signTag>true</signTag>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-struchkov-nexus</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<serverId>struchkov-nexus</serverId>
<nexusUrl>https://nexus.struchkov.dev/nexus/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>snapshot</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<serverId>struchkov-nexus</serverId>
<nexusUrl>https://nexus.struchkov.dev/nexus/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<repositories> <repositories>
<repository> <repository>
<id>struchkov-nexus-release</id> <id>struchkov-nexus-release</id>
<url>https://nexus.struchkov.dev/repository/maven-releases/</url> <url>https://nexus.struchkov.dev/repository/maven-releases/</url>
<releases> <releases>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy> <checksumPolicy>fail</checksumPolicy>
</releases> </releases>
<snapshots> <snapshots>
<enabled>false</enabled> <enabled>false</enabled>
</snapshots> </snapshots>
</repository> </repository>
<repository> <repository>
<id>struchkov-nexus-snapshot</id> <id>struchkov-nexus-snapshot</id>
<url>https://nexus.struchkov.dev/repository/maven-snapshots/</url> <url>https://nexus.struchkov.dev/repository/maven-snapshots/</url>
<releases> <releases>
<enabled>false</enabled> <enabled>false</enabled>
</releases> </releases>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy> <checksumPolicy>warn</checksumPolicy>
</snapshots> </snapshots>
</repository> </repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>
<repository> <repository>
<id>struchkov-nexus-release</id> <id>struchkov-nexus-release</id>
<url>https://nexus.struchkov.dev/repository/maven-releases/</url> <url>https://nexus.struchkov.dev/repository/maven-releases/</url>
</repository> </repository>
<snapshotRepository> <snapshotRepository>
<id>struchkov-nexus-snapshot</id> <id>struchkov-nexus-snapshot</id>
<url>https://nexus.struchkov.dev/repository/maven-snapshots/</url> <url>https://nexus.struchkov.dev/repository/maven-snapshots/</url>
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
<developers> <developers>
<developer> <developer>
<id>uPagge</id> <id>uPagge</id>
<name>Struchkov Mark</name> <name>Struchkov Mark</name>
<email>mark@struchkov.dev</email> <email>mark@struchkov.dev</email>
<url>https://mark.struchkov.dev</url> <url>https://mark.struchkov.dev</url>
</developer> </developer>
</developers> </developers>
</project> </project>

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