renamed MCchatbotyt to YouTubeBot

This commit is contained in:
nzBryce101
2024-04-29 21:06:34 +12:00
parent 8fc9ce21fa
commit 2e18a33cb6
4 changed files with 61 additions and 70 deletions

25
pom.xml
View File

@@ -35,28 +35,13 @@
<dependency> <dependency>
<groupId>com.google.api-client</groupId> <groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId> <artifactId>google-api-client</artifactId>
<version>2.4.0</version> <version>2.4.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.http-client</groupId> <groupId>com.google.apis</groupId>
<artifactId>google-http-client</artifactId> <artifactId>google-api-services-youtube</artifactId>
<version>1.44.1</version> <version>v3-rev222-1.25.0</version>
</dependency> </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>
</dependencies> </dependencies>
<build> <build>

View File

@@ -0,0 +1,8 @@
public class MainClass {
public static void main(String[] args) {
String apiKey = "AIzaSyA-wQ8i8vj_GKRuGJmtP-igFVNwaKrymIo"; // Replace with your actual YouTube API key
YouTubeBot bot = new YouTubeBot(apiKey);
// Your bot logic goes here
}
}

View File

@@ -1,50 +1,47 @@
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.JsonFactory; import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.VideoListResponse; public class YouTubeBot {
import com.google.api.services.youtube.model.Video; private Server server;
private YouTube youtube;
public class YouTubeBot {
private Server server; public YouTubeBot(String apiKey) {
private YouTube youtube; try {
this.server = Bukkit.getServer();
public YouTubeBot(String apiKey) { this.youtube = new YouTube.Builder(
try { GoogleNetHttpTransport.newTrustedTransport())
this.server = Bukkit.getServer(); .setApplicationName("Crafty MC")
this.youtube = new YouTube.Builder( .build();
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(), // API Key
null) youtube.setApiKey(apiKey);
.setApplicationName("Crafty MC") } catch (Exception e) {
.setYouTubeApiKey() e.printStackTrace();
.build(); }
} catch (Exception e) { }
e.printStackTrace();
} public int getOnlinePlayersCount() {
} return server.getOnlinePlayers().size();
}
public int getOnlinePlayersCount() {
return server.getOnlinePlayers().size(); public void handleCommand(String command) {
} if (command.equalsIgnoreCase("!stats")) {
String stats = getServerStatistics();
public void handleCommand(String command) { // Send stats to YouTube chat or log for testing
if (command.equalsIgnoreCase("!stats")) { System.out.println(stats); // For testing, replace with actual sending to YouTube chat
String stats = getServerStatistics(); }
// Send stats to YouTube chat or log for testing }
System.out.println(stats); // For testing, replace with actual sending to YouTube chat
} private String getServerStatistics() {
} // Use Spigot API or other methods to get server stats
int onlinePlayers = server.getOnlinePlayers().size();
private String getServerStatistics() { // Construct and return server stats message
// Use Spigot API or other methods to get server stats return "Online Players: " + onlinePlayers;
int onlinePlayers = server.getOnlinePlayers().size(); }
// Construct and return server stats message
return "Online Players: " + onlinePlayers; // Other methods and bot logic
}
// Other methods and bot logic
} }

View File

@@ -1 +1,2 @@
C:\Users\hbmann\Documents\Projects\_MCbotYT\MCyoutube_bot\src\main\java\MCchatbotyt.java C:\Users\hbmann\Documents\Projects\_MCbotYT\MCyoutube_bot\src\main\java\YouTubeBot.java
C:\Users\hbmann\Documents\Projects\_MCbotYT\MCyoutube_bot\src\main\java\MainClass.java