Skip to content

Commit cb01dce

Browse files
committed
Migrate to API 7.6
1 parent 0e17d85 commit cb01dce

File tree

7 files changed

+29
-32
lines changed

7 files changed

+29
-32
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repositories {
2121
}
2222

2323
dependencies {
24-
implementation 'com.annimon:tgbots-module:7.1.0'
24+
implementation 'com.annimon:tgbots-module:7.6.0'
2525
implementation 'org.slf4j:slf4j-simple:2.0.13'
2626
}
2727

src/main/java/com/annimon/ffmpegbot/MainBotHandler.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111
import com.annimon.ffmpegbot.file.TelegramFileDownloader;
1212
import com.annimon.ffmpegbot.session.Sessions;
1313
import com.annimon.tgbotsmodule.BotHandler;
14+
import com.annimon.tgbotsmodule.BotModuleOptions;
1415
import com.annimon.tgbotsmodule.commands.CommandRegistry;
1516
import com.annimon.tgbotsmodule.commands.authority.For;
1617
import org.jetbrains.annotations.NotNull;
17-
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
18+
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
1819
import org.telegram.telegrambots.meta.api.objects.Update;
1920
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
2021

2122
public class MainBotHandler extends BotHandler {
22-
private final BotConfig botConfig;
2323
private final Permissions permissions;
2424
private final CommandRegistry<For> commands;
2525
private final MediaProcessingBundle mediaProcessingBundle;
2626

2727
public MainBotHandler(BotConfig botConfig) {
28-
super(botConfig.botToken());
29-
this.botConfig = botConfig;
28+
super(BotModuleOptions.createDefault(botConfig.botToken()));
3029
permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers());
3130
commands = new CommandRegistry<>(botConfig.botUsername(), permissions);
3231
final var sessions = new Sessions();
@@ -57,11 +56,6 @@ protected BotApiMethod<?> onUpdate(@NotNull Update update) {
5756
return null;
5857
}
5958

60-
@Override
61-
public String getBotUsername() {
62-
return botConfig.botUsername();
63-
}
64-
6559
@Override
6660
public void handleTelegramApiException(TelegramApiException ex) {
6761
throw new TelegramRuntimeException(ex);

src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.annimon.tgbotsmodule.commands.context.CallbackQueryContext;
1818
import com.annimon.tgbotsmodule.services.CommonAbsSender;
1919
import org.jetbrains.annotations.NotNull;
20-
import org.telegram.telegrambots.meta.api.objects.Message;
20+
import org.telegram.telegrambots.meta.api.objects.message.Message;
2121

2222
import java.util.concurrent.CompletableFuture;
2323
import java.util.function.BiConsumer;

src/main/java/com/annimon/ffmpegbot/commands/ffmpeg/MediaProcessingKeyboard.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import com.annimon.ffmpegbot.session.YtDlpSession;
77
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
88
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
9+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow;
910

1011
import java.util.ArrayList;
1112
import java.util.Arrays;
12-
import java.util.List;
1313
import java.util.Objects;
1414
import java.util.stream.Collectors;
1515

@@ -18,6 +18,8 @@
1818
public class MediaProcessingKeyboard {
1919
private static final int BUTTON_COLUMNS = 2;
2020

21+
private MediaProcessingKeyboard() { }
22+
2123
public static InlineKeyboardMarkup createKeyboard(MediaSession session) {
2224
final var selectedParam = session.getSelectedParam();
2325
if (selectedParam != null) {
@@ -28,10 +30,10 @@ public static InlineKeyboardMarkup createKeyboard(MediaSession session) {
2830
}
2931

3032
private static InlineKeyboardMarkup createParamsListKeyboard(Parameters params) {
31-
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
33+
final var keyboard = new ArrayList<InlineKeyboardRow>();
3234
final var it = params.iterator();
3335
while (it.hasNext()) {
34-
final var row = new ArrayList<InlineKeyboardButton>();
36+
final var row = new InlineKeyboardRow();
3537
for (int i = 0; i < BUTTON_COLUMNS; i++) {
3638
if (it.hasNext()) {
3739
final var param = it.next();
@@ -41,18 +43,18 @@ private static InlineKeyboardMarkup createParamsListKeyboard(Parameters params)
4143
}
4244
keyboard.add(row);
4345
}
44-
keyboard.add(List.of(inlineKeyboardButton("Process", callbackData(PROCESS))));
46+
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Process", callbackData(PROCESS))));
4547
return new InlineKeyboardMarkup(keyboard);
4648
}
4749

4850
private static InlineKeyboardMarkup createParamKeyboard(Parameter<?> param) {
49-
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
51+
final var keyboard = new ArrayList<InlineKeyboardRow>();
5052
final String paramId = param.getId();
5153
final int maxSize = param.getPossibleValuesSize();
5254
int index = 0;
5355
final int columnsCount = param.defaultColumnsCount();
5456
while (index < maxSize) {
55-
final var row = new ArrayList<InlineKeyboardButton>();
57+
final var row = new InlineKeyboardRow();
5658
for (int i = 0; i < columnsCount; i++) {
5759
if (index < maxSize) {
5860
String value = param.describeValueByIndex(index);
@@ -62,22 +64,21 @@ private static InlineKeyboardMarkup createParamKeyboard(Parameter<?> param) {
6264
}
6365
keyboard.add(row);
6466
}
65-
keyboard.add(List.of(inlineKeyboardButton("Back", callbackData(PARAMETER))));
67+
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Back", callbackData(PARAMETER))));
6668
return new InlineKeyboardMarkup(keyboard);
6769
}
6870

6971
public static InlineKeyboardMarkup createKeyboard(YtDlpSession session) {
70-
final var keyboard = new ArrayList<List<InlineKeyboardButton>>();
72+
final var keyboard = new ArrayList<InlineKeyboardRow>();
7173
if (!session.hasAdditionalInfo()) {
72-
keyboard.add(List.of(inlineKeyboardButton("Get info", callbackData(YTDLP_INFO))));
74+
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Get info", callbackData(YTDLP_INFO))));
7375
}
74-
keyboard.add(List.of(inlineKeyboardButton("Start", callbackData(YTDLP_START))));
76+
keyboard.add(new InlineKeyboardRow(inlineKeyboardButton("Start", callbackData(YTDLP_START))));
7577
return new InlineKeyboardMarkup(keyboard);
7678
}
7779

7880
private static InlineKeyboardButton inlineKeyboardButton(String text, String callbackData) {
79-
final var button = new InlineKeyboardButton();
80-
button.setText(text);
81+
final var button = new InlineKeyboardButton(text);
8182
button.setCallbackData(callbackData);
8283
return button;
8384
}

src/main/java/com/annimon/ffmpegbot/file/TelegramFileDownloader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public File downloadFile(CommonAbsSender sender, String fileId, String defaultFi
1616
try {
1717
final var tgFile = Methods.getFile(fileId).call(sender);
1818
final var extension = FilenameUtils.getExtension(tgFile.getFilePath());
19-
return sender.downloadFile(tgFile, File.createTempFile("tmp", "file." + extension));
19+
File defaultFile = sender.downloadFile(tgFile);
20+
File dest = File.createTempFile("tmp", "file." + extension);
21+
return defaultFile.renameTo(dest) ? dest : defaultFile;
2022
} catch (IOException | TelegramApiException | TelegramRuntimeException e) {
2123
throw new FileDownloadException(e.getMessage(), e);
2224
}

src/main/java/com/annimon/ffmpegbot/parameters/Parameter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.util.List;
66
import java.util.Objects;
77

8-
import static com.google.common.base.Preconditions.checkArgument;
9-
108
public abstract class Parameter<T> {
119
protected final String id;
1210
protected final String displayName;
@@ -20,8 +18,10 @@ protected Parameter(String id, String displayName, List<? extends T> values, T v
2018
this.possibleValues = values;
2119
this.value = value;
2220
this.enabled = true;
23-
checkArgument(!values.isEmpty(), "possible values cannot be empty");
24-
checkArgument(values.contains(value), "possible values must contain a value");
21+
if (values.isEmpty())
22+
throw new IllegalArgumentException("Possible values cannot be empty");
23+
if (!values.contains(value))
24+
throw new IllegalArgumentException("Possible values " + values + " must contain " + value);
2525
}
2626

2727
public String getId() {

src/main/java/com/annimon/ffmpegbot/session/Resolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Nullable;
77
import org.telegram.telegrambots.meta.api.methods.ActionType;
8-
import org.telegram.telegrambots.meta.api.objects.Message;
8+
import org.telegram.telegrambots.meta.api.objects.message.Message;
99

1010
public class Resolver {
1111
public static @Nullable FileInfo resolveFileInfo(@NotNull Message message) {
@@ -65,9 +65,9 @@ public class Resolver {
6565

6666
public static ActionType resolveAction(@NotNull FileType fileType) {
6767
return switch (fileType) {
68-
case VIDEO -> ActionType.UPLOADVIDEO;
69-
case VIDEO_NOTE -> ActionType.UPLOADVIDEONOTE;
70-
case VOICE -> ActionType.UPLOADVOICE;
68+
case VIDEO -> ActionType.UPLOAD_VIDEO;
69+
case VIDEO_NOTE -> ActionType.UPLOAD_VIDEO_NOTE;
70+
case VOICE -> ActionType.UPLOAD_VOICE;
7171
default -> ActionType.TYPING;
7272
};
7373
}

0 commit comments

Comments
 (0)