This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Added in blacklist command #20
Open
darbyjack
wants to merge
3
commits into
MinecraftOSS:master
Choose a base branch
from
darbyjack:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/org/moss/discord/commands/BlacklistCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "✅"; | ||
} 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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unicode pls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done