64 lines
2.5 KiB
Java
64 lines
2.5 KiB
Java
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;
|
|
}
|
|
}
|
|
|
|
|