From f849c6d6203d4b8a485218f2cf9f615e2db7a251 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 29 Apr 2022 01:26:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +-- .../godfather/telegram/ProxyConfig.java | 52 ++++++++++---- .../godfather/telegram/TelegramBot.java | 4 +- .../telegram/TelegramPollingBot.java | 6 +- .../MessageAutoresponderTelegram.java | 4 +- .../config/TelegramPollingConfig.java | 37 ++++++---- .../config/TelegramWebHookConfig.java | 26 ------- .../telegram/convert/MessageMailConvert.java | 17 +++-- .../domain/keyboard/InlineKeyBoard.java | 36 ++++++++-- .../domain/keyboard/MarkupKeyBoard.java | 71 +++++++++++++++---- .../domain/keyboard/button/ButtonUrl.java | 20 ++++-- .../telegram/listen/EventDistributor.java | 4 +- .../telegram/listen/EventDistributorImpl.java | 4 +- .../telegram/listen/TelegramConnect.java | 6 +- .../telegram/listen/TelegramSender.java | 15 ++-- 15 files changed, 206 insertions(+), 104 deletions(-) delete mode 100644 telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramWebHookConfig.java diff --git a/pom.xml b/pom.xml index dad7316..949a25a 100644 --- a/pom.xml +++ b/pom.xml @@ -33,13 +33,13 @@ UTF-8 UTF-8 - 0.0.4-SNAPSHOT + 0.0.4 6.0.1 - 3.9.0 - 1.6.12 + 3.10.1 + 1.6.13 3.2.1 - 3.3.2 + 3.4.0 3.0.1 diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/ProxyConfig.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/ProxyConfig.java index 79307d6..07355eb 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/ProxyConfig.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/ProxyConfig.java @@ -1,21 +1,10 @@ package dev.struchkov.godfather.telegram; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - /** * TODO: Добавить описание класса. * * @author upagge [30.01.2020] */ -@Builder -@Setter -@Getter -@NoArgsConstructor -@AllArgsConstructor public class ProxyConfig { private String host; @@ -24,8 +13,47 @@ public class ProxyConfig { private String password; private Type type; + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + public enum Type { SOCKS5, SOCKS4, HTTP } - } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramBot.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramBot.java index 045397b..ae098f6 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramBot.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramBot.java @@ -1,7 +1,7 @@ package dev.struchkov.godfather.telegram; -import lombok.NonNull; import dev.struchkov.godfather.telegram.listen.EventDistributorImpl; +import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.meta.bots.AbsSender; /** @@ -13,6 +13,6 @@ public interface TelegramBot { AbsSender getAdsSender(); - void initEventDistributor(@NonNull EventDistributorImpl eventDistributor); + void initEventDistributor(@NotNull EventDistributorImpl eventDistributor); } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramPollingBot.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramPollingBot.java index 7b9c013..a4eb11b 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramPollingBot.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/TelegramPollingBot.java @@ -1,9 +1,9 @@ package dev.struchkov.godfather.telegram; -import lombok.NonNull; -import dev.struchkov.godfather.telegram.listen.EventDistributorImpl; import dev.struchkov.godfather.telegram.config.TelegramPollingConfig; import dev.struchkov.godfather.telegram.listen.EventDistributor; +import dev.struchkov.godfather.telegram.listen.EventDistributorImpl; +import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.objects.Update; @@ -53,7 +53,7 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr } @Override - public void initEventDistributor(@NonNull EventDistributorImpl eventDistributor) { + public void initEventDistributor(@NotNull EventDistributorImpl eventDistributor) { this.eventDistributor = eventDistributor; } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/autoresponder/MessageAutoresponderTelegram.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/autoresponder/MessageAutoresponderTelegram.java index e6dbaf7..545f39f 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/autoresponder/MessageAutoresponderTelegram.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/autoresponder/MessageAutoresponderTelegram.java @@ -1,11 +1,11 @@ package dev.struchkov.godfather.telegram.autoresponder; +import dev.struchkov.autoresponder.repository.UnitPointerRepository; import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.godfather.context.service.MessageService; import dev.struchkov.godfather.context.service.sender.Sending; import dev.struchkov.godfather.core.GeneralAutoResponder; import dev.struchkov.godfather.core.domain.unit.MainUnit; -import org.sadtech.autoresponder.repository.UnitPointerRepository; import java.util.Set; @@ -19,7 +19,7 @@ public class MessageAutoresponderTelegram extends GeneralAutoResponder { public MessageAutoresponderTelegram( Set menuUnit, Sending sending, MessageService messageService, - UnitPointerRepository unitPointerRepository + UnitPointerRepository unitPointerRepository ) { super(menuUnit, sending, messageService, unitPointerRepository); } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramPollingConfig.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramPollingConfig.java index 7855a75..7dda61f 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramPollingConfig.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramPollingConfig.java @@ -1,29 +1,38 @@ package dev.struchkov.godfather.telegram.config; import dev.struchkov.godfather.telegram.ProxyConfig; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; /** * TODO: Добавить описание класса. * * @author upagge [18.08.2019] */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor public class TelegramPollingConfig { - @NonNull - private String botUsername; + private final String botUsername; + private final String botToken; - @NonNull - private String botToken; + private ProxyConfig proxyConfig; - private ProxyConfig proxyConfig = new ProxyConfig(); + public TelegramPollingConfig(String botUsername, String botToken) { + this.botUsername = botUsername; + this.botToken = botToken; + } + + public String getBotUsername() { + return botUsername; + } + + public String getBotToken() { + return botToken; + } + + public ProxyConfig getProxyConfig() { + return proxyConfig; + } + + public void setProxyConfig(ProxyConfig proxyConfig) { + this.proxyConfig = proxyConfig; + } } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramWebHookConfig.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramWebHookConfig.java deleted file mode 100644 index d6bb3f7..0000000 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/config/TelegramWebHookConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.struchkov.godfather.telegram.config; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [12.02.2020] - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class TelegramWebHookConfig { - - @NonNull - private String botUsername; - - @NonNull - private String botToken; - -} diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/convert/MessageMailConvert.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/convert/MessageMailConvert.java index 0580d05..85b9f98 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/convert/MessageMailConvert.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/convert/MessageMailConvert.java @@ -3,8 +3,6 @@ package dev.struchkov.godfather.telegram.convert; import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.godfather.context.domain.content.attachment.Attachment; import dev.struchkov.godfather.context.domain.content.attachment.Link; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -15,23 +13,28 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; + /** * TODO: Добавить описание класса. * * @author upagge [18.08.2019] */ -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class MessageMailConvert { +public final class MessageMailConvert { + + public MessageMailConvert() { + utilityClass(); + } public static Mail apply(Message message) { - Mail mail = new Mail(); + final Mail mail = new Mail(); mail.setPersonId(message.getChatId()); mail.setAddDate(LocalDateTime.now()); mail.setText(message.getText()); mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), ZoneId.systemDefault())); mail.setFirstName(message.getChat().getFirstName()); mail.setLastName(message.getChat().getLastName()); - List entities = message.getEntities(); + final List entities = message.getEntities(); if (entities != null) { mail.setAttachments(convertAttachments(entities)); } @@ -44,7 +47,7 @@ public class MessageMailConvert { } private static List convertAttachments(List entities) { - final List attachments = new ArrayList(); + final List attachments = new ArrayList<>(); for (MessageEntity entity : entities) { String type = entity.getType(); if ("text_link".equals(type)) { diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/InlineKeyBoard.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/InlineKeyBoard.java index fb17b6b..24ed8bc 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/InlineKeyBoard.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/InlineKeyBoard.java @@ -2,22 +2,50 @@ package dev.struchkov.godfather.telegram.domain.keyboard; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard; -import lombok.Builder; -import lombok.Singular; +import java.util.ArrayList; import java.util.List; public class InlineKeyBoard extends SimpleKeyBoard { public static final String TYPE = "INLINE"; - @Builder - public InlineKeyBoard(@Singular("line") List lines) { + public InlineKeyBoard(List lines) { super(lines); } + private InlineKeyBoard(Builder builder) { + super(builder.lines); + } + + public static Builder builder() { + return new Builder(); + } + @Override public String getType() { return TYPE; } + + public static final class Builder { + private List lines = new ArrayList<>(); + + private Builder() { + } + + public Builder lines(List val) { + lines = val; + return this; + } + + public Builder line(KeyBoardLine val) { + lines.add(val); + return this; + } + + public InlineKeyBoard build() { + return new InlineKeyBoard(this); + } + } + } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/MarkupKeyBoard.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/MarkupKeyBoard.java index 5383829..bcd348d 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/MarkupKeyBoard.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/MarkupKeyBoard.java @@ -2,13 +2,10 @@ package dev.struchkov.godfather.telegram.domain.keyboard; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard; -import lombok.Builder; -import lombok.Getter; -import lombok.Singular; +import java.util.ArrayList; import java.util.List; -@Getter public class MarkupKeyBoard extends SimpleKeyBoard { public static final String TYPE = "MARKUP"; @@ -25,17 +22,23 @@ public class MarkupKeyBoard extends SimpleKeyBoard { private String inputFieldPlaceholder; - @Builder - protected MarkupKeyBoard( - @Singular(value = "line") List keyBoardLines, - boolean oneTime, - boolean resizeKeyboard, - String inputFieldPlaceholder - ) { - super(keyBoardLines); - this.oneTime = oneTime; - this.resizeKeyboard = resizeKeyboard; - this.inputFieldPlaceholder = inputFieldPlaceholder; + private MarkupKeyBoard(Builder builder) { + super(builder.lines); + oneTime = builder.oneTime; + resizeKeyboard = builder.resizeKeyboard; + inputFieldPlaceholder = builder.inputFieldPlaceholder; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public boolean isResizeKeyboard() { + return resizeKeyboard; + } + + public String getInputFieldPlaceholder() { + return inputFieldPlaceholder; } public boolean isOneTime() { @@ -47,4 +50,42 @@ public class MarkupKeyBoard extends SimpleKeyBoard { return TYPE; } + public static final class Builder { + private List lines = new ArrayList<>(); + private boolean oneTime = true; + private boolean resizeKeyboard; + private String inputFieldPlaceholder; + + private Builder() { + } + + public Builder lines(List val) { + lines = val; + return this; + } + + public Builder line(KeyBoardLine val) { + lines.add(val); + return this; + } + + public Builder oneTime(boolean val) { + oneTime = val; + return this; + } + + public Builder resizeKeyboard(boolean val) { + resizeKeyboard = val; + return this; + } + + public Builder inputFieldPlaceholder(String val) { + inputFieldPlaceholder = val; + return this; + } + + public MarkupKeyBoard build() { + return new MarkupKeyBoard(this); + } + } } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/button/ButtonUrl.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/button/ButtonUrl.java index cc7acc6..a6e501f 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/button/ButtonUrl.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/domain/keyboard/button/ButtonUrl.java @@ -1,11 +1,7 @@ package dev.struchkov.godfather.telegram.domain.keyboard.button; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; -import lombok.Builder; -import lombok.Getter; -@Getter -@Builder public class ButtonUrl implements KeyBoardButton { public static final String TYPE = "URL"; @@ -13,9 +9,25 @@ public class ButtonUrl implements KeyBoardButton { private String label; private String url; + public ButtonUrl(String label, String url) { + this.label = label; + this.url = url; + } + + public static ButtonUrl link(String label, String url) { + return new ButtonUrl(label, url); + } + @Override public String getType() { return TYPE; } + public String getLabel() { + return label; + } + + public String getUrl() { + return url; + } } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributor.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributor.java index c7589b9..40beaf3 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributor.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributor.java @@ -1,11 +1,11 @@ package dev.struchkov.godfather.telegram.listen; -import lombok.NonNull; +import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.meta.api.objects.Update; public interface EventDistributor { - void processing(@NonNull Update update); + void processing(@NotNull Update update); } diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributorImpl.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributorImpl.java index a0c925d..8fc2a1a 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributorImpl.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/EventDistributorImpl.java @@ -1,9 +1,9 @@ package dev.struchkov.godfather.telegram.listen; import dev.struchkov.godfather.context.service.MailService; -import lombok.NonNull; import dev.struchkov.godfather.telegram.convert.CallbackQueryConvert; import dev.struchkov.godfather.telegram.convert.MessageMailConvert; +import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Update; @@ -23,7 +23,7 @@ public class EventDistributorImpl implements EventDistributor { } @Override - public void processing(@NonNull Update update) { + public void processing(@NotNull Update update) { final Message message = update.getMessage(); final CallbackQuery callbackQuery = update.getCallbackQuery(); if (message != null) { diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramConnect.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramConnect.java index f73d826..c7a0f5b 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramConnect.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramConnect.java @@ -4,7 +4,8 @@ import dev.struchkov.godfather.telegram.ProxyConfig; import dev.struchkov.godfather.telegram.TelegramBot; import dev.struchkov.godfather.telegram.TelegramPollingBot; import dev.struchkov.godfather.telegram.config.TelegramPollingConfig; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.bots.AbsSender; @@ -19,9 +20,10 @@ import java.net.PasswordAuthentication; * * @author upagge [30.01.2020] */ -@Slf4j public class TelegramConnect { + private static final Logger log = LoggerFactory.getLogger(TelegramConnect.class); + private TelegramBot telegramBot; public TelegramConnect(TelegramPollingConfig telegramPollingConfig) { diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java index b986dec..d602d69 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java @@ -12,8 +12,8 @@ import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard; import dev.struchkov.godfather.telegram.domain.keyboard.MarkupKeyBoard; import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl; import dev.struchkov.godfather.telegram.service.SendPreProcessing; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText; import org.telegram.telegrambots.meta.api.objects.Message; @@ -36,18 +36,23 @@ import java.util.Map; * * @author upagge [15/07/2019] */ -@Slf4j public class TelegramSender implements Sending { + private static final Logger log = LoggerFactory.getLogger(TelegramSender.class); + private final AbsSender absSender; private Map map = new HashMap<>(); - @Setter + private SendPreProcessing sendPreProcessing; public TelegramSender(TelegramConnect telegramConnect) { this.absSender = telegramConnect.getAdsSender(); } + public void setSendPreProcessing(SendPreProcessing sendPreProcessing) { + this.sendPreProcessing = sendPreProcessing; + } + public void send(Long telegramId, BoxAnswer boxAnswer) { try { if (boxAnswer.isReplace() && map.containsKey(telegramId)) { @@ -90,7 +95,7 @@ public class TelegramSender implements Sending { return convertSimpleKeyBoard((SimpleKeyBoard) keyBoard); } } - throw new RuntimeException("Ошибка преобразования клавиаутры"); + return null; } private ReplyKeyboard convertSimpleKeyBoard(SimpleKeyBoard keyBoard) {