minor tweaks
Working on JDA dependency incompatibility
This commit is contained in:
@@ -1,68 +1,29 @@
|
||||
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import org.apache.logging.log4j.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import listeners.MinecraftEventListener;
|
||||
|
||||
public class disMCbot extends ListenerAdapter {
|
||||
|
||||
private TextChannel updateChannel; // Define the channel where updates will be posted
|
||||
|
||||
public class disMCbot {
|
||||
private static TextChannel updateChannel;
|
||||
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());
|
||||
logger.info("Starting Discord Bot...");
|
||||
String token = "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80";
|
||||
JDABuilder builder = JDABuilder.createDefault(token);
|
||||
builder.addEventListeners(new MinecraftEventListener(updateChannel));
|
||||
builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@Nonnull 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) {
|
||||
disMCbot.updateChannel = channel;
|
||||
}
|
||||
|
||||
public void setUpdateChannel(TextChannel channel) {
|
||||
this.updateChannel = channel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Other methods and event listeners can be added as needed
|
||||
}
|
Reference in New Issue
Block a user