mirror of
https://github.com/aNNiMON/ffmpegbot
synced 2024-09-19 22:54:20 +03:00
Migrate to API 7.6
This commit is contained in:
parent
0e17d85180
commit
cb01dce7ab
@ -21,7 +21,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.annimon:tgbots-module:7.1.0'
|
implementation 'com.annimon:tgbots-module:7.6.0'
|
||||||
implementation 'org.slf4j:slf4j-simple:2.0.13'
|
implementation 'org.slf4j:slf4j-simple:2.0.13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,22 +11,21 @@ import com.annimon.ffmpegbot.file.TelegramClientFileDownloader;
|
|||||||
import com.annimon.ffmpegbot.file.TelegramFileDownloader;
|
import com.annimon.ffmpegbot.file.TelegramFileDownloader;
|
||||||
import com.annimon.ffmpegbot.session.Sessions;
|
import com.annimon.ffmpegbot.session.Sessions;
|
||||||
import com.annimon.tgbotsmodule.BotHandler;
|
import com.annimon.tgbotsmodule.BotHandler;
|
||||||
|
import com.annimon.tgbotsmodule.BotModuleOptions;
|
||||||
import com.annimon.tgbotsmodule.commands.CommandRegistry;
|
import com.annimon.tgbotsmodule.commands.CommandRegistry;
|
||||||
import com.annimon.tgbotsmodule.commands.authority.For;
|
import com.annimon.tgbotsmodule.commands.authority.For;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
|
|
||||||
public class MainBotHandler extends BotHandler {
|
public class MainBotHandler extends BotHandler {
|
||||||
private final BotConfig botConfig;
|
|
||||||
private final Permissions permissions;
|
private final Permissions permissions;
|
||||||
private final CommandRegistry<For> commands;
|
private final CommandRegistry<For> commands;
|
||||||
private final MediaProcessingBundle mediaProcessingBundle;
|
private final MediaProcessingBundle mediaProcessingBundle;
|
||||||
|
|
||||||
public MainBotHandler(BotConfig botConfig) {
|
public MainBotHandler(BotConfig botConfig) {
|
||||||
super(botConfig.botToken());
|
super(BotModuleOptions.createDefault(botConfig.botToken()));
|
||||||
this.botConfig = botConfig;
|
|
||||||
permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers());
|
permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers());
|
||||||
commands = new CommandRegistry<>(botConfig.botUsername(), permissions);
|
commands = new CommandRegistry<>(botConfig.botUsername(), permissions);
|
||||||
final var sessions = new Sessions();
|
final var sessions = new Sessions();
|
||||||
@ -57,11 +56,6 @@ public class MainBotHandler extends BotHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBotUsername() {
|
|
||||||
return botConfig.botUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTelegramApiException(TelegramApiException ex) {
|
public void handleTelegramApiException(TelegramApiException ex) {
|
||||||
throw new TelegramRuntimeException(ex);
|
throw new TelegramRuntimeException(ex);
|
||||||
|
@ -17,7 +17,7 @@ import com.annimon.tgbotsmodule.commands.authority.For;
|
|||||||
import com.annimon.tgbotsmodule.commands.context.CallbackQueryContext;
|
import com.annimon.tgbotsmodule.commands.context.CallbackQueryContext;
|
||||||
import com.annimon.tgbotsmodule.services.CommonAbsSender;
|
import com.annimon.tgbotsmodule.services.CommonAbsSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.message.Message;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
@ -6,10 +6,10 @@ import com.annimon.ffmpegbot.session.MediaSession;
|
|||||||
import com.annimon.ffmpegbot.session.YtDlpSession;
|
import com.annimon.ffmpegbot.session.YtDlpSession;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -18,6 +18,8 @@ import static com.annimon.ffmpegbot.commands.ffmpeg.CallbackQueryCommands.*;
|
|||||||
public class MediaProcessingKeyboard {
|
public class MediaProcessingKeyboard {
|
||||||
private static final int BUTTON_COLUMNS = 2;
|
private static final int BUTTON_COLUMNS = 2;
|
||||||
|
|
||||||
|
private MediaProcessingKeyboard() { }
|
||||||
|
|
||||||
public static InlineKeyboardMarkup createKeyboard(MediaSession session) {
|
public static InlineKeyboardMarkup createKeyboard(MediaSession session) {
|
||||||
final var selectedParam = session.getSelectedParam();
|
final var selectedParam = session.getSelectedParam();
|
||||||
if (selectedParam != null) {
|
if (selectedParam != null) {
|
||||||
@ -28,10 +30,10 @@ public class MediaProcessingKeyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static InlineKeyboardMarkup createParamsListKeyboard(Parameters params) {
|
private static InlineKeyboardMarkup createParamsListKeyboard(Parameters params) {
|
||||||
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
|
final var keyboard = new ArrayList<InlineKeyboardRow>();
|
||||||
final var it = params.iterator();
|
final var it = params.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final var row = new ArrayList<InlineKeyboardButton>();
|
final var row = new InlineKeyboardRow();
|
||||||
for (int i = 0; i < BUTTON_COLUMNS; i++) {
|
for (int i = 0; i < BUTTON_COLUMNS; i++) {
|
||||||
if (it.hasNext()) {
|
if (it.hasNext()) {
|
||||||
final var param = it.next();
|
final var param = it.next();
|
||||||
@ -41,18 +43,18 @@ public class MediaProcessingKeyboard {
|
|||||||
}
|
}
|
||||||
keyboard.add(row);
|
keyboard.add(row);
|
||||||
}
|
}
|
||||||
keyboard.add(List.of(inlineKeyboardButton("Process", callbackData(PROCESS))));
|
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Process", callbackData(PROCESS))));
|
||||||
return new InlineKeyboardMarkup(keyboard);
|
return new InlineKeyboardMarkup(keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InlineKeyboardMarkup createParamKeyboard(Parameter<?> param) {
|
private static InlineKeyboardMarkup createParamKeyboard(Parameter<?> param) {
|
||||||
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
|
final var keyboard = new ArrayList<InlineKeyboardRow>();
|
||||||
final String paramId = param.getId();
|
final String paramId = param.getId();
|
||||||
final int maxSize = param.getPossibleValuesSize();
|
final int maxSize = param.getPossibleValuesSize();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
final int columnsCount = param.defaultColumnsCount();
|
final int columnsCount = param.defaultColumnsCount();
|
||||||
while (index < maxSize) {
|
while (index < maxSize) {
|
||||||
final var row = new ArrayList<InlineKeyboardButton>();
|
final var row = new InlineKeyboardRow();
|
||||||
for (int i = 0; i < columnsCount; i++) {
|
for (int i = 0; i < columnsCount; i++) {
|
||||||
if (index < maxSize) {
|
if (index < maxSize) {
|
||||||
String value = param.describeValueByIndex(index);
|
String value = param.describeValueByIndex(index);
|
||||||
@ -62,22 +64,21 @@ public class MediaProcessingKeyboard {
|
|||||||
}
|
}
|
||||||
keyboard.add(row);
|
keyboard.add(row);
|
||||||
}
|
}
|
||||||
keyboard.add(List.of(inlineKeyboardButton("Back", callbackData(PARAMETER))));
|
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Back", callbackData(PARAMETER))));
|
||||||
return new InlineKeyboardMarkup(keyboard);
|
return new InlineKeyboardMarkup(keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InlineKeyboardMarkup createKeyboard(YtDlpSession session) {
|
public static InlineKeyboardMarkup createKeyboard(YtDlpSession session) {
|
||||||
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
|
final var keyboard = new ArrayList<InlineKeyboardRow>();
|
||||||
if (!session.hasAdditionalInfo()) {
|
if (!session.hasAdditionalInfo()) {
|
||||||
keyboard.add(List.of(inlineKeyboardButton("Get info", callbackData(YTDLP_INFO))));
|
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Get info", callbackData(YTDLP_INFO))));
|
||||||
}
|
}
|
||||||
keyboard.add(List.of(inlineKeyboardButton("Start", callbackData(YTDLP_START))));
|
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Start", callbackData(YTDLP_START))));
|
||||||
return new InlineKeyboardMarkup(keyboard);
|
return new InlineKeyboardMarkup(keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InlineKeyboardButton inlineKeyboardButton(String text, String callbackData) {
|
private static InlineKeyboardButton inlineKeyboardButton(String text, String callbackData) {
|
||||||
final var button = new InlineKeyboardButton();
|
final var button = new InlineKeyboardButton(text);
|
||||||
button.setText(text);
|
|
||||||
button.setCallbackData(callbackData);
|
button.setCallbackData(callbackData);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ public class TelegramFileDownloader implements FileDownloader {
|
|||||||
try {
|
try {
|
||||||
final var tgFile = Methods.getFile(fileId).call(sender);
|
final var tgFile = Methods.getFile(fileId).call(sender);
|
||||||
final var extension = FilenameUtils.getExtension(tgFile.getFilePath());
|
final var extension = FilenameUtils.getExtension(tgFile.getFilePath());
|
||||||
return sender.downloadFile(tgFile, File.createTempFile("tmp", "file." + extension));
|
File defaultFile = sender.downloadFile(tgFile);
|
||||||
|
File dest = File.createTempFile("tmp", "file." + extension);
|
||||||
|
return defaultFile.renameTo(dest) ? dest : defaultFile;
|
||||||
} catch (IOException | TelegramApiException | TelegramRuntimeException e) {
|
} catch (IOException | TelegramApiException | TelegramRuntimeException e) {
|
||||||
throw new FileDownloadException(e.getMessage(), e);
|
throw new FileDownloadException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import com.annimon.ffmpegbot.commands.ffmpeg.Visitor;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
public abstract class Parameter<T> {
|
public abstract class Parameter<T> {
|
||||||
protected final String id;
|
protected final String id;
|
||||||
protected final String displayName;
|
protected final String displayName;
|
||||||
@ -20,8 +18,10 @@ public abstract class Parameter<T> {
|
|||||||
this.possibleValues = values;
|
this.possibleValues = values;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
checkArgument(!values.isEmpty(), "possible values cannot be empty");
|
if (values.isEmpty())
|
||||||
checkArgument(values.contains(value), "possible values must contain a value");
|
throw new IllegalArgumentException("Possible values cannot be empty");
|
||||||
|
if (!values.contains(value))
|
||||||
|
throw new IllegalArgumentException("Possible values " + values + " must contain " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -5,7 +5,7 @@ import com.annimon.tgbotsmodule.api.methods.interfaces.MediaMessageMethod;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.telegram.telegrambots.meta.api.methods.ActionType;
|
import org.telegram.telegrambots.meta.api.methods.ActionType;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.message.Message;
|
||||||
|
|
||||||
public class Resolver {
|
public class Resolver {
|
||||||
public static @Nullable FileInfo resolveFileInfo(@NotNull Message message) {
|
public static @Nullable FileInfo resolveFileInfo(@NotNull Message message) {
|
||||||
@ -65,9 +65,9 @@ public class Resolver {
|
|||||||
|
|
||||||
public static ActionType resolveAction(@NotNull FileType fileType) {
|
public static ActionType resolveAction(@NotNull FileType fileType) {
|
||||||
return switch (fileType) {
|
return switch (fileType) {
|
||||||
case VIDEO -> ActionType.UPLOADVIDEO;
|
case VIDEO -> ActionType.UPLOAD_VIDEO;
|
||||||
case VIDEO_NOTE -> ActionType.UPLOADVIDEONOTE;
|
case VIDEO_NOTE -> ActionType.UPLOAD_VIDEO_NOTE;
|
||||||
case VOICE -> ActionType.UPLOADVOICE;
|
case VOICE -> ActionType.UPLOAD_VOICE;
|
||||||
default -> ActionType.TYPING;
|
default -> ActionType.TYPING;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user