if(args.length<1)returnnewCommandResult(CommandResultType.FAILURE,"Please enter something to search for!");
JSONObjectmain,props;
try{
//get required cookies
//Mozilla/4.0 actually bypasses the need for CSRF, but breaks /api/search/all since it requires X-Requested-With (/browse?name= still works but doesn't handle multiple types at once)
Stringres=Jsoup.connect("https://mywaifulist.moe/api/search/all")//advancedsearch is no longer a thing
.userAgent("Mozilla/5.0")
.header("X-Requested-With","XMLHttpRequest")
.header("X-XSRF-TOKEN",URLDecoder.decode(con.cookie("XSRF-TOKEN"),"UTF-8"))//base64 might be encoded - if it is, then laravel will return 419 page expired
.header("Content-Type","application/json")//needed or the endpoint can't parse the query json
.header("Referer","https://mywaifulist.moe/")//needed to avoid internal server error for some reason
arr=arr.stream().filter(o->!o.isNull("entity_type")&&(o.getString("entity_type").equalsIgnoreCase("waifu")||o.getString("entity_type").equalsIgnoreCase("husbando")))//filter only characters
.sorted((a,b)->Integer.compare(//combine likes and trash to get popularity - sort by popularity since the search result sucks ass
.sorted((a,b)->wholeWord.matcher(a.getString("name")).matches()&&!wholeWord.matcher(b.getString("name")).matches()?-1:0)//move whole word matches up only if last one was not matched
em.setTitle((main.getBoolean("husbando")?"Husbando":"Waifu")+" info of "+main.getString("name"),"https://mywaifulist.moe/waifu/"+main.getString("slug"));
+(!jobj.isNull("description")?(" \""+jobj.getString("description").substring(0,Math.min(jobj.getString("description").length(),avg)).replaceAll("\"","”"))//trim desc to max length, replacing double quotes since it will interfere with markdown
+(jobj.getString("description").length()>avg?"...":"")+"\")":")"))//append ... if its not finished (only if desc is non null will desc be printed)
em.setFooter("Created at "+DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId.of("Z")).format(Instant.parse(main.getString("created_at")))+" | MyWaifuList.moe",null);