splitting work flow up to make it easier
Discord, Youtube and Twitch will have their own jar files
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
name: MCbot
|
||||
version: 1.0
|
||||
main: src/MCbot.class
|
||||
main: MCbot
|
||||
description: A custom bot for interacting with Minecraft server stats.
|
||||
author: Bryce
|
||||
api-version: 1.20.4
|
||||
@@ -14,4 +14,3 @@ commands:
|
||||
death:
|
||||
description: update Death counter and post in chat [player has died [x] times]
|
||||
usage: /death <player>
|
||||
|
BIN
MCbot_bryce.jar
BIN
MCbot_bryce.jar
Binary file not shown.
53
pom.xml
53
pom.xml
@@ -23,59 +23,6 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Google / YouTube dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client</artifactId>
|
||||
<version>1.44.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client-jackson2</artifactId>
|
||||
<version>1.44.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.oauth-client</groupId>
|
||||
<artifactId>google-oauth-client</artifactId>
|
||||
<version>1.35.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-youtube</artifactId>
|
||||
<version>v3-rev222-1.25.0</version>
|
||||
</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>
|
||||
|
@@ -1,107 +0,0 @@
|
||||
import com.google.api.client.googleapis.auth.oauth2.Credential;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.googleapis.http.HttpRequest;
|
||||
import com.google.api.client.googleapis.http.HttpRequestInitializer;
|
||||
import com.google.api.client.googleapis.json.JsonFactory;
|
||||
import com.google.api.client.googleapis.json.jackson2.JacksonFactory;
|
||||
import com.google.api.services.youtube.YouTube;
|
||||
import com.google.api.services.youtube.model.LiveChatMessage;
|
||||
import com.google.api.services.youtube.model.LiveChatMessageListResponse;
|
||||
import com.google.api.services.youtube.model.LiveChatMessageSnippet;
|
||||
import com.google.api.services.youtube.model.LiveChatTextMessageDetails;
|
||||
import com.google.api.services.youtube.model.LiveChatTextMessageDetails.MessageTextDetails;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.List;
|
||||
|
||||
public class MCchatbotyt {
|
||||
|
||||
private static final String APPLICATION_NAME = "MC chatbot for YT";
|
||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||
private static YouTube youtube;
|
||||
|
||||
public static void main(String[] args) throws GeneralSecurityException, IOException {
|
||||
// Set up credentials
|
||||
Credential credential = authorize();
|
||||
|
||||
// Set up YouTube API client
|
||||
youtube = new YouTube.Builder(
|
||||
GoogleNetHttpTransport.newTrustedTransport(),
|
||||
JSON_FACTORY,
|
||||
new HttpRequestInitializer() {
|
||||
@Override
|
||||
public void initialize(HttpRequest request) throws IOException {
|
||||
request.setInterceptor(credential);
|
||||
}
|
||||
})
|
||||
.setApplicationName(APPLICATION_NAME)
|
||||
.build();
|
||||
|
||||
// Get live chat ID for your live stream
|
||||
String liveChatId = getLiveChatId("5lAKSeFQS2M");
|
||||
|
||||
// Poll for new chat messages every few seconds
|
||||
while (true) {
|
||||
List<LiveChatMessage> messages = getLiveChatMessages(liveChatId);
|
||||
for (LiveChatMessage message : messages) {
|
||||
String author = message.getSnippet().getAuthorChannelId();
|
||||
String text = message.getSnippet().getDisplayMessage();
|
||||
System.out.println("New message from " + author + ": " + text);
|
||||
// Add your logic to handle incoming messages here
|
||||
}
|
||||
|
||||
// Connect to the socket server in MCbot.java and send a command
|
||||
try (Socket socket = new Socket("localhost", 8888);
|
||||
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
|
||||
|
||||
// Send command to MCbot.java
|
||||
out.println("!players");
|
||||
|
||||
// Receive response from MCbot.java
|
||||
String response = in.readLine();
|
||||
System.out.println("Response from MCbot.java: " + response);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(5000); // Poll every 5 seconds
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Credential authorize() throws IOException, GeneralSecurityException {
|
||||
// Load client secrets JSON file (you need to create this file with your OAuth client ID and secret)
|
||||
GoogleCredential credential = GoogleCredential.fromStream(
|
||||
YouTubeLiveChatBot.class.getResourceAsStream("/client_secrets.json"))
|
||||
.createScoped(List.of("https://www.googleapis.com/auth/youtube"));
|
||||
|
||||
return credential;
|
||||
}
|
||||
|
||||
private static String getLiveChatId(String liveStreamId) throws IOException {
|
||||
YouTube.LiveChatMessages.List liveChatRequest = youtube.liveChatMessages()
|
||||
.list("id,snippet")
|
||||
.setLiveChatId(liveStreamId);
|
||||
LiveChatMessageListResponse response = liveChatRequest.execute();
|
||||
List<LiveChatMessage> messages = response.getItems();
|
||||
if (messages != null && !messages.isEmpty()) {
|
||||
return messages.get(0).getSnippet().getLiveChatId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<LiveChatMessage> getLiveChatMessages(String liveChatId) throws IOException {
|
||||
YouTube.LiveChatMessages.List liveChatRequest = youtube.liveChatMessages()
|
||||
.list("id,snippet")
|
||||
.setLiveChatId(liveChatId);
|
||||
LiveChatMessageListResponse response = liveChatRequest.execute();
|
||||
return response.getItems();
|
||||
}
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<File name="File" fileName="logs/MCbot.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>
|
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<File name="File" fileName="logs/MCbot.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>
|
Reference in New Issue
Block a user