Skip to content

Commit a7309e1

Browse files
fix: Fix update command autocomplete.
1 parent 85418e8 commit a7309e1

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/main/java/net/modgarden/gardenbot/commands/event/UpdateHandler.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,19 @@ public static List<Command.Choice> getChoices(String focusedOption, User user,
109109
return submissionsJson.getAsJsonArray().asList().stream().map(submissionJson -> {
110110
try {
111111
if (submissionJson.isJsonObject()) {
112-
var modGardenStream = ModGardenAPIClient.get("project/" + submissionJson.getAsJsonObject().get("project_id").getAsString(), HttpResponse.BodyHandlers.ofInputStream());
113-
if (modGardenStream.statusCode() == 200) {
114-
try (InputStreamReader modGardenReader = new InputStreamReader(modGardenStream.body())) {
115-
ModGardenProject modGardenProject = GardenBot.GSON.fromJson(modGardenReader, ModGardenProject.class);
116-
117-
String slug = modGardenProject.slug;
118-
String title = slug;
119-
120-
var modrinthStream = ModrinthAPIClient.get("v2/project/" + modGardenProject.modrinthId, HttpResponse.BodyHandlers.ofInputStream());
121-
if (modrinthStream.statusCode() == 200) {
122-
try (InputStreamReader modrinthReader = new InputStreamReader(modrinthStream.body())) {
123-
ModrinthProject modrinthProject = GardenBot.GSON.fromJson(modrinthReader, ModrinthProject.class);
124-
title = modrinthProject.title;
125-
}
126-
}
127-
return new Command.Choice(title, slug);
112+
ModGardenProject modGardenProject = GardenBot.GSON.fromJson(submissionJson.getAsJsonObject().get("project"), ModGardenProject.class);
113+
114+
String slug = modGardenProject.slug;
115+
String title = slug;
116+
117+
var modrinthStream = ModrinthAPIClient.get("v2/project/" + modGardenProject.modrinthId, HttpResponse.BodyHandlers.ofInputStream());
118+
if (modrinthStream.statusCode() == 200) {
119+
try (InputStreamReader modrinthReader = new InputStreamReader(modrinthStream.body())) {
120+
ModrinthProject modrinthProject = GardenBot.GSON.fromJson(modrinthReader, ModrinthProject.class);
121+
title = modrinthProject.title;
128122
}
129123
}
124+
return new Command.Choice(title, slug);
130125
}
131126
} catch (Exception ex) {
132127
GardenBot.LOG.error("Failed to read Modrinth version.", ex);

0 commit comments

Comments
 (0)