82 lines
2.3 KiB
Java
82 lines
2.3 KiB
Java
package com.alttd;
|
|
|
|
import com.alttd.commandManager.listeners.JDAListener;
|
|
import com.alttd.config.MessagesConfig;
|
|
import com.alttd.config.SettingsConfig;
|
|
import com.alttd.console.ConsoleCommandManager;
|
|
import com.alttd.database.Database;
|
|
import com.alttd.database.DatabaseTables;
|
|
import com.alttd.util.Logger;
|
|
import com.alttd.util.Util;
|
|
import net.dv8tion.jda.api.JDA;
|
|
import net.dv8tion.jda.api.JDABuilder;
|
|
import net.dv8tion.jda.api.OnlineStatus;
|
|
import net.dv8tion.jda.api.entities.Activity;
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
import java.io.File;
|
|
import java.net.URISyntaxException;
|
|
|
|
import static java.lang.System.exit;
|
|
|
|
public class AltitudeBot {
|
|
|
|
private JDA jda;
|
|
private static AltitudeBot instance;
|
|
|
|
public static AltitudeBot getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
instance = new AltitudeBot();
|
|
instance.start();
|
|
}
|
|
|
|
private void start() {
|
|
Logger.info("Starting bot...");
|
|
initConfigs();
|
|
try {
|
|
jda = JDABuilder.createDefault(SettingsConfig.TOKEN).build();
|
|
} catch (LoginException e) {
|
|
Logger.info("Unable to log in, shutting down (check token in settings.yml).");
|
|
Logger.exception(e);
|
|
exit(1);
|
|
}
|
|
DatabaseTables.createTables(Database.getDatabase().getConnection());
|
|
ConsoleCommandManager.startConsoleCommands(jda);
|
|
try {
|
|
jda.getPresence().setPresence(
|
|
OnlineStatus.valueOf(SettingsConfig.STATUS),
|
|
Activity.listening(SettingsConfig.ACTIVITY));
|
|
} catch (IllegalArgumentException e) {
|
|
Logger.exception(e);
|
|
}
|
|
initListeners();
|
|
//TODO init permissionManager
|
|
}
|
|
|
|
private void initListeners() {
|
|
jda.addEventListener(new JDAListener(jda));
|
|
}
|
|
|
|
private void initConfigs() {
|
|
SettingsConfig.reload();
|
|
MessagesConfig.reload();
|
|
}
|
|
|
|
public String getDataFolder() {
|
|
try {
|
|
return new File(AltitudeBot.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getPath();
|
|
} catch (URISyntaxException e) {
|
|
Logger.severe("Unable to retrieve config directory");
|
|
e.printStackTrace();
|
|
}
|
|
return (null);
|
|
}
|
|
|
|
public JDA getJDA() {
|
|
return jda;
|
|
}
|
|
}
|