Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Added in blacklist command #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
<scope>compile</scope>
</dependency>

<!-- JSON Dependency -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>


</dependencies>

<build>
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/moss/discord/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
import de.btobastian.sdcf4j.handler.JavacordHandler;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.moss.discord.commands.AvatarCommand;
import org.moss.discord.commands.BStatsCommand;
import org.moss.discord.commands.*;
import org.moss.discord.listeners.StarboardListener;
import org.moss.discord.commands.GithubCommand;
import org.moss.discord.commands.MojangCommand;
import org.moss.discord.commands.NicknameCommand;
import org.moss.discord.commands.PresenceCommand;
import org.moss.discord.commands.TagCommand;
import org.moss.discord.commands.SpigetCommand;
import org.moss.discord.commands.moderation.BanCommand;
import org.moss.discord.commands.moderation.KickCommand;
import org.moss.discord.commands.moderation.PruneCommand;
Expand Down Expand Up @@ -55,6 +48,7 @@ public static void main(String[] args) {
commandHandler.registerCommand(new NicknameCommand());
commandHandler.registerCommand(new AvatarCommand());
commandHandler.registerCommand(new SpigetCommand());
commandHandler.registerCommand(new BlacklistCommand());

// Register listeners
api.addListener(new ModLogListeners(api));
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/moss/discord/commands/BlacklistCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.moss.discord.commands;

import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.Objects;

public class BlacklistCommand implements CommandExecutor {

@Command(aliases = {"!blacklist"}, usage = "!blacklist <server IP>", description = "Checks if a server IP is blacklisted from Mojang")
public void onCommand(DiscordApi api, Message message, TextChannel channel, String[] args) {
if (args.length != 1) return;
EmbedBuilder builder = new EmbedBuilder();
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://use.gameapis.net/mc/extra/blockedservers/check/" + args[0]).build();
Response response = client.newCall(request).execute();
String jsonData = Objects.requireNonNull(response.body()).string();
JSONObject json = new JSONObject(jsonData);
response.close();
JSONArray array = json.getJSONArray(args[0]);
int length = array.length();
builder.setTitle(args[0] + " Blacklist Information");
for (int i = 0; i < length; i++) {
String emoji;
String check = String.valueOf(array.getJSONObject(i).getBoolean("blocked"));
if (check.equalsIgnoreCase("false")) {
emoji = "✅";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode pls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else {
emoji = "\uD83D\uDEAB";
}
builder.addField(array.getJSONObject(i).getString("domain"), "Status: " + emoji, true);
}
builder.setFooter("Requested by " + message.getAuthor().getDisplayName(), message.getAuthor().getAvatar());
channel.sendMessage(builder);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/org/moss/discord/commands/GithubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public EmbedBuilder makeInfoEmbed(DiscordApi api, String repository) {

embed.addInlineField("\uD83C\uDF1F Stars", String.format("```%s```", repo.get("stargazers_count").asText()));
embed.addInlineField("\u203C Issues", String.format("```%s```", repo.get("open_issues_count").asText()));
embed.addField("\uD83C\uDF74 Forks", String.format("```%s```", repo.get("forks").asText()));

StringBuilder issuenames = new StringBuilder();
for (int i = 0; i < 3; i++) {
Expand Down