|
@ -18,45 +18,50 @@ import net.dv8tion.jda.api.OnlineStatus; |
|
|
import net.dv8tion.jda.api.entities.Activity; |
|
|
import net.dv8tion.jda.api.entities.Activity; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Repräsentiert einen Yoshi-Bot. Der Bot initialisiert alle Ressourcen und schaltet sich in der |
|
|
|
|
|
* startYoshiBot-Methode online und beginnt dann zu lauschen. Parallel lauscht ein Thread auf |
|
|
|
|
|
* Konsoleneingaben für administrative Zwecke, die nicht über den Chat erledigt werden sollten. |
|
|
|
|
|
|
|
|
* Repräsentiert einen Yoshi-Bot. Der Bot initialisiert alle Ressourcen und schaltet sich in der startYoshiBot-Methode |
|
|
|
|
|
* online und beginnt dann zu lauschen. Parallel lauscht ein Thread auf Konsoleneingaben für administrative Zwecke, die |
|
|
|
|
|
* nicht über den Chat erledigt werden sollten. |
|
|
|
|
|
* |
|
|
* @author Yannic Link |
|
|
* @author Yannic Link |
|
|
*/ |
|
|
*/ |
|
|
public class YoshiBot { |
|
|
|
|
|
|
|
|
public class YoshiBot { |
|
|
|
|
|
|
|
|
private static CommandLine commandLineThread; |
|
|
|
|
|
|
|
|
private CommandLine commandLineThread; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Erlaubt es einige Einstellungen vor und nach der Erzeugung eines Bots vorzunehmen. |
|
|
* Erlaubt es einige Einstellungen vor und nach der Erzeugung eines Bots vorzunehmen. |
|
|
*/ |
|
|
*/ |
|
|
public static JDABuilder jdaBuilder; |
|
|
|
|
|
|
|
|
public JDABuilder jdaBuilder; |
|
|
/** |
|
|
/** |
|
|
* Instanz vom aktuell laufenden Bot. |
|
|
* Instanz vom aktuell laufenden Bot. |
|
|
*/ |
|
|
*/ |
|
|
public static JDA jda; |
|
|
|
|
|
|
|
|
public JDA jda; |
|
|
/** |
|
|
/** |
|
|
* LavaPlayer AudioPlayerManager. |
|
|
* LavaPlayer AudioPlayerManager. |
|
|
*/ |
|
|
*/ |
|
|
public static AudioPlayerManager audioPlayerManager; |
|
|
|
|
|
|
|
|
public AudioPlayerManager audioPlayerManager; |
|
|
|
|
|
|
|
|
public static AudioControllerManager audioControllerManager; |
|
|
|
|
|
|
|
|
public AudioControllerManager audioControllerManager; |
|
|
|
|
|
|
|
|
|
|
|
private static YoshiBot instance = null; |
|
|
|
|
|
|
|
|
|
|
|
private YoshiBot() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Initialisiert alle dynamisch hinzugefügten und statischen Ressourcen. Startet aber nicht |
|
|
|
|
|
* den Bot selbst. |
|
|
|
|
|
|
|
|
* Initialisiert alle dynamisch hinzugefügten und statischen Ressourcen. Startet aber nicht den Bot selbst. |
|
|
*/ |
|
|
*/ |
|
|
public static void init(String configPath) { |
|
|
|
|
|
|
|
|
public void init(String configPath) { |
|
|
Resources.init(configPath); |
|
|
Resources.init(configPath); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Startet den Bot und schaltet ihn online. Beginnt auf Konsoleneingaben für administrative |
|
|
|
|
|
* Zwecke zu lauschen. |
|
|
|
|
|
|
|
|
* Startet den Bot und schaltet ihn online. Beginnt auf Konsoleneingaben für administrative Zwecke zu lauschen. |
|
|
|
|
|
* |
|
|
* @throws LoginException Falls das Token ungültig ist. |
|
|
* @throws LoginException Falls das Token ungültig ist. |
|
|
*/ |
|
|
*/ |
|
|
public static void start() throws LoginException { |
|
|
|
|
|
|
|
|
public void start() throws LoginException { |
|
|
System.out.println("Starte YoshiBot."); |
|
|
System.out.println("Starte YoshiBot."); |
|
|
|
|
|
|
|
|
jdaBuilder = JDABuilder.createDefault(Resources.getJdaBuilderString()); |
|
|
jdaBuilder = JDABuilder.createDefault(Resources.getJdaBuilderString()); |
|
@ -80,7 +85,7 @@ public class YoshiBot { |
|
|
commandLineThread.start(); |
|
|
commandLineThread.start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static synchronized void stop() { |
|
|
|
|
|
|
|
|
public synchronized void stop() { |
|
|
commandLineThread.stopCommandLine(); |
|
|
commandLineThread.stopCommandLine(); |
|
|
System.out.println("Beende YoshiBot ..."); |
|
|
System.out.println("Beende YoshiBot ..."); |
|
|
jdaBuilder.setStatus(OnlineStatus.OFFLINE); |
|
|
jdaBuilder.setStatus(OnlineStatus.OFFLINE); |
|
@ -90,10 +95,18 @@ public class YoshiBot { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Leitet den Context an den CommandDistributor weiter. |
|
|
* Leitet den Context an den CommandDistributor weiter. |
|
|
|
|
|
* |
|
|
* @param command Der Kontext für das Kommando. |
|
|
* @param command Der Kontext für das Kommando. |
|
|
*/ |
|
|
*/ |
|
|
public static void executeCommand(YoshiCommandContext command) { |
|
|
public static void executeCommand(YoshiCommandContext command) { |
|
|
YoshiCommandDistributor.distribute(command); |
|
|
YoshiCommandDistributor.distribute(command); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static YoshiBot getInstance() { |
|
|
|
|
|
if (YoshiBot.instance == null) { |
|
|
|
|
|
YoshiBot.instance = new YoshiBot(); |
|
|
|
|
|
} |
|
|
|
|
|
return YoshiBot.instance; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |