2017-05-23 17:19:15 +00:00
|
|
|
package me.savvy.rixa;
|
|
|
|
|
2017-07-12 03:04:56 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.commands.admin.BatchMoveCommand;
|
2017-06-09 22:09:40 +00:00
|
|
|
import me.savvy.rixa.commands.admin.ConfigCommand;
|
2017-07-12 01:56:47 +00:00
|
|
|
import me.savvy.rixa.commands.admin.InviteCommand;
|
2017-06-09 22:09:40 +00:00
|
|
|
import me.savvy.rixa.commands.general.*;
|
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-06-09 22:09:40 +00:00
|
|
|
import me.savvy.rixa.commands.mod.MuteCommand;
|
2017-05-29 22:31:22 +00:00
|
|
|
import me.savvy.rixa.commands.mod.PurgeMessagesCommand;
|
2017-06-04 23:00:58 +00:00
|
|
|
import me.savvy.rixa.data.database.Data;
|
|
|
|
import me.savvy.rixa.data.database.DataType;
|
|
|
|
import me.savvy.rixa.data.database.sql.DatabaseManager;
|
|
|
|
import me.savvy.rixa.data.filemanager.ConfigManager;
|
|
|
|
import me.savvy.rixa.data.filemanager.LanguageManager;
|
2017-05-24 13:16:39 +00:00
|
|
|
import me.savvy.rixa.events.BotEvent;
|
2017-07-11 21:27:18 +00:00
|
|
|
import me.savvy.rixa.events.MemberEvent;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.events.MessageEvent;
|
2017-07-14 09:53:47 +00:00
|
|
|
import me.savvy.rixa.events.VoiceChannel;
|
2017-07-11 21:27:18 +00:00
|
|
|
import me.savvy.rixa.modules.reactions.handlers.React;
|
2017-05-23 17:19:15 +00:00
|
|
|
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
2017-07-11 21:27:18 +00:00
|
|
|
import me.savvy.rixa.modules.reactions.react.ConfigReaction;
|
2017-05-23 17:19:15 +00:00
|
|
|
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-07-14 18:22:29 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2017-05-23 17:19:15 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Timber on 5/7/2017.
|
|
|
|
*/
|
|
|
|
public class Rixa {
|
2017-07-12 03:04:56 +00:00
|
|
|
|
|
|
|
@Getter
|
2017-06-04 23:00:58 +00:00
|
|
|
private static Data data;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter
|
2017-06-04 23:00:58 +00:00
|
|
|
private static long timeUp;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter
|
2017-06-04 23:00:58 +00:00
|
|
|
private static Rixa instance;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter
|
2017-05-23 17:19:15 +00:00
|
|
|
private static List<JDA> shardsList;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter
|
2017-06-04 23:00:58 +00:00
|
|
|
private static ConfigManager config;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter @Setter
|
2017-05-29 22:31:22 +00:00
|
|
|
private static DatabaseManager dbManager;
|
2017-07-12 03:04:56 +00:00
|
|
|
@Getter @Setter
|
2017-06-04 23:00:58 +00:00
|
|
|
private LanguageManager languageManager;
|
|
|
|
// String search = event.getMessage().getContent().substring(event.getMessage().getContent().indexOf(" ") + 1);
|
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-07-14 18:22:29 +00:00
|
|
|
// config = new ConfigManager();
|
|
|
|
config = new ConfigManager(new File("Rixa/config.json"));
|
2017-05-29 22:31:22 +00:00
|
|
|
load();
|
2017-05-23 17:19:15 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 22:31:22 +00:00
|
|
|
private static void load() {
|
2017-06-04 23:00:58 +00:00
|
|
|
dbManager = new DatabaseManager(
|
2017-07-14 18:22:29 +00:00
|
|
|
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("hostName")),
|
|
|
|
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("portNumber")),
|
|
|
|
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("databaseName")),
|
|
|
|
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("userName")),
|
|
|
|
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("password")));
|
2017-05-29 22:31:22 +00:00
|
|
|
dbManager.createTable();
|
2017-06-04 23:00:58 +00:00
|
|
|
getInstance().setLanguageManager(new LanguageManager());
|
2017-05-29 22:31:22 +00:00
|
|
|
try {
|
2017-07-11 21:27:18 +00:00
|
|
|
int shards = 5;
|
2017-05-29 22:31:22 +00:00
|
|
|
for(int i = 0; i < shards; i++) {
|
|
|
|
Logger.getLogger("Rixa").info("Loading shard #" + i);
|
|
|
|
JDABuilder jda = new JDABuilder(AccountType.BOT)
|
2017-07-14 18:22:29 +00:00
|
|
|
.setToken(config.getJsonObject().getString("secretToken"))
|
2017-05-29 22:31:22 +00:00
|
|
|
.setEventManager(new AnnotatedEventManager())
|
|
|
|
.addEventListener(new MessageEvent())
|
2017-06-04 23:00:58 +00:00
|
|
|
.addEventListener(new BotEvent())
|
2017-07-11 21:27:18 +00:00
|
|
|
.addEventListener(new MemberEvent())
|
2017-07-14 09:53:47 +00:00
|
|
|
.addEventListener(new VoiceChannel())
|
2017-07-14 18:22:29 +00:00
|
|
|
.setGame(Game.of(config.getJsonObject().getString("botGame")))
|
2017-06-04 23:00:58 +00:00
|
|
|
.setAutoReconnect(true)
|
2017-05-29 22:31:22 +00:00
|
|
|
.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(),
|
2017-06-09 22:09:40 +00:00
|
|
|
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
|
2017-07-12 01:56:47 +00:00
|
|
|
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand()});
|
2017-07-11 21:27:18 +00:00
|
|
|
register(new React[] {new HelpReaction(), new ConfigReaction()});
|
2017-06-04 23:00:58 +00:00
|
|
|
data = new Data(DataType.SQL);
|
|
|
|
}
|
2017-07-12 03:04:56 +00:00
|
|
|
|
2017-06-04 23:00:58 +00:00
|
|
|
private static void register(CommandExec commandExecs[]) {
|
|
|
|
for (CommandExec command: commandExecs) {
|
|
|
|
CommandHandler.registerCommand(command);
|
2017-05-29 22:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-04 23:00:58 +00:00
|
|
|
|
2017-07-11 21:27:18 +00:00
|
|
|
private static void register(React react[]) {
|
|
|
|
for (React reaction: react) {
|
|
|
|
ReactionManager.registerReaction(reaction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 23:00:58 +00:00
|
|
|
public Logger getLogger() {
|
|
|
|
return Logger.getLogger("Rixa");
|
|
|
|
}
|
2017-07-12 03:04:56 +00:00
|
|
|
|
2017-05-23 17:19:15 +00:00
|
|
|
}
|