55import org .jetbrains .annotations .NotNull ;
66import org .jetbrains .annotations .Nullable ;
77import 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 ;
810import org .telegram .telegrambots .meta .api .objects .message .Message ;
11+ import org .telegram .telegrambots .meta .api .objects .stickers .Sticker ;
912
1013public 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