2022-03-23 20:39:52 +00:00
|
|
|
package moe.oko.Kiafumi;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
|
|
|
import net.dv8tion.jda.api.JDA;
|
|
|
|
import net.dv8tion.jda.api.JDABuilder;
|
2022-03-23 20:39:52 +00:00
|
|
|
import net.dv8tion.jda.api.OnlineStatus;
|
|
|
|
import net.dv8tion.jda.api.entities.Activity;
|
|
|
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
|
|
|
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
|
|
|
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
2022-03-23 20:31:23 +00:00
|
|
|
import org.simpleyaml.configuration.file.YamlConfiguration;
|
|
|
|
import org.simpleyaml.exceptions.InvalidConfigurationException;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public class Kiafumi {
|
2022-03-23 20:31:23 +00:00
|
|
|
|
|
|
|
private File CONFIG_FILE = new File("config.yml");
|
|
|
|
|
|
|
|
public YamlConfiguration yamlConfiguration;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public Logger logger = LoggerFactory.getLogger("Kiafumi");
|
2022-03-23 20:31:23 +00:00
|
|
|
|
|
|
|
public static String PREFIX;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public static Kiafumi instance;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public static JDA JDA;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public KiafumiConfig config;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
try {
|
2022-03-23 20:39:52 +00:00
|
|
|
Kiafumi shiki = new Kiafumi();
|
2022-03-23 20:31:23 +00:00
|
|
|
shiki.start();
|
|
|
|
} catch (Exception ex) {
|
2022-03-23 20:39:52 +00:00
|
|
|
System.out.println("Failed to start Kiafumi Instance, check your Java installation.");
|
2022-03-23 20:31:23 +00:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void start() {
|
|
|
|
instance = this;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
logger.info("Starting Kiafumi.");
|
2022-03-23 20:31:23 +00:00
|
|
|
System.out.println("If no other messages are present, logger failed to instantiate.");
|
|
|
|
|
|
|
|
logger.info("Config load start...");
|
|
|
|
|
|
|
|
if (!CONFIG_FILE.exists()) {
|
|
|
|
try {
|
|
|
|
CONFIG_FILE.createNewFile();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
logger.warn("Failed to create the configuration file. Stopping. (Try creating configuration directory.)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
yamlConfiguration.load(CONFIG_FILE);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
logger.warn("File not found, attempting to create.");
|
|
|
|
|
|
|
|
} catch (IOException | InvalidConfigurationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
config = new KiafumiConfig(yamlConfiguration);
|
2022-03-23 20:31:23 +00:00
|
|
|
if(config.load()) {
|
|
|
|
logger.info("Config loaded, proceeding.");
|
|
|
|
} else {
|
|
|
|
logger.error("Failed to load configuration. Stopping process.");
|
|
|
|
Runtime.getRuntime().exit(0);
|
|
|
|
}
|
|
|
|
logger.info("Registering shutdown hook.");
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
|
|
|
|
|
|
|
|
PREFIX = config.getPrefix();
|
|
|
|
|
|
|
|
//Makes our JDA instance.
|
|
|
|
startDiscord();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stop() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startDiscord() {
|
2022-03-23 20:39:52 +00:00
|
|
|
try {
|
|
|
|
JDA = JDABuilder.create(config.getToken(), GatewayIntent.GUILD_MEMBERS,
|
|
|
|
GatewayIntent.GUILD_MESSAGES,
|
|
|
|
GatewayIntent.DIRECT_MESSAGES)
|
|
|
|
.setChunkingFilter(ChunkingFilter.ALL)
|
|
|
|
.setMemberCachePolicy(MemberCachePolicy.ALL)
|
|
|
|
.setActivity(Activity.of(Activity.ActivityType.valueOf(config.getActivityType()), config.getActivityMsg()))
|
|
|
|
.setStatus(OnlineStatus.valueOf(config.getStatusType()))
|
|
|
|
.addEventListeners().build().awaitReady();
|
|
|
|
} catch(Exception ex) {
|
|
|
|
error("Initialization broke...");
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2022-03-23 20:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static logger info reference.
|
|
|
|
*/
|
|
|
|
public static void info(String str) {
|
|
|
|
instance.logger.info(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static Logger Error reference.
|
|
|
|
*/
|
|
|
|
public static void error(String str) {
|
|
|
|
instance.logger.error(str);
|
|
|
|
}
|
|
|
|
}
|