Skip to content

Commit

Permalink
fix minecraft wiki command sometimes not showing summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Chew committed Feb 11, 2024
1 parent f88d953 commit 2126349
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.LoggerFactory;
import pw.chew.chewbotcca.util.RestClient;

import java.net.URLEncoder;
Expand Down Expand Up @@ -100,10 +99,12 @@ private MessageEmbed gatherData(String query) {
Document doc = Jsoup.parse(page);

// Get summary
String summar1 = doc.select("#mw-content-text > div.mw-parser-output > p:nth-child(3)").html();
String summar2 = doc.select("#mw-content-text > div.mw-parser-output > p:nth-child(4)").html();
Element summarySelection = doc.select("#mw-content-text > div.mw-parser-output > p").first();

String summary = summar1.isBlank() ? summar2 : summar1;
String summary = "";
if (summarySelection != null) {
summary = summarySelection.html();
}

String img = null;
Element infobox = doc.select("#mw-content-text > div.mw-parser-output > div.notaninfobox > div.infobox-imagearea.animated-container").first();
Expand All @@ -113,7 +114,6 @@ private MessageEmbed gatherData(String query) {
img = "https://minecraft.wiki" + imgEle.attr("src");
// Ensure img is a valid image

LoggerFactory.getLogger(this.getClass()).debug("image is " + img);
if (!EmbedBuilder.URL_PATTERN.matcher(img).matches()) {
img = null;
}
Expand Down

0 comments on commit 2126349

Please sign in to comment.