use of net.kodehawa.mantarobot.commands.image.YandereImageData in project MantaroBot by Mantaro.
the class ImageCmds method getImage.
private static EmbedBuilder getImage(int argsCount, String requestType, String url, String rating, String[] messageArray, GuildMessageReceivedEvent event) {
EmbedBuilder builder = new EmbedBuilder();
if (!nsfwCheck(event, false, false))
return builder.setDescription("Cannot send a lewd image in a non-nsfw channel.");
String json = Utils.wget(url, event);
try {
YandereImageData[] imageData = GsonDataManager.GSON_PRETTY.fromJson(json, YandereImageData[].class);
List<YandereImageData> filter = new ArrayList<>(Arrays.asList(imageData)).stream().filter(data -> rating.equals(data.rating)).collect(Collectors.toList());
int get;
try {
get = requestType.equals("tags") ? argsCount >= 4 ? number : r.nextInt(filter.size()) : argsCount <= 2 ? Integer.parseInt(messageArray[2]) : r.nextInt(filter.size());
} catch (IndexOutOfBoundsException e) {
get = r.nextInt(filter.size());
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("bound must be positive"))
return builder.setDescription("No results found.");
else
return builder.setDescription("Query not valid.");
}
String AUTHOR = filter.get(get).getAuthor();
String tags = filter.get(get).getTags().stream().collect(Collectors.joining(", "));
if (!smallRequest) {
return builder.setAuthor("Found image", filter.get(get).getFile_url(), null).setDescription("Image uploaded by: " + (AUTHOR == null ? "not found" : AUTHOR) + ", with a rating of: **" + nRating.inverseBidiMap().get(filter.get(get).getRating()) + "**").setImage(filter.get(get).getFile_url()).addField("Height", String.valueOf(filter.get(get).getHeight()), true).addField("Width", String.valueOf(filter.get(get).getWidth()), true).addField("Tags", "``" + (tags == null ? "None" : tags) + "``", false).setFooter("If the image doesn't load, click the title.", null);
}
return builder.setAuthor("Found image", filter.get(get).getFile_url(), null).setDescription("Image uploaded by: " + (AUTHOR == null ? "not found" : AUTHOR) + ", with a rating of: **" + nRating.inverseBidiMap().get(filter.get(get).getRating()) + "**").setImage(filter.get(get).getFile_url()).addField("Width", String.valueOf(filter.get(get).getHeight()), true).addField("Height", String.valueOf(filter.get(get).getWidth()), true).addField("Tags", "``" + (tags == null ? "None" : tags) + "``", false).setFooter("If the image doesn't load, click the title.", null);
} catch (Exception ex) {
if (ex instanceof NullPointerException)
return builder.setDescription(EmoteReference.ERROR + "Wrong syntax.");
return builder.setDescription(EmoteReference.ERROR + "There are no images here, just dust.");
}
}
Aggregations