7
7
import okhttp3 .Response ;
8
8
import okhttp3 .ResponseBody ;
9
9
import org .javacord .api .DiscordApi ;
10
+ import org .javacord .bot .Constants ;
11
+ import org .javacord .bot .util .LatestVersionFinder ;
10
12
11
13
import java .io .IOException ;
12
14
import java .util .HashSet ;
@@ -43,7 +45,7 @@ public JavadocParser(DiscordApi api, String url) {
43
45
* @return The latest JavaDoc link.
44
46
*/
45
47
public static CompletableFuture <String > getLatestJavaDocs (DiscordApi api ) {
46
- return getJavadocUrl (api , "https://docs.javacord.org/ api/ " );
48
+ return getJavadocUrl (api , "api" );
47
49
}
48
50
49
51
/**
@@ -53,21 +55,26 @@ public static CompletableFuture<String> getLatestJavaDocs(DiscordApi api) {
53
55
* @return The latest core JavaDoc link.
54
56
*/
55
57
public static CompletableFuture <String > getLatestCoreJavaDocs (DiscordApi api ) {
56
- return getJavadocUrl (api , "https://docs.javacord.org/ core/ " );
58
+ return getJavadocUrl (api , "core" );
57
59
}
58
60
59
- private static CompletableFuture <String > getJavadocUrl (DiscordApi api , String url ) {
61
+ private static CompletableFuture <String > getJavadocUrl (DiscordApi api , String type ) {
60
62
return CompletableFuture .supplyAsync (() -> {
61
63
try {
62
64
Request request = new Request .Builder ()
63
- .url (url )
65
+ .url (String . format ( Constants . JAVACORD_DOCS_URL_1 , type ) )
64
66
.build ();
65
67
66
68
try (Response response = client .newCall (request ).execute ()) {
67
69
return response .request ().url ().toString ();
68
70
}
69
71
} catch (Exception e ) {
70
- throw new CompletionException (e );
72
+ try {
73
+ return String .format (Constants .JAVACORD_DOCS_URL_2 , type , new LatestVersionFinder (api ).findLatestVersion ().join ());
74
+ } catch (Exception ignored ) {
75
+ //Just handle first exception, because it is more important.
76
+ throw new CompletionException (e );
77
+ }
71
78
}
72
79
}, api .getThreadPool ().getExecutorService ());
73
80
}
0 commit comments