2017-05-23 17:19:15 +00:00
|
|
|
package me.savvy.rixa;
|
|
|
|
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.commands.admin.BatchMoveCommand;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.commands.general.HelpCommand;
|
|
|
|
import me.savvy.rixa.commands.general.InfoCommand;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.commands.general.PingCommand;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.commands.general.ServerInfoCommand;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.commands.handlers.CommandHandler;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.commands.mod.DeleteMessagesCommand;
|
2017-05-29 22:31:22 +00:00
|
|
|
import me.savvy.rixa.commands.mod.PurgeMessagesCommand;
|
|
|
|
import me.savvy.rixa.database.DatabaseManager;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.events.BotEvent;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.events.MessageEvent;
|
|
|
|
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
|
|
|
import me.savvy.rixa.modules.reactions.react.HelpReaction;
|
|
|
|
import net.dv8tion.jda.core.AccountType;
|
|
|
|
import net.dv8tion.jda.core.JDA;
|
|
|
|
import net.dv8tion.jda.core.JDABuilder;
|
|
|
|
import net.dv8tion.jda.core.OnlineStatus;
|
|
|
|
import net.dv8tion.jda.core.entities.Game;
|
|
|
|
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
|
|
|
import net.dv8tion.jda.core.hooks.AnnotatedEventManager;
|
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
2017-05-29 22:31:22 +00:00
|
|
|
import java.io.*;
|
|
|
|
import java.util.HashMap;
|
2017-05-23 17:19:15 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2017-05-29 22:31:22 +00:00
|
|
|
import java.util.Map;
|
2017-05-23 17:19:15 +00:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Timber on 5/7/2017.
|
|
|
|
*/
|
|
|
|
public class Rixa {
|
|
|
|
|
|
|
|
private static List<JDA> shardsList;
|
2017-05-29 22:31:22 +00:00
|
|
|
private static DatabaseManager dbManager;
|
2017-05-23 17:19:15 +00:00
|
|
|
private static long timeUp;
|
|
|
|
private static Rixa instance; // String search = event.getMessage().getContent().substring(event.getMessage().getContent().indexOf(" ") + 1);
|
2017-05-29 22:31:22 +00:00
|
|
|
private static Map<String, String> config;
|
2017-05-23 17:19:15 +00:00
|
|
|
|
2017-05-29 22:31:22 +00:00
|
|
|
public static void main(String[] args) {
|
2017-05-23 17:19:15 +00:00
|
|
|
instance = new Rixa();
|
|
|
|
shardsList = new LinkedList<>();
|
2017-05-29 22:31:22 +00:00
|
|
|
config = new HashMap<>();
|
|
|
|
populateConfiguration();
|
|
|
|
load();
|
2017-05-23 17:19:15 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 13:16:39 +00:00
|
|
|
private static void register(CommandExec commandExecs[]) {
|
|
|
|
for (CommandExec command: commandExecs) {
|
|
|
|
CommandHandler.registerCommand(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 17:19:15 +00:00
|
|
|
public static Rixa getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimeUp() {
|
|
|
|
return timeUp;
|
|
|
|
}
|
2017-05-24 13:16:39 +00:00
|
|
|
|
|
|
|
public Logger getLogger() {
|
|
|
|
return Logger.getLogger("Rixa");
|
|
|
|
}
|
2017-05-29 22:31:22 +00:00
|
|
|
|
|
|
|
private static void load() {
|
|
|
|
if(!config.containsKey("TOKEN")) {
|
|
|
|
getInstance().getLogger().severe("Could not find \"TOKEN\" in config.text! Shutting down...");
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
dbManager = new DatabaseManager(config.get("SQL_HOSTNAME"), config.get("SQL_PORT"), config.get("SQL_DATABASE"), config.get("SQL_USER"), config.get("SQL_PASSWORD"));
|
|
|
|
dbManager.createTable();
|
|
|
|
try {
|
|
|
|
int shards = 3;
|
|
|
|
for(int i = 0; i < shards; i++) {
|
|
|
|
Logger.getLogger("Rixa").info("Loading shard #" + i);
|
|
|
|
JDABuilder jda = new JDABuilder(AccountType.BOT)
|
|
|
|
.setToken(config.get("TOKEN"))
|
|
|
|
.setEventManager(new AnnotatedEventManager())
|
|
|
|
.addEventListener(new MessageEvent())
|
|
|
|
.addEventListener(new BotEvent());
|
|
|
|
if(config.containsKey("GAME")) {
|
|
|
|
jda.setGame(Game.of(config.get("GAME")));
|
|
|
|
}
|
|
|
|
jda.setAutoReconnect(true)
|
|
|
|
.setStatus(OnlineStatus.ONLINE)
|
|
|
|
.setAudioEnabled(true)
|
|
|
|
.useSharding(i, shards);
|
|
|
|
shardsList.add(jda.buildBlocking());
|
|
|
|
getInstance().getLogger().info("Shard #" + i + " has been loaded");
|
|
|
|
}
|
|
|
|
} catch (LoginException | InterruptedException | RateLimitedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
timeUp = System.currentTimeMillis();
|
|
|
|
register(new CommandExec[] {
|
|
|
|
new InfoCommand(), new ServerInfoCommand(), new HelpCommand(),
|
|
|
|
new DeleteMessagesCommand(), new PingCommand(), new PurgeMessagesCommand(),
|
|
|
|
new BatchMoveCommand() });
|
|
|
|
ReactionManager.registerReaction(new HelpReaction());
|
|
|
|
}
|
|
|
|
|
|
|
|
public DatabaseManager getDbManager() {
|
|
|
|
return dbManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDbManager(DatabaseManager dbManager) {
|
|
|
|
this.dbManager = dbManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void populateConfiguration() {
|
|
|
|
FileReader fileReader = null;
|
|
|
|
try {
|
|
|
|
fileReader = new FileReader(new File("config.txt"));
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
getInstance().getLogger().severe("Could not find file \"config.text\"! Shutting down...");
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
BufferedReader br = new BufferedReader(fileReader);
|
|
|
|
String line = null;
|
|
|
|
try {
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
String[] s = line.split(":");
|
|
|
|
config.put(s[0], s[1]);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 17:19:15 +00:00
|
|
|
}
|