From e6a12c36751c30c5fd629c73e7b3871e01077ecb Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 24 Apr 2024 16:05:39 -0400 Subject: [PATCH] Discord bot project --- DiscordBot/.gitignore | 28 ++++ DiscordBot/README.md | 2 + DiscordBot/pom.xml | 121 ++++++++++++++++++ .../java/cc/restfulmc/bot/DiscordBot.java | 8 ++ .../src/main/java/cc/restfulmc/sdk/Testy.java | 46 ++++++- 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 DiscordBot/.gitignore create mode 100644 DiscordBot/README.md create mode 100644 DiscordBot/pom.xml create mode 100644 DiscordBot/src/main/java/cc/restfulmc/bot/DiscordBot.java diff --git a/DiscordBot/.gitignore b/DiscordBot/.gitignore new file mode 100644 index 0000000..d1e6768 --- /dev/null +++ b/DiscordBot/.gitignore @@ -0,0 +1,28 @@ +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +replay_pid* +.idea +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +build/ +target/ +.idea_modules/ +atlassian-ide-plugin.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +git.properties +pom.xml.versionsBackup \ No newline at end of file diff --git a/DiscordBot/README.md b/DiscordBot/README.md new file mode 100644 index 0000000..13a6db2 --- /dev/null +++ b/DiscordBot/README.md @@ -0,0 +1,2 @@ +# RESTfulMC Discord Bot +This Discord bot allows you to interact with the API directly from Discord. Want to try it out? Join the [RESTfulMC Discord](https://discord.restfulmc.cc) \ No newline at end of file diff --git a/DiscordBot/pom.xml b/DiscordBot/pom.xml new file mode 100644 index 0000000..8e2ef60 --- /dev/null +++ b/DiscordBot/pom.xml @@ -0,0 +1,121 @@ + + + 4.0.0 + + + cc.restfulmc + DiscordBot + 1.0.0 + + + + 8 + ${java.version} + ${java.version} + UTF-8 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + ${java.version} + ${java.version} + + + + false + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.3 + + false + + + + package + + shade + + + + + + + + pl.project13.maven + git-commit-id-plugin + 4.9.10 + + + + revision + + + + + git + $PROJECT.BASEDIR$/.git + true + true + src/main/resources/git.properties + full + $USER.TIMEZONE$ + MM-dd-yyyy@HH:mm:ss + + ^git.branch$ + ^git.build.(time|version)$ + ^git.commit.id.(abbrev|full)$ + ^git.build.user.name$ + + + + + + + + + + rainnny-repo-public + https://maven.rainnny.club/public + + + + + + + org.projectlombok + lombok + 1.18.32 + provided + + + net.dv8tion + JDA + 5.0.0-beta.23 + + + club.minnced + opus-java + + + + + cc.restfulmc + Java-SDK + 1.0.0 + compile + + + \ No newline at end of file diff --git a/DiscordBot/src/main/java/cc/restfulmc/bot/DiscordBot.java b/DiscordBot/src/main/java/cc/restfulmc/bot/DiscordBot.java new file mode 100644 index 0000000..03b8c64 --- /dev/null +++ b/DiscordBot/src/main/java/cc/restfulmc/bot/DiscordBot.java @@ -0,0 +1,8 @@ +package cc.restfulmc.bot; + +/** + * @author Braydon + */ +public final class DiscordBot { + public static void main(String[] args) { } +} \ No newline at end of file diff --git a/Java-SDK/src/main/java/cc/restfulmc/sdk/Testy.java b/Java-SDK/src/main/java/cc/restfulmc/sdk/Testy.java index 56f2dfa..64dc646 100644 --- a/Java-SDK/src/main/java/cc/restfulmc/sdk/Testy.java +++ b/Java-SDK/src/main/java/cc/restfulmc/sdk/Testy.java @@ -25,7 +25,13 @@ package cc.restfulmc.sdk; import cc.restfulmc.sdk.client.ClientConfig; import cc.restfulmc.sdk.client.RESTfulMCClient; +import cc.restfulmc.sdk.command.impl.SyncClientCommands; +import cc.restfulmc.sdk.exception.RESTfulMCAPIException; +import cc.restfulmc.sdk.response.MojangServerStatus; import cc.restfulmc.sdk.response.Player; +import cc.restfulmc.sdk.response.server.BedrockMinecraftServer; +import cc.restfulmc.sdk.response.server.JavaMinecraftServer; +import cc.restfulmc.sdk.response.server.MinecraftServer; import lombok.SneakyThrows; /** @@ -35,7 +41,43 @@ public final class Testy { @SneakyThrows public static void main(String[] args) { RESTfulMCClient client = new RESTfulMCClient(ClientConfig.defaultConfig()); // Create the client - Player player = client.sync().getPlayer("Rainnny"); - System.out.println("player = " + player); + SyncClientCommands sync = client.sync(); // Get synchronous commands + + // Get a player + try { + Player player = sync.getPlayer("rAINnny"); + System.out.printf("%s's UUID is %s%n", player.getUsername(), player.getUniqueId()); + } catch (RESTfulMCAPIException ex) { + if (ex.getCode() == 400 || ex.getCode() == 404) { + System.out.println("Player not found!"); + } + } + + // Get a Java Minecraft server + try { + JavaMinecraftServer server = sync.getMinecraftServer(MinecraftServer.Platform.JAVA, "hypixel.net"); + MinecraftServer.Players players = server.getPlayers(); + System.out.printf("%s has %s/%s players online%n", server.getHostname(), players.getOnline(), players.getMax()); + } catch (RESTfulMCAPIException ex) { + if (ex.getCode() == 400 || ex.getCode() == 404) { + System.out.println("Server not found!"); + } + } + + // Get a Bedrock Minecraft server + try { + BedrockMinecraftServer server = sync.getMinecraftServer(MinecraftServer.Platform.BEDROCK, "wildprison.bedrock.minehut.gg"); + MinecraftServer.Players players = server.getPlayers(); + System.out.printf("%s has %s/%s players online%n", server.getHostname(), players.getOnline(), players.getMax()); + } catch (RESTfulMCAPIException ex) { + if (ex.getCode() == 400 || ex.getCode() == 404) { + System.out.println("Server not found!"); + } + } + + System.out.println("mojang blocked? = " + sync.isMojangBlocked("arkhamnetwork.org")); + + MojangServerStatus status = sync.getMojangStatus(); + System.out.println("status = " + status.getServers()[0]); } } \ No newline at end of file