initial commit
This commit is contained in:
64
disMCbot.java
Normal file
64
disMCbot.java
Normal file
@@ -0,0 +1,64 @@
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
public class disMCbot extends ListenerAdapter {
|
||||
|
||||
private TextChannel updateChannel; // Define the channel where updates will be posted
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(disMCbot.class);
|
||||
|
||||
public static void main(String[] args) throws LoginException {
|
||||
logger.info("Starting Discord Comms...");
|
||||
JDABuilder builder = JDABuilder.createDefault("MTIyNjY1NTgxODU0NDMxNjQxNw.GALTlL.vPRJyKTEJNqN1Snfj5G-_2306lBKFdOYB1eDXE");
|
||||
builder.addEventListeners(new disMCbot());
|
||||
builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return; // Ignore messages from bots
|
||||
|
||||
String message = event.getMessage().getContentRaw();
|
||||
// Check for conditions or events triggering updates
|
||||
if (message.contains("Player1 died")) {
|
||||
// Log It
|
||||
logger.info("Player1 died - detected");
|
||||
// Post update to the specified channel
|
||||
if (updateChannel != null) {
|
||||
updateChannel.sendMessage("Player1 has died in Minecraft!").queue();
|
||||
// Log It
|
||||
logger.info("Message Posted in Discord.");
|
||||
}
|
||||
} else if (message.contains("Player1 Exp")) {
|
||||
// Log It
|
||||
logger.info("Player1 Exp Gained");
|
||||
// Post another type of update
|
||||
if (updateChannel != null) {
|
||||
updateChannel.sendMessage("Player1 gained experience in Minecraft!").queue();
|
||||
// Log It
|
||||
logger.info("Message sent to Discord.");
|
||||
}
|
||||
} else if (message.contains("drowned")) {
|
||||
// Log It
|
||||
logger.info("Player1 has drowned");
|
||||
// Post another type of update
|
||||
if (updateChannel != null) {
|
||||
updateChannel.sendMessage("Player1 has drowned - they got thirsty!").queue();
|
||||
// Log It
|
||||
logger.info("Message sent to Discord.");
|
||||
}
|
||||
|
||||
public void setUpdateChannel(TextChannel channel) {
|
||||
this.updateChannel = channel;
|
||||
}
|
||||
}
|
||||
|
||||
|
13
log4j2.xml
Normal file
13
log4j2.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<File name="File" fileName="../logs/bot.log">
|
||||
<PatternLayout pattern="%d{dd-MM-yyyy HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="File" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
70
pom.xml
Normal file
70
pom.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>minecraft-chatbot</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<!-- Specify Java version -->
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spigot API dependency -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--(Java Discord API) with JFlac and Tritonus-dsp -->
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>1.2.2_139</version> <!-- Update version to the latest stable version -->
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>jflac</groupId>
|
||||
<artifactId>jflac</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>tritonus</groupId>
|
||||
<artifactId>tritonus-dsp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- Logging-->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.23.1</version> <!-- Use the latest STABLE version -->
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Add other dependencies as needed -->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Maven Compiler Plugin configuration -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version> <!-- Use the appropriate version -->
|
||||
<configuration>
|
||||
<source>21</source> <!-- Update to the Java version you're using -->
|
||||
<target>21</target> <!-- Update to the Java version you're using -->
|
||||
<compilerArgs>
|
||||
<arg>--enable-preview</arg> <!-- Enable preview features -->
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Add other plugins as needed -->
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
BIN
spigot-api-1.20.4-R0.1-SNAPSHOT.jar
Normal file
BIN
spigot-api-1.20.4-R0.1-SNAPSHOT.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user