From 7fe47cad13b90a0bb9c66c6306fd7f0614154e2a Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Thu, 19 Jan 2023 22:45:43 +0200 Subject: [PATCH] Send bot actions showing that job is running --- .../commands/ffmpeg/MediaProcessingBundle.java | 10 +++++++++- .../ffmpegbot/commands/ytdlp/YtDlpCommandBundle.java | 2 ++ .../java/com/annimon/ffmpegbot/session/Resolver.java | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingBundle.java b/src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingBundle.java index 56e6b2e..53fca9c 100644 --- a/src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingBundle.java +++ b/src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingBundle.java @@ -101,6 +101,7 @@ public class MediaProcessingBundle implements CommandBundle { private void process(final CallbackQueryContext ctx, final MediaSession session) { if (!session.isDownloaded()) { + sendAction(ctx, session); download(ctx, session); } if (!session.isDownloaded()) { @@ -108,6 +109,8 @@ public class MediaProcessingBundle implements CommandBundle { editMessage(ctx, session); return; } + + sendAction(ctx, session); CompletableFuture.runAsync(() -> new FFmpegTask().process(session)) .thenRunAsync(() -> { editMessage(ctx, session); @@ -134,13 +137,18 @@ public class MediaProcessingBundle implements CommandBundle { } } - private void editMessage(CallbackQueryContext ctx, MediaSession session) { + private static void editMessage(CallbackQueryContext ctx, MediaSession session) { ctx.editMessage(session.toString()) .enableHtml() .setReplyMarkup(createKeyboard(session)) .callAsync(ctx.sender); } + private static void sendAction(CallbackQueryContext ctx, MediaSession session) { + Methods.sendChatAction(session.getChatId(), Resolver.resolveAction(session.getFileType())) + .callAsync(ctx.sender); + } + private Consumer sessionCommand(BiConsumer consumer) { return ctx -> { final var msg = ctx.message(); diff --git a/src/main/java/com/annimon/ffmpegbot/commands/ytdlp/YtDlpCommandBundle.java b/src/main/java/com/annimon/ffmpegbot/commands/ytdlp/YtDlpCommandBundle.java index c8499a5..f85259b 100644 --- a/src/main/java/com/annimon/ffmpegbot/commands/ytdlp/YtDlpCommandBundle.java +++ b/src/main/java/com/annimon/ffmpegbot/commands/ytdlp/YtDlpCommandBundle.java @@ -2,6 +2,7 @@ package com.annimon.ffmpegbot.commands.ytdlp; import com.annimon.ffmpegbot.Permissions; import com.annimon.ffmpegbot.session.*; +import com.annimon.tgbotsmodule.api.methods.Methods; import com.annimon.tgbotsmodule.commands.CommandBundle; import com.annimon.tgbotsmodule.commands.CommandRegistry; import com.annimon.tgbotsmodule.commands.SimpleRegexCommand; @@ -34,6 +35,7 @@ public class YtDlpCommandBundle implements CommandBundle { final var filename = FilePath.generateFilename(url, Resolver.resolveDefaultFilename(fileType)); ytDlpSession.setOutputFilename(filename); + Methods.sendChatAction(ctx.chatId(), Resolver.resolveAction(fileType)).callAsync(ctx.sender); CompletableFuture.runAsync(() -> new YtDlpTask().process(ytDlpSession)) .thenRunAsync(() -> { final File outputFile = FilePath.outputFile(ytDlpSession.getOutputFilename()); diff --git a/src/main/java/com/annimon/ffmpegbot/session/Resolver.java b/src/main/java/com/annimon/ffmpegbot/session/Resolver.java index 791c8af..5ca3281 100644 --- a/src/main/java/com/annimon/ffmpegbot/session/Resolver.java +++ b/src/main/java/com/annimon/ffmpegbot/session/Resolver.java @@ -5,6 +5,7 @@ import com.annimon.ffmpegbot.parameters.Parameters; import com.annimon.tgbotsmodule.api.methods.Methods; import com.annimon.tgbotsmodule.api.methods.interfaces.MediaMessageMethod; import org.jetbrains.annotations.NotNull; +import org.telegram.telegrambots.meta.api.methods.ActionType; import org.telegram.telegrambots.meta.api.objects.Message; import java.util.List; @@ -57,4 +58,13 @@ public class Resolver { case VOICE -> Methods.sendVoice(); }; } + + public static ActionType resolveAction(FileType fileType) { + return switch (fileType) { + case VIDEO -> ActionType.UPLOADVIDEO; + case VIDEO_NOTE -> ActionType.UPLOADVIDEONOTE; + case VOICE -> ActionType.UPLOADVOICE; + default -> ActionType.TYPING; + }; + } }