src/com/minecraft/bot folder created

This commit is contained in:
nzBryce101
2024-04-05 20:34:06 +13:00
parent 5efad52007
commit a65760d4ac
7 changed files with 46 additions and 23 deletions

29
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "MCbot",
"request": "launch",
"mainClass": "MCbot",
"projectName": "minecraft-chatbot"
},
{
"type": "java",
"name": "MCchatbotyt",
"request": "launch",
"mainClass": "MCchatbotyt",
"projectName": "minecraft-chatbot"
}
]
}

View File

@@ -43,7 +43,6 @@ public class MCchatbotyt {
// 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);
@@ -53,6 +52,22 @@ public class MCchatbotyt {
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) {
@@ -89,25 +104,4 @@ public class MCchatbotyt {
LiveChatMessageListResponse response = liveChatRequest.execute();
return response.getItems();
}
// Connect to the socket server in MCbot.java
Socket socket = new Socket("localhost", 12345); // Connect to localhost on port 12345
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);
socket.close();
} catch (IOException | GeneralSecurityException e) {
e.printStackTrace();
}
}
}

Binary file not shown.