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) {
|
private void process(final CallbackQueryContext ctx, final MediaSession session) {
|
||||||
if (!session.isDownloaded()) {
|
if (!session.isDownloaded()) {
|
||||||
|
sendAction(ctx, session);
|
||||||
download(ctx, session);
|
download(ctx, session);
|
||||||
}
|
}
|
||||||
if (!session.isDownloaded()) {
|
if (!session.isDownloaded()) {
|
||||||
@ -108,6 +109,8 @@ public class MediaProcessingBundle implements CommandBundle<For> {
|
|||||||
editMessage(ctx, session);
|
editMessage(ctx, session);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendAction(ctx, session);
|
||||||
CompletableFuture.runAsync(() -> new FFmpegTask().process(session))
|
CompletableFuture.runAsync(() -> new FFmpegTask().process(session))
|
||||||
.thenRunAsync(() -> {
|
.thenRunAsync(() -> {
|
||||||
editMessage(ctx, session);
|
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())
|
ctx.editMessage(session.toString())
|
||||||
.enableHtml()
|
.enableHtml()
|
||||||
.setReplyMarkup(createKeyboard(session))
|
.setReplyMarkup(createKeyboard(session))
|
||||||
.callAsync(ctx.sender);
|
.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) {
|
private Consumer<CallbackQueryContext> sessionCommand(BiConsumer<CallbackQueryContext, MediaSession> consumer) {
|
||||||
return ctx -> {
|
return ctx -> {
|
||||||
final var msg = ctx.message();
|
final var msg = ctx.message();
|
||||||
|
@ -2,6 +2,7 @@ package com.annimon.ffmpegbot.commands.ytdlp;
|
|||||||
|
|
||||||
import com.annimon.ffmpegbot.Permissions;
|
import com.annimon.ffmpegbot.Permissions;
|
||||||
import com.annimon.ffmpegbot.session.*;
|
import com.annimon.ffmpegbot.session.*;
|
||||||
|
import com.annimon.tgbotsmodule.api.methods.Methods;
|
||||||
import com.annimon.tgbotsmodule.commands.CommandBundle;
|
import com.annimon.tgbotsmodule.commands.CommandBundle;
|
||||||
import com.annimon.tgbotsmodule.commands.CommandRegistry;
|
import com.annimon.tgbotsmodule.commands.CommandRegistry;
|
||||||
import com.annimon.tgbotsmodule.commands.SimpleRegexCommand;
|
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));
|
final var filename = FilePath.generateFilename(url, Resolver.resolveDefaultFilename(fileType));
|
||||||
ytDlpSession.setOutputFilename(filename);
|
ytDlpSession.setOutputFilename(filename);
|
||||||
|
|
||||||
|
Methods.sendChatAction(ctx.chatId(), Resolver.resolveAction(fileType)).callAsync(ctx.sender);
|
||||||
CompletableFuture.runAsync(() -> new YtDlpTask().process(ytDlpSession))
|
CompletableFuture.runAsync(() -> new YtDlpTask().process(ytDlpSession))
|
||||||
.thenRunAsync(() -> {
|
.thenRunAsync(() -> {
|
||||||
final File outputFile = FilePath.outputFile(ytDlpSession.getOutputFilename());
|
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.Methods;
|
||||||
import com.annimon.tgbotsmodule.api.methods.interfaces.MediaMessageMethod;
|
import com.annimon.tgbotsmodule.api.methods.interfaces.MediaMessageMethod;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.ActionType;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -57,4 +58,13 @@ public class Resolver {
|
|||||||
case VOICE -> Methods.sendVoice();
|
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