2022-03-09 21:11:11 +00:00
|
|
|
package com.alttd;
|
|
|
|
|
|
|
|
|
|
import com.alttd.commandManager.CommandManager;
|
|
|
|
|
import com.alttd.config.SettingsConfig;
|
|
|
|
|
import com.alttd.config.MessagesConfig;
|
|
|
|
|
import com.alttd.permissions.PermissionManager;
|
|
|
|
|
import com.alttd.util.Logger;
|
|
|
|
|
import net.dv8tion.jda.api.JDA;
|
|
|
|
|
import net.dv8tion.jda.api.JDABuilder;
|
|
|
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
2022-04-08 17:51:12 +00:00
|
|
|
import static java.lang.System.exit;
|
|
|
|
|
|
2022-03-09 21:11:11 +00:00
|
|
|
public class AltitudeBot {
|
|
|
|
|
|
|
|
|
|
private JDA jda;
|
|
|
|
|
private static AltitudeBot instance;
|
|
|
|
|
|
|
|
|
|
public static AltitudeBot getInstance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 17:51:12 +00:00
|
|
|
public static void main(String[] args) {
|
|
|
|
|
instance = new AltitudeBot();
|
|
|
|
|
instance.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void start() {
|
2022-03-09 21:11:11 +00:00
|
|
|
Logger.info("Starting bot...");
|
|
|
|
|
initConfigs();
|
|
|
|
|
try {
|
|
|
|
|
jda = JDABuilder.createDefault(SettingsConfig.TOKEN).build();
|
|
|
|
|
} catch (LoginException e) {
|
2022-04-08 17:51:12 +00:00
|
|
|
Logger.info("Unable to log in, shutting down (check token in settings.yml).");
|
|
|
|
|
exit(1);
|
|
|
|
|
Logger.exception(e);
|
2022-03-09 21:11:11 +00:00
|
|
|
}
|
|
|
|
|
initListeners();
|
|
|
|
|
//TODO init permissionManager
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initListeners() {
|
2022-04-01 00:54:33 +00:00
|
|
|
jda.addEventListener(new CommandManager(jda));
|
2022-03-09 21:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 21:09:30 +00:00
|
|
|
public JDA getJDA() {
|
|
|
|
|
return jda;
|
|
|
|
|
}
|
2022-03-09 21:11:11 +00:00
|
|
|
}
|