Discord bot project
All checks were successful
Publish Java SDK / docker (17, 3.8.5) (push) Successful in 34s

This commit is contained in:
Braydon 2024-04-24 16:05:39 -04:00
parent f9bd49c4bb
commit e6a12c3675
5 changed files with 203 additions and 2 deletions

28
DiscordBot/.gitignore vendored Normal file

@ -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

2
DiscordBot/README.md Normal file

@ -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)

121
DiscordBot/pom.xml Normal file

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--Project Details-->
<groupId>cc.restfulmc</groupId>
<artifactId>DiscordBot</artifactId>
<version>1.0.0</version>
<!-- Properties -->
<properties>
<java.version>8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- Used for compiling the source code with the proper Java version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<!-- Enable incremental builds, this is reversed due to -->
<!-- a bug as seen in https://issues.apache.org/jira/browse/MCOMPILER-209 -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<!-- Handles shading of dependencies in the final output jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Used for generating a git properties file during build -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<dotGitDirectory>$PROJECT.BASEDIR$/.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
<commitIdGenerationMode>full</commitIdGenerationMode>
<dateFormatTimeZone>$USER.TIMEZONE$</dateFormatTimeZone>
<dateFormat>MM-dd-yyyy@HH:mm:ss</dateFormat>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>^git.build.user.name$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
</plugins>
</build>
<!-- Repositories -->
<repositories>
<repository>
<id>rainnny-repo-public</id>
<url>https://maven.rainnny.club/public</url>
</repository>
</repositories>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-beta.23</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cc.restfulmc</groupId>
<artifactId>Java-SDK</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,8 @@
package cc.restfulmc.bot;
/**
* @author Braydon
*/
public final class DiscordBot {
public static void main(String[] args) { }
}

@ -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]);
}
}