Добавил Vertex для LongPolling
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e960c273a0
commit
6414f92904
@ -3,6 +3,7 @@ package dev.struchkov.godfather.telegram.quarkus.core;
|
|||||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
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.EventDistributor;
|
||||||
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
|
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||||
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||||
@ -16,20 +17,27 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
|
|||||||
*/
|
*/
|
||||||
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
|
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
|
||||||
|
|
||||||
|
private final Vertx vertx;
|
||||||
private final TelegramBotConfig telegramBotConfig;
|
private final TelegramBotConfig telegramBotConfig;
|
||||||
private EventDistributor eventDistributor;
|
private EventDistributor eventDistributor;
|
||||||
|
|
||||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
public TelegramPollingBot(Vertx vertx, TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
||||||
super(defaultBotOptions);
|
super(defaultBotOptions);
|
||||||
this.telegramBotConfig = telegramBotConfig;
|
this.telegramBotConfig = telegramBotConfig;
|
||||||
|
this.vertx = vertx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
|
public TelegramPollingBot(Vertx vertx, TelegramBotConfig telegramBotConfig) {
|
||||||
|
this.vertx = vertx;
|
||||||
this.telegramBotConfig = telegramBotConfig;
|
this.telegramBotConfig = telegramBotConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public void onUpdateReceived(Update update) {
|
||||||
|
vertx.runOnContext(v -> handleUpdate(update));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleUpdate(Update update) {
|
||||||
if (update != null && eventDistributor != null) {
|
if (update != null && eventDistributor != null) {
|
||||||
eventDistributor.processing(update)
|
eventDistributor.processing(update)
|
||||||
.subscribe().asCompletionStage();
|
.subscribe().asCompletionStage();
|
||||||
|
@ -5,6 +5,7 @@ import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
|
|||||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
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.EventDistributor;
|
||||||
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramConnect;
|
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramConnect;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||||
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||||
@ -22,11 +23,11 @@ public class TelegramPollingConnect implements TelegramConnect {
|
|||||||
|
|
||||||
private TelegramPollingBot pollingBot;
|
private TelegramPollingBot pollingBot;
|
||||||
|
|
||||||
public TelegramPollingConnect(TelegramBotConfig telegramBotConfig) {
|
public TelegramPollingConnect(Vertx vertx, TelegramBotConfig telegramBotConfig) {
|
||||||
initLongPolling(telegramBotConfig);
|
initLongPolling(vertx, telegramBotConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
|
private void initLongPolling(Vertx vertx, TelegramBotConfig telegramBotConfig) {
|
||||||
log.info("Initializing Telegram Long Polling...");
|
log.info("Initializing Telegram Long Polling...");
|
||||||
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
|
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
|
||||||
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
|
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
|
||||||
@ -59,14 +60,14 @@ public class TelegramPollingConnect implements TelegramConnect {
|
|||||||
|
|
||||||
log.info("Telegram proxy configuration set for bot");
|
log.info("Telegram proxy configuration set for bot");
|
||||||
|
|
||||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
|
final TelegramPollingBot bot = new TelegramPollingBot(vertx, telegramBotConfig, botOptions);
|
||||||
|
|
||||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
botapi.registerBot(bot);
|
botapi.registerBot(bot);
|
||||||
this.pollingBot = bot;
|
this.pollingBot = bot;
|
||||||
log.info("Telegram Bot registered with proxy settings");
|
log.info("Telegram Bot registered with proxy settings");
|
||||||
} else {
|
} else {
|
||||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
|
final TelegramPollingBot bot = new TelegramPollingBot(vertx, telegramBotConfig);
|
||||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
botapi.registerBot(bot);
|
botapi.registerBot(bot);
|
||||||
this.pollingBot = bot;
|
this.pollingBot = bot;
|
||||||
|
@ -4,14 +4,14 @@ import dev.struchkov.godfather.telegram.quarkus.context.repository.SenderReposit
|
|||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||||
|
|
||||||
public class SenderMapRepository implements SenderRepository {
|
public class SenderMapRepository implements SenderRepository {
|
||||||
|
|
||||||
private final Map<String, String> lastMessageId = new HashMap<>();
|
private final Map<String, String> lastMessageId = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uni<String> getLastSendMessage(String telegramId) {
|
public Uni<String> getLastSendMessage(String telegramId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user