Skip to content

Commit 88b4b9d

Browse files
committed
Fix sonar warnings
1 parent 83c17dd commit 88b4b9d

File tree

10 files changed

+48
-28
lines changed

10 files changed

+48
-28
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN apk add --no-cache py3-pip ffmpeg \
2020
&& python3 -m pip install --break-system-packages --no-cache-dir --upgrade \
2121
wheel yt-dlp pyrogram TgCrypto
2222
WORKDIR /app
23-
COPY --from=builder /usr/src/java-code/build/libs/effybot-1.2-SNAPSHOT-all.jar effybot.jar
23+
COPY --from=builder /usr/src/java-code/build/libs/effybot-1.3-SNAPSHOT-all.jar effybot.jar
2424
RUN mkdir input && mkdir output
2525
COPY pytgfile.py .
2626
COPY effybot-docker.yaml .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cp effybot.yaml.template effybot.yaml
3131
vim effybot.yaml
3232
mkdir {input,output}
3333
# Run
34-
java -jar ./build/libs/effybot-1.2-SNAPSHOT-all.jar
34+
java -jar ./build/libs/effybot-1.3-SNAPSHOT-all.jar
3535
```
3636

3737

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.annimon'
8-
version '1.2-SNAPSHOT'
8+
version '1.3-SNAPSHOT'
99

1010
java {
1111
sourceCompatibility = JavaVersion.VERSION_17

src/main/java/com/annimon/effybot/TextUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.StringJoiner;
55

66
public class TextUtils {
7+
private TextUtils() {}
8+
79
public static boolean isNotEmpty(String str) {
810
return (str != null) && (!str.isEmpty());
911
}

src/main/java/com/annimon/effybot/commands/admin/RunCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private String run(String command) {
7070

7171
private static List<String> toCommands(String command) {
7272
final var commands = new ArrayList<String>();
73-
final var m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(command);
73+
final var m = Pattern.compile("([^\"]\\S*|\"[^\"]++\")\\s*").matcher(command);
7474
while (m.find()) {
7575
commands.add(m.group(1));
7676
}

src/main/java/com/annimon/effybot/commands/ffmpeg/FFmpegCommandBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public void visit(OutputFormat p, MediaSession session) {
194194
additionalExtension = ".jpg";
195195
recipe = OutputFormat.AUDIO_SPECTRUM;
196196
}
197+
default -> throw new IllegalStateException("Not supported output format");
197198
}
198199

199200
if (localFilename.toLowerCase(Locale.ENGLISH).endsWith(additionalExtension)) {

src/main/java/com/annimon/effybot/commands/ffmpeg/InputParametersBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private void cutCommand(RegexMessageContext ctx, Session session) {
3737
switch (ctx.group(1)) {
3838
case "ss" -> inputParams.setStartPosition(arg);
3939
case "to" -> inputParams.setEndPosition(arg);
40-
case "t" -> inputParams.setDuration(arg);
40+
case "t", default -> inputParams.setDuration(arg);
4141
}
4242
editMessage(ctx, session);
4343
}

src/main/java/com/annimon/effybot/file/FilePath.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88

99
public class FilePath {
10+
private FilePath() {}
1011

1112
public static String inputDir() {
1213
return "input";
@@ -26,7 +27,7 @@ public static File outputFile(String filename) {
2627

2728
public static String generateFilename(String fileId, String filename) {
2829
final var ext = FilenameUtils.getExtension(filename);
29-
return "%d_%d.%s".formatted(System.currentTimeMillis(), Math.abs(fileId.hashCode()), ext);
30+
return "%d_%d.%s".formatted(System.currentTimeMillis(), fileId.hashCode() & 0x7FFFFFFF, ext);
3031
}
3132

3233
public static String defaultFilename(@NotNull FileType fileType) {

src/main/java/com/annimon/effybot/session/FileTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.annimon.effybot.session;
22

33
public class FileTypes {
4+
private FileTypes() {}
5+
46
public static boolean canContainAudio(FileType type) {
57
return switch (type) {
68
case AUDIO, VIDEO, VIDEO_NOTE, VOICE -> true;

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

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
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.Document;
9+
import org.telegram.telegrambots.meta.api.objects.VideoNote;
810
import org.telegram.telegrambots.meta.api.objects.message.Message;
11+
import org.telegram.telegrambots.meta.api.objects.stickers.Sticker;
912

1013
public class Resolver {
14+
private Resolver() {}
15+
1116
public static @Nullable FileInfo resolveFileInfo(@NotNull Message message) {
1217
if (message.hasAnimation()) {
1318
final var att = message.getAnimation();
@@ -21,38 +26,47 @@ public class Resolver {
2126
return new FileInfo(FileType.VIDEO, att.getFileId(), att.getFileName(),
2227
att.getFileSize(), att.getDuration(), att.getWidth(), att.getHeight());
2328
} else if (message.hasVideoNote()) {
24-
final var att = message.getVideoNote();
25-
final Long fileSize = att.getFileSize() != null ? (Long.valueOf(att.getFileSize())) : null;
26-
return new FileInfo(FileType.VIDEO_NOTE, att.getFileId(), null,
27-
fileSize, att.getDuration(), att.getLength(), att.getLength());
29+
return resolveVideoNote(message.getVideoNote());
2830
} else if (message.hasVoice()) {
2931
final var att = message.getVoice();
3032
return new FileInfo(FileType.VOICE, att.getFileId(), null, att.getFileSize(), att.getDuration());
3133
} else if (message.hasDocument()) {
32-
final var att = message.getDocument();
33-
final var mimeType = att.getMimeType();
34-
if (mimeType == null || att.getFileSize() == null || att.getFileSize() == 0) {
35-
return null;
36-
} else if (mimeType.startsWith("video/")) {
37-
return new FileInfo(FileType.VIDEO, att.getFileId(), att.getFileName(),
38-
att.getFileSize(), null);
39-
} else if (mimeType.startsWith("audio/")) {
40-
return new FileInfo(FileType.AUDIO, att.getFileId(), att.getFileName(),
41-
att.getFileSize(), null);
42-
}
43-
return null;
34+
return resolveDocument(message.getDocument());
4435
} else if (message.hasSticker()) {
45-
final var att = message.getSticker();
46-
if (att.getIsVideo()) {
47-
long fileSize = att.getFileSize() != null ? att.getFileSize().longValue() : 0L;
48-
return new FileInfo(FileType.ANIMATION, att.getFileId(), "sticker.webm", fileSize, null);
49-
}
50-
return null;
36+
return resolveSticker(message.getSticker());
5137
} else {
5238
return null;
5339
}
5440
}
5541

42+
private static @NotNull FileInfo resolveVideoNote(VideoNote att) {
43+
final Long fileSize = att.getFileSize() != null ? (Long.valueOf(att.getFileSize())) : null;
44+
return new FileInfo(FileType.VIDEO_NOTE, att.getFileId(), null,
45+
fileSize, att.getDuration(), att.getLength(), att.getLength());
46+
}
47+
48+
private static @Nullable FileInfo resolveDocument(@NotNull Document att) {
49+
final var mimeType = att.getMimeType();
50+
if (mimeType == null || att.getFileSize() == null || att.getFileSize() == 0) {
51+
return null;
52+
} else if (mimeType.startsWith("video/")) {
53+
return new FileInfo(FileType.VIDEO, att.getFileId(), att.getFileName(),
54+
att.getFileSize(), null);
55+
} else if (mimeType.startsWith("audio/")) {
56+
return new FileInfo(FileType.AUDIO, att.getFileId(), att.getFileName(),
57+
att.getFileSize(), null);
58+
}
59+
return null;
60+
}
61+
62+
private static @Nullable FileInfo resolveSticker(Sticker att) {
63+
if (Boolean.TRUE.equals(att.getIsVideo())) {
64+
long fileSize = att.getFileSize() != null ? att.getFileSize().longValue() : 0L;
65+
return new FileInfo(FileType.ANIMATION, att.getFileId(), "sticker.webm", fileSize, null);
66+
}
67+
return null;
68+
}
69+
5670
public static MediaMessageMethod<? extends MediaMessageMethod<?, ?>, ?> resolveMethod(@NotNull FileType fileType) {
5771
return switch (fileType) {
5872
case ANIMATION -> Methods.sendAnimation();

0 commit comments

Comments
 (0)