Рефакторинг
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing

This commit is contained in:
Struchkov Mark 2023-02-18 20:47:01 +03:00
parent 1f587f80de
commit 1b63aa1f43
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
12 changed files with 29 additions and 228 deletions

View File

@ -51,10 +51,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -21,7 +21,7 @@ logging:
level:
"dev.struchkov": ${LOG_LEVEL:info}
telegram-config:
telegram-bot:
bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: ${TELEGRAM_BOT_TOKEN}
proxy-config:

18
pom.xml
View File

@ -44,7 +44,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<godfather.telegram.core.version>0.0.49</godfather.telegram.core.version>
<godfather.telegram.version>0.0.50-SNAPSHOT</godfather.telegram.version>
<haiti.utils.version>2.6.0</haiti.utils.version>
<haiti.utils.fields.version>0.0.9</haiti.utils.fields.version>
<haiti.filter.version>0.0.5</haiti.filter.version>
@ -129,20 +129,8 @@
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
<version>${godfather.telegram.core.version}</version>
<artifactId>telegram-bot-spring-boot-starter</artifactId>
<version>${godfather.telegram.version}</version>
</dependency>
<!-- /SADTECH -->

View File

@ -19,17 +19,7 @@
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<artifactId>telegram-bot-spring-boot-starter</artifactId>
</dependency>
</dependencies>

View File

@ -1,178 +0,0 @@
package dev.struchkov.bot.gitlab.telegram.config;
import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost;
import dev.struchkov.bot.gitlab.telegram.unit.MenuConfig;
import dev.struchkov.bot.gitlab.telegram.unit.command.AnswerNoteUnit;
import dev.struchkov.bot.gitlab.telegram.unit.command.DeleteMessageUnit;
import dev.struchkov.bot.gitlab.telegram.unit.command.DisableNotifyMrUnit;
import dev.struchkov.bot.gitlab.telegram.unit.command.DisableNotifyThreadUnit;
import dev.struchkov.bot.gitlab.telegram.unit.command.EnableProjectNotify;
import dev.struchkov.bot.gitlab.telegram.unit.flow.InitSettingFlow;
import dev.struchkov.godfather.main.core.unit.TypeUnit;
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.Sending;
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
import dev.struchkov.godfather.simple.core.action.AnswerTextAction;
import dev.struchkov.godfather.simple.core.action.cmd.RollBackCmdAction;
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.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.ProxyConfig;
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.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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
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 org.springframework.scheduling.annotation.EnableScheduling;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author upagge [30.01.2020]
*/
@Slf4j
@Configuration
@EnableScheduling
public class TelegramBotConfig {
@Bean("messageExecutorService")
public ExecutorService executorService() {
return Executors.newFixedThreadPool(3);
}
@Bean
public TelegramService telegramService(TelegramConnect telegramConnect) {
return new TelegramServiceImpl(telegramConnect);
}
@Bean
public AnswerTextAction answerTextAction(Sending sending) {
return new AnswerTextAction(sending);
}
@Bean
public StorylineContext storylineContext() {
return new StorylineContextMapImpl();
}
@Bean
public UnitPointerService unitPointerService() {
return new UnitPointerServiceImpl(new UnitPointLocalRepository());
}
@Bean
public PersonSettingService personSettingService() {
return new PersonSettingServiceImpl(new PersonSettingLocalRepository());
}
@Bean
public StorylineService<Mail> storylineService(
UnitPointerService unitPointerService,
MenuConfig menuConfig,
InitSettingFlow unitConfig,
AnswerNoteUnit commandUnit,
DeleteMessageUnit deleteMessageUnit,
DisableNotifyMrUnit disableNotifyMrUnit,
DisableNotifyThreadUnit disableNotifyThreadUnit,
EnableProjectNotify enableProjectNotify
) {
final List<Object> config = List.of(menuConfig, unitConfig, commandUnit, deleteMessageUnit, disableNotifyMrUnit,
disableNotifyThreadUnit, enableProjectNotify);
return new StorylineMailService(
unitPointerService,
new StorylineMapRepository(),
config
);
}
@Bean
public MailAutoresponderTelegram messageAutoresponderTelegram(
@Qualifier("messageExecutorService") ExecutorService executorService,
TelegramSending sending,
PersonSettingService personSettingService,
ErrorHandler errorHandler,
AnswerTextAction answerTextAction,
StorylineService<Mail> storylineService
) {
final MailAutoresponderTelegram autoresponder = new MailAutoresponderTelegram(
sending, personSettingService, storylineService
);
autoresponder.initActionUnit(TypeUnit.BACK_CMD, new RollBackCmdAction<>(storylineService));
autoresponder.setExecutorService(executorService);
autoresponder.setErrorHandler(errorHandler);
autoresponder.initTextAnswerActionUnit(answerTextAction);
return autoresponder;
}
@Bean
public TelegramSending sending(
TelegramConnect telegramConnect,
ReplaceUrlLocalhost replaceUrlLocalhost
) {
final TelegramSender telegramSender = new TelegramSender(telegramConnect);
telegramSender.addPreSendProcess(replaceUrlLocalhost);
telegramSender.setSenderRepository(new SenderMapRepository());
return telegramSender;
}
@Bean
public TelegramConnectBot telegramConnect(TelegramConnectConfig telegramConfig) {
return new TelegramConnectBot(telegramConfig);
}
@Bean
@ConfigurationProperties("telegram-proxy-config")
@ConditionalOnProperty(prefix = "telegram-config.proxy-config.enable", value = "true")
public ProxyConfig proxyConfig() {
return new ProxyConfig();
}
@Bean
@ConfigurationProperties("telegram-config")
public TelegramConnectConfig telegramConfig() {
return new TelegramConnectConfig();
}
@Bean
public StoryLineHandler storyLineHandler(
MailAutoresponderTelegram mailAutoresponderTelegram
) {
return new StoryLineHandler(mailAutoresponderTelegram);
}
@Bean
public EventDistributor eventDistributor(
TelegramConnectBot telegramConnect,
List<EventHandler> eventProviders
) {
return new EventDistributorService(telegramConnect, eventProviders);
}
}

View File

@ -13,14 +13,14 @@ import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser;
import dev.struchkov.bot.gitlab.telegram.utils.UnitName;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.context.MailPayload;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramService;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import dev.struchkov.haiti.utils.Checker;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -53,14 +53,13 @@ import static java.util.Collections.singleton;
*/
@Component
@RequiredArgsConstructor
public class MenuConfig {
public class MenuConfig implements UnitConfiguration {
private final GitlabProperty gitlabProperty;
private final PersonInformation personInformation;
private final ProjectParser projectParser;
private final TelegramService telegramService;
private final ProjectService projectService;
private final NoteService noteService;
private final MergeRequestsService mergeRequestsService;

View File

@ -7,9 +7,10 @@ import dev.struchkov.bot.gitlab.context.service.DiscussionService;
import dev.struchkov.bot.gitlab.context.service.NoteService;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import dev.struchkov.haiti.utils.Checker;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -24,7 +25,7 @@ import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
@Component
@RequiredArgsConstructor
public class AnswerNoteUnit {
public class AnswerNoteUnit implements UnitConfiguration {
private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$");

View File

@ -4,10 +4,11 @@ import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -17,7 +18,7 @@ import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
@Component
@RequiredArgsConstructor
public class DeleteMessageUnit {
public class DeleteMessageUnit implements UnitConfiguration {
private final TelegramSending telegramSending;
private final PersonInformation personInformation;

View File

@ -6,11 +6,12 @@ import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment.Arg;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -29,7 +30,7 @@ import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.in
@Component
@RequiredArgsConstructor
public class DisableNotifyMrUnit {
public class DisableNotifyMrUnit implements UnitConfiguration {
public static final String WARNING_ABOUT_DISABLE_NOTIFY = Icons.DISABLE_NOTIFY + """
*Disabling notifications*

View File

@ -6,11 +6,12 @@ import dev.struchkov.bot.gitlab.context.service.DiscussionService;
import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment.Arg;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -29,7 +30,7 @@ import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.in
@Component
@RequiredArgsConstructor
public class DisableNotifyThreadUnit {
public class DisableNotifyThreadUnit implements UnitConfiguration {
public static final String WARNING_ABOUT_DISABLE_NOTIFY = Icons.DISABLE_NOTIFY + """
*Disabling notifications*

View File

@ -8,11 +8,12 @@ import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.bot.gitlab.telegram.utils.UnitName;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment.Arg;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -26,7 +27,7 @@ import static dev.struchkov.godfather.simple.domain.BoxAnswer.replaceBoxAnswer;
@Component
@RequiredArgsConstructor
public class EnableProjectNotify {
public class EnableProjectNotify implements UnitConfiguration {
private final ProjectService projectService;
private final MergeRequestsService mergeRequestsService;

View File

@ -13,12 +13,13 @@ import dev.struchkov.bot.gitlab.core.service.parser.PipelineParser;
import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser;
import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.starter.UnitConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -41,9 +42,9 @@ import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PARSER_OWNER
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PARSER_PRIVATE_PROJECT;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PRIVACY_SETTING;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_PRIVACY_SETTING_THREAD_LEVEL;
import static dev.struchkov.godfather.main.core.unit.UnitActiveType.AFTER;
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.main.domain.unit.UnitActiveType.AFTER;
import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.godfather.simple.domain.BoxAnswer.replaceBoxAnswer;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
@ -60,7 +61,7 @@ import static java.text.MessageFormat.format;
*/
@Component
@RequiredArgsConstructor
public class InitSettingFlow {
public class InitSettingFlow implements UnitConfiguration {
private final TelegramSending sending;