Skip to content

Commit

Permalink
* Typos got corrected.
Browse files Browse the repository at this point in the history
* Switched from NekosLife to Reddit on NSFW since NekosLife does not support NSFW anymore.
* Made the User-Agent a Static constant.
  • Loading branch information
DxsSucuk committed Jun 9, 2022
1 parent 8487bfc commit 0d7ee1a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 14 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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!

[![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

Expand All @@ -37,7 +37,6 @@ and <a href="https://www.yourkit.com/youmonitor/">YourKit YouMonitor</a>.
# 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)
Expand Down
35 changes: 33 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>de.presti</groupId>
<artifactId>Ree6</artifactId>
<version>1.7.10</version>
<version>1.7.11</version>
<packaging>jar</packaging>
<name>Ree6</name>
<description>Ree6 is an open-Source Discord Bot.</description>
Expand Down Expand Up @@ -128,7 +128,7 @@
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.33.2</version>
<version>1.33.3</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
Expand Down Expand Up @@ -277,7 +277,38 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate-jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
70 changes: 64 additions & 6 deletions src/main/java/de/presti/ree6/commands/impl/nsfw/NSFW.java
Original file line number Diff line number Diff line change
@@ -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<String> 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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/presti/ree6/utils/others/RandomUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.presti.ree6.utils.others;

import java.security.SecureRandom;
import java.util.Random;

public final class RandomUtils {
Expand All @@ -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;
Expand Down

0 comments on commit 0d7ee1a

Please sign in to comment.