this.remarks=Arrays.asList("The URL should be a direct link to an image.","You can also upload an image as an attachment while calling this command instead of using a url.",
" * Specify the `-d` parameter to do a depth search!"," * It is useful for cropped images and edited images, but makes the search much longer,"," * and can sometimes result in a related image instead of the actual source.");
}
@Override
publicCommandResultexecute(TextChannelchannel,Userauthor,Messagemsg,String[]args){//allow people to not input url to check sauce of the most recent image like u/2dgt3d?
//check if image boards are found, if so return the first one found and discard similar results since imageboards are as standard as we can get
//it is possible but unlikely that we would be grabbing the wrong image's source in the lower sections even though there are good sources (that are not imageboards) at the top due to this
//gets second image coz usually the first one is just a sharper identical image
ElementsimThumb=yandex.select(osSimilar).get(1);
Stringsimilar="https:"+(osSimilar.contains(".CbirSimilar")?simThumb.attr("style").replaceAll(".*url\\((.*?)\\).*","$1"):simThumb.attr("src"));//use yandex's thumbnails since the actual source might be broken already
//use other sizes if found - second most accurate result (unless theres edits that uses the image in it (memes for example), so still retain similar results)
if(yandex.select(".CbirOtherSizes-Wrapper").size()>0){//merge the sort algorithms? //sorting with ratio seems to perform bad for most crops so dont sort anymore
try{//search iqdb first for the tags; results usually more organized and formatted
Elementiqdb=Jsoup.connect("https://iqdb.org/?url="+URLEncoder.encode(url,"UTF-8")+"&service[]=1&service[]=2&service[]=3&service[]=4&service[]=5&service[]=11&service[]=13").post().body();//services excluding eshuushuu since it has no tags and will fallback to saucenao anyways
//post instead of get due to the recent incident making iqdb and saucenao block imgur
if(iqdb.select(".err").size()>0&&iqdb.select(".err").html().contains("HTTP"))//iqdb errors, most likely broken link so dont fallback
try{//fallback to saucenao, usually pixiv source instead of image boards; also falls back if its anime scenes
Elementsaucenao=Jsoup.connect("https://saucenao.com/search.php").requestBody("url="+URLEncoder.encode(url,"UTF-8")).post().body();//same reason as iqdb post
//change line break tags to \n, and use first line as title
result.select("br").after("\\n");
String[]title=result.selectFirst(".resulttitle")==null?newString[]{"No title"}:result.selectFirst(".resulttitle").wholeText().replaceAll("\\\\n","\n").split("\n",2);//there can be no titles, like 4chan sources