mirror of
https://github.com/aNNiMON/ffmpegbot
synced 2024-09-19 22:54:20 +03:00
Send bot actions showing that job is running
This commit is contained in:
parent
8e952672d8
commit
7fe47cad13
@ -101,6 +101,7 @@ public class MediaProcessingBundle implements CommandBundle<For> {
|
||||
|
||||
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<For> {
|
||||
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<For> {
|
||||
}
|
||||
}
|
||||
|
||||
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<CallbackQueryContext> sessionCommand(BiConsumer<CallbackQueryContext, MediaSession> consumer) {
|
||||
return ctx -> {
|
||||
final var msg = ctx.message();
|
||||
|
@ -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<For> {
|
||||
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());
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user