From ee2024d37fe4bb2ab5e3f38cf79a33bfbb185f57 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Thu, 30 Mar 2023 22:32:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D1=8E=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quarkus/core/TelegramPollingConnect.java | 16 +++---- .../quarkus/core/TelegramWebhookConnect.java | 1 + .../simple/core/TelegramPollingConnect.java | 46 +++++++++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingConnect.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingConnect.java index 75853c6..00e40ae 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingConnect.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingConnect.java @@ -17,11 +17,6 @@ import java.net.PasswordAuthentication; import static dev.struchkov.haiti.utils.Checker.checkNotNull; -/** - * TODO: Добавить описание класса. - * - * @author upagge [30.01.2020] - */ @Slf4j public class TelegramPollingConnect implements TelegramConnect { @@ -32,6 +27,7 @@ public class TelegramPollingConnect implements TelegramConnect { } private void initLongPolling(TelegramBotConfig telegramBotConfig) { + log.info("Initializing Telegram Long Polling..."); final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig(); if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { try { @@ -45,8 +41,9 @@ public class TelegramPollingConnect implements TelegramConnect { } }); } catch (Exception e) { - e.printStackTrace(); + log.error("Error setting default authenticator for telegram proxy", e); } + log.info("Telegram proxy with authentication enabled"); } final TelegramBotsApi botapi; @@ -54,26 +51,29 @@ public class TelegramPollingConnect implements TelegramConnect { 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")); +// log.info(System.getProperty("https.protocols")); DefaultBotOptions botOptions = new DefaultBotOptions(); botOptions.setProxyHost(proxyConfig.getHost()); botOptions.setProxyPort(proxyConfig.getPort()); botOptions.setProxyType(convertProxyType(proxyConfig.getType())); + log.info("Telegram proxy configuration set for bot"); final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions); botapi = new TelegramBotsApi(DefaultBotSession.class); botapi.registerBot(bot); this.pollingBot = bot; + log.info("Telegram Bot registered with proxy settings"); } else { final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig); botapi = new TelegramBotsApi(DefaultBotSession.class); botapi.registerBot(bot); this.pollingBot = bot; + log.info("Telegram Bot registered without proxy settings"); } } catch (TelegramApiException e) { - log.error(e.getMessage()); + log.error("Error registering telegram bot", e); } } diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookConnect.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookConnect.java index 9d96ccf..65b1e8b 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookConnect.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookConnect.java @@ -15,6 +15,7 @@ public class TelegramWebhookConnect implements TelegramConnect { private TelegramWebhookBot webhookBot; public TelegramWebhookConnect(TelegramBotConfig telegramBotConfig) { + log.info("Initializing Webhook Polling..."); try { final TelegramWebhookBot bot = new TelegramWebhookBot(telegramBotConfig); final WebhookConfig webhookConfig = telegramBotConfig.getWebhookConfig(); diff --git a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingConnect.java b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingConnect.java index 9a01ba4..3814773 100644 --- a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingConnect.java +++ b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/TelegramPollingConnect.java @@ -4,10 +4,8 @@ import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor; -import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot; import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.bots.AbsSender; @@ -19,26 +17,19 @@ import java.net.PasswordAuthentication; import static dev.struchkov.haiti.utils.Checker.checkNotNull; -/** - * TODO: Добавить описание класса. - * - * @author upagge [30.01.2020] - */ +@Slf4j public class TelegramPollingConnect implements TelegramConnect { - private static final Logger log = LoggerFactory.getLogger(TelegramPollingConnect.class); - - private TelegramBot telegramBot; - private final TelegramBotConfig telegramBotConfig; + private TelegramPollingBot pollingBot; public TelegramPollingConnect(TelegramBotConfig telegramBotConfig) { - this.telegramBotConfig = telegramBotConfig; initLongPolling(telegramBotConfig); } private void initLongPolling(TelegramBotConfig telegramBotConfig) { + log.info("Initializing Telegram Long Polling..."); final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig(); - if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { + if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { try { Authenticator.setDefault(new Authenticator() { @Override @@ -50,8 +41,9 @@ public class TelegramPollingConnect implements TelegramConnect { } }); } catch (Exception e) { - e.printStackTrace(); + log.error("Error setting default authenticator for telegram proxy", e); } + log.info("Telegram proxy with authentication enabled"); } final TelegramBotsApi botapi; @@ -59,25 +51,29 @@ public class TelegramPollingConnect implements TelegramConnect { 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")); +// log.info(System.getProperty("https.protocols")); DefaultBotOptions botOptions = new DefaultBotOptions(); botOptions.setProxyHost(proxyConfig.getHost()); botOptions.setProxyPort(proxyConfig.getPort()); botOptions.setProxyType(convertProxyType(proxyConfig.getType())); + log.info("Telegram proxy configuration set for bot"); + final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions); botapi = new TelegramBotsApi(DefaultBotSession.class); botapi.registerBot(bot); - this.telegramBot = bot; + this.pollingBot = bot; + log.info("Telegram Bot registered with proxy settings"); } else { final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig); botapi = new TelegramBotsApi(DefaultBotSession.class); botapi.registerBot(bot); - this.telegramBot = bot; + this.pollingBot = bot; + log.info("Telegram Bot registered without proxy settings"); } } catch (TelegramApiException e) { - log.error(e.getMessage()); + log.error("Error registering telegram bot", e); } } @@ -89,17 +85,19 @@ public class TelegramPollingConnect implements TelegramConnect { }; } - public void initEventDistributor(EventDistributor eventDistributor) { - telegramBot.initEventDistributor(eventDistributor); + @Override + public String getToken() { + return pollingBot.getBotToken(); } - public String getToken() { - return telegramBotConfig.getToken(); + @Override + public void initEventDistributor(EventDistributor eventDistributorService) { + pollingBot.initEventDistributor(eventDistributorService); } @Override public AbsSender getAbsSender() { - return telegramBot.getAdsSender(); + return pollingBot.getAdsSender(); } }