diff --git a/README.md b/README.md index afde59458..98d06d843 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Ree6 is an all-in-one Discord Bot maintained by Presti, which started as an alte # What can Ree6 do? As of right now Ree6 has the ability to play Music freely from YouTube, Spotify and Soundcloud. As well as the "default" moderation ability such as ban, kick etc., Ree6 also provides its own implementation of the Audit-Logger. -We also provide a **open-Source** Webinterface, Twitch and Twitter Notification, a Leveling System, a public Rest-API and more! +We also provide an **open-Source** Webinterface, Twitch and Twitter Notification, a Leveling System, a public Rest-API and more! # Discord Ree6 has its own support Discord that you can join to help us reach the Partner status on Discord and you to get help! @@ -23,7 +23,7 @@ Ree6 has its own support Discord that you can join to help us reach the Partner [![Discord](https://img.shields.io/discord/805149057004732457?logo=discord&style=for-the-badge)](https://support.ree6.de) # Disclaimer -Please be aware that Im a Student and can't work full-time on the Bot, and that I am paying for every costs that comes up to keep this Project alive! I'm thankful for every donation that I receive on [Ko-fi](https://ko-fi.com/presti). +Please be aware that I'm a Student and can't work full-time on the Bot, and that I am paying for every costs that comes up to keep this Project alive! I'm thankful for every donation that I receive on [Ko-fi](https://ko-fi.com/presti). # Support @@ -37,7 +37,6 @@ and YourKit YouMonitor. # Used APIs. - [JDA](https://github.com/DV8FromTheWorld/JDA) - [LavaPlayer](https://github.com/sedmelluq/lavaplayer) -- [Nekos4J](https://github.com/Nekos-life/Nekos4J) - [Spotify Web API](https://github.com/thelinmichael/spotify-web-api-java) - [Youtube Data API v3](https://github.com/googleapis/google-api-java-client-services/tree/master/clients/google-api-services-youtube/v3) - [Twitch4J](https://github.com/twitch4j/twitch4j) diff --git a/pom.xml b/pom.xml index dbb57940c..a2cd12cb5 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ de.presti Ree6 - 1.7.10 + 1.7.11 jar Ree6 Ree6 is an open-Source Discord Bot. @@ -128,7 +128,7 @@ com.google.oauth-client google-oauth-client-jetty - 1.33.2 + 1.33.3 com.google.apis @@ -277,7 +277,38 @@ + + + + maven-javadoc-plugin + false + + + aggregate + + aggregate-jar + + package + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + verify + + jar-no-fork + + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/src/main/java/de/presti/ree6/commands/impl/nsfw/NSFW.java b/src/main/java/de/presti/ree6/commands/impl/nsfw/NSFW.java index 53f8a16fd..7328c06e7 100644 --- a/src/main/java/de/presti/ree6/commands/impl/nsfw/NSFW.java +++ b/src/main/java/de/presti/ree6/commands/impl/nsfw/NSFW.java @@ -1,26 +1,84 @@ package de.presti.ree6.commands.impl.nsfw; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import de.presti.ree6.commands.*; import de.presti.ree6.commands.interfaces.Command; import de.presti.ree6.commands.interfaces.ICommand; import de.presti.ree6.main.Data; import de.presti.ree6.main.Main; import de.presti.ree6.utils.apis.Neko4JsAPI; +import de.presti.ree6.utils.external.RequestUtility; import de.presti.ree6.utils.others.RandomUtils; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.interactions.commands.build.CommandData; -@Command(name = "nsfw", description = "Get NSFW Image for nekos.life", category = Category.NSFW) -public class NSFW implements ICommand { +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; - String[] imageTags = new String[] { "Random_hentai_gif", "hentai"}; +@Command(name = "nsfw", description = "Get NSFW Image for reddit.com/r/hentai", category = Category.NSFW) +public class NSFW implements ICommand { @Override public void onPerform(CommandEvent commandEvent) { if (commandEvent.getTextChannel().isNSFW()) { - Neko4JsAPI.imageAPI.getImageProvider().getRandomImage(imageTags[RandomUtils.random.nextInt(imageTags.length)]).async(image -> Main.getInstance().getCommandManager().sendMessage(new EmbedBuilder() - .setImage(image.getUrl()) - .setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()), commandEvent.getTextChannel(), commandEvent.getInteractionHook())); + + Message message = commandEvent.isSlashCommand() ? + commandEvent.getInteractionHook().sendMessage("Searching for Image...").complete() : + commandEvent.getTextChannel().sendMessage("Searching for Image...").complete(); + + JsonElement jsonElement = RequestUtility.request(new RequestUtility.Request("https://www.reddit.com/r/hentai/new.json?sort=hot&limit=100")); + + if (jsonElement.isJsonObject() && + jsonElement.getAsJsonObject().has("data") && + jsonElement.getAsJsonObject().get("data").isJsonObject() && + jsonElement.getAsJsonObject().getAsJsonObject("data").has("children") && + jsonElement.getAsJsonObject().getAsJsonObject("data").get("children").isJsonArray()) { + + JsonArray children = jsonElement.getAsJsonObject().getAsJsonObject("data").getAsJsonArray("children"); + + List images = new ArrayList<>(); + + children.forEach(post -> { + if (post.isJsonObject() && post.getAsJsonObject().has("data") && + post.getAsJsonObject().getAsJsonObject("data").has("url") && + post.getAsJsonObject().getAsJsonObject("data").has("post_hint") && + post.getAsJsonObject().getAsJsonObject("data").get("url").isJsonPrimitive() && + post.getAsJsonObject().getAsJsonObject("data").get("post_hint").isJsonPrimitive() && + post.getAsJsonObject().getAsJsonObject("data").getAsJsonPrimitive("url").isString() && + post.getAsJsonObject().getAsJsonObject("data").getAsJsonPrimitive("post_hint").isString()) { + + JsonObject postObject = post.getAsJsonObject().getAsJsonObject("data"); + + String postHint = postObject.getAsJsonPrimitive("post_hint").getAsString(), + fileUrl = postObject.getAsJsonObject("url").getAsString(); + if ((postHint.equalsIgnoreCase("image") || + postHint.equalsIgnoreCase("link") || + postHint.equalsIgnoreCase("rich:video")) && + !fileUrl.toLowerCase(Locale.ROOT).startsWith("https://www.reddit.com/gallery/")) { + images.add(fileUrl); + } + } + }); + + if (!images.isEmpty()) { + String randomUrl = images.get(RandomUtils.secureRandom.nextInt(images.size() - 1)); + EmbedBuilder em = new EmbedBuilder(); + + em.setImage(randomUrl); + em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); + + message.editMessageEmbeds(em.build()).queue(); + } else { + message.editMessage("We received an empty Image list from Reddit? Please try again later!").delay(Duration.ofSeconds(5)).flatMap(Message::delete).queue(); + } + } else { + message.editMessage("We received an Invalid response from Reddit? Please try again later!").delay(Duration.ofSeconds(5)).flatMap(Message::delete).queue(); + } } else { Main.getInstance().getCommandManager().sendMessage("Only available in NSFW Channels!", 5, commandEvent.getTextChannel(), commandEvent.getInteractionHook()); } diff --git a/src/main/java/de/presti/ree6/main/Main.java b/src/main/java/de/presti/ree6/main/Main.java index 30bf04dc8..520202c5e 100644 --- a/src/main/java/de/presti/ree6/main/Main.java +++ b/src/main/java/de/presti/ree6/main/Main.java @@ -98,7 +98,7 @@ public static void main(String[] args) { // Create a RayGun Client to send Exception to an external Service for Bug fixing. Thread.setDefaultUncaughtExceptionHandler((t, e) -> { RaygunClient raygunClient = new RaygunClient(instance.config.getConfiguration().getString("raygun.apitoken")); - raygunClient.setVersion("1.7.9"); + raygunClient.setVersion("1.7.11"); }); // Create a new connection between the Application and the SQL-Server. @@ -132,7 +132,7 @@ public static void main(String[] args) { // Create a new Instance of the Bot, as well as add the Events. try { - BotWorker.createBot(BotVersion.PUBLIC, "1.7.10"); + BotWorker.createBot(BotVersion.PUBLIC, "1.7.11"); instance.musicWorker = new MusicWorker(); instance.addEvents(); } catch (Exception ex) { diff --git a/src/main/java/de/presti/ree6/utils/external/RequestUtility.java b/src/main/java/de/presti/ree6/utils/external/RequestUtility.java index 64bd4bede..183113505 100644 --- a/src/main/java/de/presti/ree6/utils/external/RequestUtility.java +++ b/src/main/java/de/presti/ree6/utils/external/RequestUtility.java @@ -21,6 +21,9 @@ public class RequestUtility { // HTTP Client used to send the Requests. private static final HttpClient CLIENT = HttpClient.newHttpClient(); + // User-Agent for all the Requests. + private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 Ree6/" + BotWorker.getBuild(); + /** * Send a Request. * @@ -31,7 +34,7 @@ public static JsonElement request(Request request) { HttpRequest.Builder httpRequestBuilder = HttpRequest.newBuilder() .uri(request.getUri()) - .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 Ree6/" + BotWorker.getBuild()) + .header("User-Agent", USER_AGENT) .header("Content-Type", "application/json-rpc"); if (request.bearerAuth != null) { diff --git a/src/main/java/de/presti/ree6/utils/others/RandomUtils.java b/src/main/java/de/presti/ree6/utils/others/RandomUtils.java index e24da7815..28c138dea 100644 --- a/src/main/java/de/presti/ree6/utils/others/RandomUtils.java +++ b/src/main/java/de/presti/ree6/utils/others/RandomUtils.java @@ -1,5 +1,6 @@ package de.presti.ree6.utils.others; +import java.security.SecureRandom; import java.util.Random; public final class RandomUtils { @@ -14,6 +15,8 @@ private RandomUtils() { public static final Random random = new Random(); + public static final SecureRandom secureRandom = new SecureRandom(); + public static int nextInt(int startInclusive, int endExclusive) { if (endExclusive - startInclusive <= 0) { return startInclusive;