From 7fda16b63ce1211d2926c2c1d2be72e42bffbb04 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 13 Dec 2022 18:34:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D1=83=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D1=81=D0=B8=20=D0=B4=D0=BB=D1=8F=20telegram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- telegram-consumer/pom.xml | 2 +- .../telegram-consumer-main/pom.xml | 2 +- .../telegram-consumer-quarkus/pom.xml | 2 +- .../telegram-consumer-simple/pom.xml | 2 +- telegram-context/pom.xml | 2 +- .../telegram-context-main/pom.xml | 2 +- .../telegram-context-quarkus/pom.xml | 2 +- .../telegram-context-simple/pom.xml | 2 +- telegram-core/pom.xml | 2 +- telegram-core/telegram-core-main/pom.xml | 2 +- .../main/core/TelegramDefaultConnect.java | 59 +++++++++---------- telegram-core/telegram-core-quarkus/pom.xml | 2 +- .../quarkus/core/TelegramConnectBot.java | 21 +++---- telegram-core/telegram-core-simple/pom.xml | 2 +- .../simple/core/TelegramConnectBot.java | 22 +++---- telegram-domain/pom.xml | 2 +- .../telegram/domain/config/ProxyConfig.java | 10 ++++ telegram-sender/pom.xml | 2 +- telegram-sender/telegram-sender-main/pom.xml | 2 +- .../telegram-sender-quarkus/pom.xml | 2 +- .../telegram-sender-simple/pom.xml | 2 +- telegram-simple/pom.xml | 2 +- 23 files changed, 76 insertions(+), 74 deletions(-) diff --git a/pom.xml b/pom.xml index d1dc86a..24aa0d3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-bot - 0.0.41 + 0.0.42 pom diff --git a/telegram-consumer/pom.xml b/telegram-consumer/pom.xml index a4fad06..234f3ab 100644 --- a/telegram-consumer/pom.xml +++ b/telegram-consumer/pom.xml @@ -5,7 +5,7 @@ telegram-bot dev.struchkov.godfather.telegram - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-consumer/telegram-consumer-main/pom.xml b/telegram-consumer/telegram-consumer-main/pom.xml index b7ed8ac..f30b803 100644 --- a/telegram-consumer/telegram-consumer-main/pom.xml +++ b/telegram-consumer/telegram-consumer-main/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-consumer - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-consumer/telegram-consumer-quarkus/pom.xml b/telegram-consumer/telegram-consumer-quarkus/pom.xml index b7d8afb..0c4317f 100644 --- a/telegram-consumer/telegram-consumer-quarkus/pom.xml +++ b/telegram-consumer/telegram-consumer-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-consumer - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-consumer/telegram-consumer-simple/pom.xml b/telegram-consumer/telegram-consumer-simple/pom.xml index eeea610..42403fa 100644 --- a/telegram-consumer/telegram-consumer-simple/pom.xml +++ b/telegram-consumer/telegram-consumer-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-consumer - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-context/pom.xml b/telegram-context/pom.xml index 3535833..3ffa36a 100644 --- a/telegram-context/pom.xml +++ b/telegram-context/pom.xml @@ -5,7 +5,7 @@ telegram-bot dev.struchkov.godfather.telegram - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-context/telegram-context-main/pom.xml b/telegram-context/telegram-context-main/pom.xml index a3d3073..a429938 100644 --- a/telegram-context/telegram-context-main/pom.xml +++ b/telegram-context/telegram-context-main/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-context - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-context/telegram-context-quarkus/pom.xml b/telegram-context/telegram-context-quarkus/pom.xml index e9dc3f8..e9728cf 100644 --- a/telegram-context/telegram-context-quarkus/pom.xml +++ b/telegram-context/telegram-context-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-context - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-context/telegram-context-simple/pom.xml b/telegram-context/telegram-context-simple/pom.xml index ccc03ed..68d7105 100644 --- a/telegram-context/telegram-context-simple/pom.xml +++ b/telegram-context/telegram-context-simple/pom.xml @@ -5,7 +5,7 @@ telegram-context dev.struchkov.godfather.telegram - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-core/pom.xml b/telegram-core/pom.xml index 45e45b9..4f849b9 100644 --- a/telegram-core/pom.xml +++ b/telegram-core/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-bot - 0.0.41 + 0.0.42 telegram-core-main diff --git a/telegram-core/telegram-core-main/pom.xml b/telegram-core/telegram-core-main/pom.xml index 27faf66..6046194 100644 --- a/telegram-core/telegram-core-main/pom.xml +++ b/telegram-core/telegram-core-main/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-core - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/TelegramDefaultConnect.java b/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/TelegramDefaultConnect.java index 18abd17..c0edeb6 100644 --- a/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/TelegramDefaultConnect.java +++ b/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/TelegramDefaultConnect.java @@ -11,6 +11,8 @@ import org.telegram.telegrambots.meta.bots.AbsSender; import java.net.Authenticator; import java.net.PasswordAuthentication; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + public class TelegramDefaultConnect implements TelegramConnect { private final String botToken; @@ -26,28 +28,30 @@ public class TelegramDefaultConnect implements TelegramConnect { final DefaultBotOptions botOptions = new DefaultBotOptions(); final ProxyConfig proxyConfig = connectConfig.getProxyConfig(); - if (proxyConfig != null && proxyConfig.getPassword() != null) { - try { - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication( - proxyConfig.getUser(), - proxyConfig.getPassword().toCharArray() - ); - } - }); - } catch (Exception e) { - e.printStackTrace(); + if (checkNotNull(proxyConfig) && proxyConfig.isEnable()) { + if (checkNotNull(proxyConfig.getPassword())) { + try { + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication( + proxyConfig.getUser(), + proxyConfig.getPassword().toCharArray() + ); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } } - } - if (proxyConfig != null && proxyConfig.getHost() != null) { - System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); - System.setProperty("javax.net.debug", "all"); - botOptions.setProxyHost(proxyConfig.getHost()); - botOptions.setProxyPort(proxyConfig.getPort()); - botOptions.setProxyType(convertProxyType(proxyConfig.getType())); + if (checkNotNull(proxyConfig.getHost())) { + System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); + System.setProperty("javax.net.debug", "all"); + botOptions.setProxyHost(proxyConfig.getHost()); + botOptions.setProxyPort(proxyConfig.getPort()); + botOptions.setProxyType(convertProxyType(proxyConfig.getType())); + } } return new DefaultAbsSender(botOptions) { @@ -59,16 +63,11 @@ public class TelegramDefaultConnect implements TelegramConnect { } private DefaultBotOptions.ProxyType convertProxyType(ProxyConfig.Type type) { - switch (type) { - case SOCKS5: - return DefaultBotOptions.ProxyType.SOCKS5; - case SOCKS4: - return DefaultBotOptions.ProxyType.SOCKS4; - case HTTP: - return DefaultBotOptions.ProxyType.HTTP; - default: - return DefaultBotOptions.ProxyType.NO_PROXY; - } + return switch (type) { + case SOCKS5 -> DefaultBotOptions.ProxyType.SOCKS5; + case SOCKS4 -> DefaultBotOptions.ProxyType.SOCKS4; + case HTTP -> DefaultBotOptions.ProxyType.HTTP; + }; } @Override diff --git a/telegram-core/telegram-core-quarkus/pom.xml b/telegram-core/telegram-core-quarkus/pom.xml index ecab613..76ea4c5 100644 --- a/telegram-core/telegram-core-quarkus/pom.xml +++ b/telegram-core/telegram-core-quarkus/pom.xml @@ -5,7 +5,7 @@ telegram-core dev.struchkov.godfather.telegram - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramConnectBot.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramConnectBot.java index 3df7dbc..c692c93 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramConnectBot.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramConnectBot.java @@ -17,6 +17,8 @@ import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; import java.net.Authenticator; import java.net.PasswordAuthentication; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + /** * TODO: Добавить описание класса. * @@ -52,7 +54,7 @@ public class TelegramConnectBot implements TelegramConnect { private void initLongPolling(TelegramConnectConfig telegramConnectConfig) { final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig(); - if (proxyConfig != null && proxyConfig.getPassword() != null) { + if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { try { Authenticator.setDefault(new Authenticator() { @Override @@ -70,7 +72,7 @@ public class TelegramConnectBot implements TelegramConnect { final TelegramBotsApi botapi; try { - if (proxyConfig != null && proxyConfig.getHost() != null) { + if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getHost()) && !"".equals(proxyConfig.getHost())) { System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); System.setProperty("javax.net.debug", "all"); log.info(System.getProperty("https.protocols")); @@ -97,16 +99,11 @@ public class TelegramConnectBot implements TelegramConnect { } private DefaultBotOptions.ProxyType convertProxyType(Type type) { - switch (type) { - case SOCKS5: - return DefaultBotOptions.ProxyType.SOCKS5; - case SOCKS4: - return DefaultBotOptions.ProxyType.SOCKS4; - case HTTP: - return DefaultBotOptions.ProxyType.HTTP; - default: - return DefaultBotOptions.ProxyType.NO_PROXY; - } + return switch (type) { + case SOCKS5 -> DefaultBotOptions.ProxyType.SOCKS5; + case SOCKS4 -> DefaultBotOptions.ProxyType.SOCKS4; + case HTTP -> DefaultBotOptions.ProxyType.HTTP; + }; } public void initEventDistributor(EventDistributor eventDistributor) { diff --git a/telegram-core/telegram-core-simple/pom.xml b/telegram-core/telegram-core-simple/pom.xml index f5ac94f..8896c2c 100644 --- a/telegram-core/telegram-core-simple/pom.xml +++ b/telegram-core/telegram-core-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-core - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramConnectBot.java b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramConnectBot.java index e2dca5b..0bcfc10 100644 --- a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramConnectBot.java +++ b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramConnectBot.java @@ -17,6 +17,8 @@ import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; import java.net.Authenticator; import java.net.PasswordAuthentication; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; + /** * TODO: Добавить описание класса. * @@ -35,9 +37,8 @@ public class TelegramConnectBot implements TelegramConnect { } private void initLongPolling(TelegramConnectConfig telegramConnectConfig) { - final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig(); - if (proxyConfig != null && proxyConfig.getPassword() != null) { + if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { try { Authenticator.setDefault(new Authenticator() { @Override @@ -55,7 +56,7 @@ public class TelegramConnectBot implements TelegramConnect { final TelegramBotsApi botapi; try { - if (proxyConfig != null && proxyConfig.getHost() != null) { + if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getHost()) && !"".equals(proxyConfig.getHost())) { System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); System.setProperty("javax.net.debug", "all"); log.info(System.getProperty("https.protocols")); @@ -81,16 +82,11 @@ public class TelegramConnectBot implements TelegramConnect { } private DefaultBotOptions.ProxyType convertProxyType(Type type) { - switch (type) { - case SOCKS5: - return DefaultBotOptions.ProxyType.SOCKS5; - case SOCKS4: - return DefaultBotOptions.ProxyType.SOCKS4; - case HTTP: - return DefaultBotOptions.ProxyType.HTTP; - default: - return DefaultBotOptions.ProxyType.NO_PROXY; - } + return switch (type) { + case SOCKS5 -> DefaultBotOptions.ProxyType.SOCKS5; + case SOCKS4 -> DefaultBotOptions.ProxyType.SOCKS4; + case HTTP -> DefaultBotOptions.ProxyType.HTTP; + }; } public void initEventDistributor(EventDistributor eventDistributor) { diff --git a/telegram-domain/pom.xml b/telegram-domain/pom.xml index ede5e2f..b9b050f 100644 --- a/telegram-domain/pom.xml +++ b/telegram-domain/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-bot - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-domain/src/main/java/dev/struchkov/godfather/telegram/domain/config/ProxyConfig.java b/telegram-domain/src/main/java/dev/struchkov/godfather/telegram/domain/config/ProxyConfig.java index eb8c32d..d2c7d6a 100644 --- a/telegram-domain/src/main/java/dev/struchkov/godfather/telegram/domain/config/ProxyConfig.java +++ b/telegram-domain/src/main/java/dev/struchkov/godfather/telegram/domain/config/ProxyConfig.java @@ -7,6 +7,7 @@ package dev.struchkov.godfather.telegram.domain.config; */ public class ProxyConfig { + private boolean enable = true; private String host; private Integer port; private String user; @@ -53,7 +54,16 @@ public class ProxyConfig { this.type = type; } + public boolean isEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + public enum Type { SOCKS5, SOCKS4, HTTP } + } diff --git a/telegram-sender/pom.xml b/telegram-sender/pom.xml index 6a45e73..5afc1c8 100644 --- a/telegram-sender/pom.xml +++ b/telegram-sender/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-bot - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-sender/telegram-sender-main/pom.xml b/telegram-sender/telegram-sender-main/pom.xml index 16e6a5d..081365e 100644 --- a/telegram-sender/telegram-sender-main/pom.xml +++ b/telegram-sender/telegram-sender-main/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-sender - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-sender/telegram-sender-quarkus/pom.xml b/telegram-sender/telegram-sender-quarkus/pom.xml index 2fd6fc3..adde14e 100644 --- a/telegram-sender/telegram-sender-quarkus/pom.xml +++ b/telegram-sender/telegram-sender-quarkus/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-sender - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-sender/telegram-sender-simple/pom.xml b/telegram-sender/telegram-sender-simple/pom.xml index 3f75896..3d1d7df 100644 --- a/telegram-sender/telegram-sender-simple/pom.xml +++ b/telegram-sender/telegram-sender-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-sender - 0.0.41 + 0.0.42 4.0.0 diff --git a/telegram-simple/pom.xml b/telegram-simple/pom.xml index 59f7aa9..fadd244 100644 --- a/telegram-simple/pom.xml +++ b/telegram-simple/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather.telegram telegram-bot - 0.0.41 + 0.0.42 4.0.0