From a18dceb617f8fa56bec8c7b798aad0c9d3deb343 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 15 Apr 2023 12:57:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20ex?= =?UTF-8?q?ecutorservice=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20mutiny?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../telegram/quarkus/core/TelegramPollingBot.java | 12 ++++++++++++ .../telegram/quarkus/core/TelegramWebhookBot.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c12bd25..dfd70b7 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ UTF-8 UTF-8 - 0.0.58 + 0.0.59-SNAPSHOT 6.3.0 diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java index 3b329f7..6364996 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java @@ -3,13 +3,17 @@ package dev.struchkov.godfather.telegram.quarkus.core; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; +import io.smallrye.mutiny.infrastructure.Infrastructure; import io.vertx.core.Vertx; +import lombok.SneakyThrows; 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; import org.telegram.telegrambots.meta.bots.AbsSender; +import java.lang.reflect.Field; + /** * TODO: Добавить описание класса. * @@ -21,10 +25,18 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr private final TelegramBotConfig telegramBotConfig; private EventDistributor eventDistributor; + @SneakyThrows public TelegramPollingBot(Vertx vertx, TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) { super(defaultBotOptions); this.telegramBotConfig = telegramBotConfig; this.vertx = vertx; + final Field field = this.getClass().getSuperclass().getSuperclass().getDeclaredField("exe"); + // Делаем поле exe доступным для изменений + field.setAccessible(true); + // Заменяем поле exe в экземпляре наследника + field.set(this, Infrastructure.getDefaultExecutor()); + // Закрываем доступ к полю exe + field.setAccessible(false); } public TelegramPollingBot(Vertx vertx, TelegramBotConfig telegramBotConfig) { diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookBot.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookBot.java index 037f6fb..c48dbfa 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookBot.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramWebhookBot.java @@ -3,19 +3,31 @@ package dev.struchkov.godfather.telegram.quarkus.core; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; +import io.smallrye.mutiny.infrastructure.Infrastructure; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.bots.AbsSender; +import java.lang.reflect.Field; + @Slf4j public class TelegramWebhookBot extends org.telegram.telegrambots.bots.TelegramWebhookBot implements TelegramBot { private final TelegramBotConfig telegramBotConfig; private EventDistributor eventDistributor; + @SneakyThrows public TelegramWebhookBot(TelegramBotConfig telegramBotConfig) { this.telegramBotConfig = telegramBotConfig; + final Field field = this.getClass().getSuperclass().getSuperclass().getDeclaredField("exe"); + // Делаем поле exe доступным для изменений + field.setAccessible(true); + // Заменяем поле exe в экземпляре наследника + field.set(this, Infrastructure.getDefaultExecutor()); + // Закрываем доступ к полю exe + field.setAccessible(false); } @Override