From 97122552e819a92b17d196d4eb0604b554ce0c21 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 25 Feb 2023 11:27:20 +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=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D1=80=D0=B8=D0=BA=D1=80=D0=B5=D0=BF=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=20=D0=BE=D1=82=D0=BA=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=BB=D1=8F=D1=82=D1=8C=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 0 .../context/service/TelegramService.java | 4 ++ .../context/service/TelegramService.java | 4 ++ .../core/service/TelegramServiceImpl.java | 45 +++++++++++++++++++ .../core/service/TelegramServiceImpl.java | 30 +++++++++++++ 5 files changed, 83 insertions(+) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/TelegramService.java b/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/TelegramService.java index 146e1d4..d2c39d5 100644 --- a/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/TelegramService.java +++ b/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/TelegramService.java @@ -8,4 +8,8 @@ public interface TelegramService { Uni executeAction(@NotNull String personId, ChatAction chatAction); + Uni pinMessage(@NotNull String personId, @NotNull String messageId); + + Uni unPinMessage(@NotNull String personId, @NotNull String messageId); + } diff --git a/telegram-context/telegram-context-simple/src/main/java/dev/struchkov/godfather/telegram/simple/context/service/TelegramService.java b/telegram-context/telegram-context-simple/src/main/java/dev/struchkov/godfather/telegram/simple/context/service/TelegramService.java index 2662823..cdc376c 100644 --- a/telegram-context/telegram-context-simple/src/main/java/dev/struchkov/godfather/telegram/simple/context/service/TelegramService.java +++ b/telegram-context/telegram-context-simple/src/main/java/dev/struchkov/godfather/telegram/simple/context/service/TelegramService.java @@ -7,4 +7,8 @@ public interface TelegramService { void executeAction(@NotNull String personId, ChatAction chatAction); + void pinMessage(@NotNull String personId, @NotNull String messageId); + + void unPinMessage(@NotNull String personId, @NotNull String messageId); + } diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/TelegramServiceImpl.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/TelegramServiceImpl.java index 99e21e8..701c2e0 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/TelegramServiceImpl.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/TelegramServiceImpl.java @@ -8,12 +8,15 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.ActionType; +import org.telegram.telegrambots.meta.api.methods.pinnedmessages.PinChatMessage; +import org.telegram.telegrambots.meta.api.methods.pinnedmessages.UnpinChatMessage; import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; public class TelegramServiceImpl implements TelegramService { @@ -35,6 +38,48 @@ public class TelegramServiceImpl implements TelegramService { .replaceWithVoid(); } + @Override + public Uni pinMessage(@NotNull String personId, @NotNull String messageId) { + final PinChatMessage pinChatMessage = new PinChatMessage(); + pinChatMessage.setChatId(personId); + pinChatMessage.setMessageId(Integer.parseInt(messageId)); + + return Uni.createFrom().completionStage(getExecuteAsync(pinChatMessage)) + .replaceWithVoid(); + } + + @Override + public Uni unPinMessage(@NotNull String personId, @NotNull String messageId) { + final UnpinChatMessage unpinChatMessage = new UnpinChatMessage(); + unpinChatMessage.setChatId(personId); + unpinChatMessage.setMessageId(Integer.parseInt(messageId)); + + return Uni.createFrom().completionStage(getExecuteAsync(unpinChatMessage)) + .replaceWithVoid(); + } + + private CompletableFuture getExecuteAsync(UnpinChatMessage unpinChatMessage) { + try { + return absSender.executeAsync(unpinChatMessage); + } catch (TelegramApiRequestException e) { + log.error(e.getApiResponse()); + } catch (TelegramApiException e) { + log.error(e.getMessage()); + } + return CompletableFuture.completedFuture(null); + } + + private CompletionStage getExecuteAsync(PinChatMessage pinChatMessage) { + try { + return absSender.executeAsync(pinChatMessage); + } catch (TelegramApiRequestException e) { + log.error(e.getApiResponse()); + } catch (TelegramApiException e) { + log.error(e.getMessage()); + } + return CompletableFuture.completedFuture(null); + } + private CompletableFuture getExecuteAsync(SendChatAction sendChatAction) { try { return absSender.executeAsync(sendChatAction); diff --git a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/service/TelegramServiceImpl.java b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/service/TelegramServiceImpl.java index d98c15d..a78c756 100644 --- a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/service/TelegramServiceImpl.java +++ b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/service/TelegramServiceImpl.java @@ -7,6 +7,8 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.ActionType; +import org.telegram.telegrambots.meta.api.methods.pinnedmessages.PinChatMessage; +import org.telegram.telegrambots.meta.api.methods.pinnedmessages.UnpinChatMessage; import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; @@ -36,4 +38,32 @@ public class TelegramServiceImpl implements TelegramService { } } + @Override + public void pinMessage(@NotNull String personId, @NotNull String messageId) { + final PinChatMessage pinChatMessage = new PinChatMessage(); + pinChatMessage.setChatId(personId); + pinChatMessage.setMessageId(Integer.parseInt(messageId)); + try { + absSender.execute(pinChatMessage); + } catch (TelegramApiRequestException e) { + log.error(e.getApiResponse()); + } catch (TelegramApiException e) { + log.error(e.getMessage()); + } + } + + @Override + public void unPinMessage(@NotNull String personId, @NotNull String messageId) { + final UnpinChatMessage unpinChatMessage = new UnpinChatMessage(); + unpinChatMessage.setChatId(personId); + unpinChatMessage.setMessageId(Integer.parseInt(messageId)); + try { + absSender.execute(unpinChatMessage); + } catch (TelegramApiRequestException e) { + log.error(e.getApiResponse()); + } catch (TelegramApiException e) { + log.error(e.getMessage()); + } + } + }