From a5790235c6dfe58420d27a746147286d74da65bf Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 13 Dec 2022 22:08:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=8E=D0=BD=D0=B8=D1=82,=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=B8=D1=82?= =?UTF-8?q?,=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BA=D1=82=D0=BE-=D1=82=D0=BE,?= =?UTF-8?q?=20=D0=BA=D1=80=D0=BE=D0=BC=D0=B5=20=D0=B2=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D1=86=D0=B0,=20=D0=BF=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D1=83=D0=B5=D1=82=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=B1=D0=BE=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../service/MessageSendTelegramService.java | 5 +++- .../bot/gitlab/telegram/unit/UnitConfig.java | 24 ++++++++++++++++--- .../bot/gitlab/telegram/utils/UnitName.java | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 5446aa5..b441444 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ UTF-8 UTF-8 - 0.0.42 + 0.0.43 2.2 diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java index 8638a0d..b3c7761 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -3,6 +3,7 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.notify.Notify; import dev.struchkov.bot.gitlab.context.service.MessageSendService; +import dev.struchkov.godfather.main.domain.BoxAnswer; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -25,7 +26,9 @@ public class MessageSendTelegramService implements MessageSendService { @Override public void send(@NonNull Notify notify) { - sending.send(personInformation.getTelegramId(), boxAnswer(notify.generateMessage())); + final BoxAnswer boxAnswer = boxAnswer(notify.generateMessage()); + boxAnswer.setRecipientIfNull(personInformation.getTelegramId()); + sending.send(boxAnswer); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java index 875d5ea..a89b4be 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/UnitConfig.java @@ -6,8 +6,8 @@ import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.NoteService; import dev.struchkov.bot.gitlab.context.service.NotifyService; +import dev.struchkov.bot.gitlab.context.utils.Smile; import dev.struchkov.bot.gitlab.core.service.parser.ProjectParser; -import dev.struchkov.bot.gitlab.telegram.utils.UnitName; import dev.struchkov.godfather.main.core.unit.UnitActiveType; import dev.struchkov.godfather.main.domain.BoxAnswer; import dev.struchkov.godfather.main.domain.annotation.Unit; @@ -27,7 +27,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ACCESS_ERROR; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ANSWER_NOTE; +import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.AUTHORIZATION; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_FIRST_START; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_MENU_OR_ANSWER; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.CHECK_PARSER_PRIVATE_PROJECT; @@ -64,13 +66,29 @@ public class UnitConfig { private final ProjectParser projectParser; - @Unit(value = UnitName.AUTHORIZATION, main = true) + @Unit(value = AUTHORIZATION, main = true) public AnswerCheck auth( - @Unit(CHECK_FIRST_START) MainUnit checkFirstStart + @Unit(CHECK_FIRST_START) MainUnit checkFirstStart, + @Unit(ACCESS_ERROR) MainUnit accessError ) { return AnswerCheck.builder() .check(mail -> personInformation.getTelegramId().equals(mail.getPersonId())) .unitTrue(checkFirstStart) + .unitFalse(accessError) + .build(); + } + + @Unit(value = ACCESS_ERROR) + public AnswerText accessError() { + return AnswerText.builder() + .answer(message -> { + final String messageText = new StringBuilder("\uD83D\uDEA8 *Попытка несанкционированного доступа к боту*") + .append(Smile.HR.getValue()) + .append("\uD83E\uDDB9\u200D♂️: ").append(message.getPersonId()).append("\n") + .append("\uD83D\uDCAC: ").append(message.getText()) + .toString(); + return BoxAnswer.builder().recipientPersonId(personInformation.getTelegramId()).message(messageText).build(); + }) .build(); } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java index 4ee9588..797e1b8 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/utils/UnitName.java @@ -21,6 +21,7 @@ public final class UnitName { public static final String PARSE_OWNER_PROJECT = "parseOwnerProject"; public static final String END_SETTING = "endSetting"; public static final String AUTHORIZATION = "AUTHORIZATION"; + public static final String ACCESS_ERROR = "ACCESS_ERROR"; private UnitName() { utilityClass();