From bbc9093769ac1366ae1a85bcd87943be9d38d9ef Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 27 Jan 2023 11:00:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=D0=B0,=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=BD=20=D1=83=D0=B6=D0=B5=20=D0=B1=D1=8B=D0=BB=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD,=20=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB=20=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D0=B2=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bot/gitlab/telegram/unit/MenuConfig.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java index c7b2e00..0ba133c 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java @@ -14,8 +14,9 @@ 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.data.StorylineContext; +import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment; import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard; +import dev.struchkov.godfather.telegram.main.core.util.Attachments; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.haiti.utils.Checker; import lombok.RequiredArgsConstructor; @@ -23,6 +24,7 @@ import org.springframework.stereotype.Component; import java.text.MessageFormat; import java.util.List; +import java.util.concurrent.ScheduledExecutorService; import java.util.stream.Collectors; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ACCESS_ERROR; @@ -33,10 +35,12 @@ import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GET_TASKS; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.SETTINGS; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_ADD_NEW_PROJECT; import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; +import static dev.struchkov.godfather.main.domain.BoxAnswer.replaceBoxAnswer; 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.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.clickButtonRaw; +import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.isLinks; /** * // TODO: 16.01.2021 Добавить описание. @@ -47,9 +51,7 @@ import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.cl @RequiredArgsConstructor public class MenuConfig { - private final StorylineContext context; private final TelegramSending sending; - private final ProjectParser projectParser; private final GitlabProperty gitlabProperty; private final PersonInformation personInformation; @@ -57,6 +59,8 @@ public class MenuConfig { private final MergeRequestsService mergeRequestsService; private final AppSettingService settingService; + private final ScheduledExecutorService scheduledExecutorService; + @Unit(value = ACCESS_ERROR, main = true) public AnswerText accessError() { return AnswerText.builder() @@ -115,7 +119,7 @@ public class MenuConfig { ) { return AnswerText.builder() .triggerCheck(clickButtonRaw(TEXT_ADD_NEW_PROJECT)) - .answer(boxAnswer("Copy the url of the project and send it to me")) + .answer(replaceBoxAnswer("Send me links to repositories you want to track")) .next(addNewProject) .build(); } @@ -123,13 +127,16 @@ public class MenuConfig { @Unit(ADD_NEW_PROJECT) public AnswerText addNewProject() { return AnswerText.builder() + .triggerCheck(isLinks()) .answer(mail -> { - final String mailText = mail.getText(); - final String projectUrl = gitlabProperty.getProjectAddUrl() + mailText.replace(gitlabProperty.getBaseUrl(), "") - .substring(1) - .replace("/", "%2F"); - projectParser.parseByUrl(projectUrl); - return boxAnswer("Project added successfully"); + final List links = Attachments.findAllLinks(mail.getAttachments()); + for (LinkAttachment link : links) { + final String projectUrl = gitlabProperty.getProjectAddUrl() + link.getUrl().replace(gitlabProperty.getBaseUrl(), "") + .substring(1) + .replace("/", "%2F"); + projectParser.parseByUrl(projectUrl); + } + return boxAnswer("\uD83D\uDC4D Projects added successfully!"); }) .build(); }