use of com.github.vaerys.pogos.GlobalData in project DiscordSailv2 by Vaerys-Dawn.
the class Main method main.
public static void main(String[] args) throws UnknownHostException {
// important, do not move
PatchHandler.preInitPatches();
logger = LoggerFactory.getLogger(Main.class);
logger.info("Starting bot...");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info(">>> Running Shutdown Process <<<");
if (Globals.savingFiles) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Utility.sendStack(e);
}
}
Globals.saveFiles(true);
}
});
String token = null;
// you need to set a token in Token/Token.txt for the bot to run
try {
Discord4J.disableAudio();
FileHandler.createDirectory(Constants.DIRECTORY_STORAGE);
FileHandler.createDirectory(Constants.DIRECTORY_GLOBAL_IMAGES);
FileHandler.createDirectory(Constants.DIRECTORY_COMP);
FileHandler.createDirectory(Constants.DIRECTORY_BACKUPS);
FileHandler.createDirectory(Constants.DIRECTORY_TEMP);
FileHandler.createDirectory(Constants.DIRECTORY_OLD_FILES);
FileHandler.createDirectory(Constants.DIRECTORY_ERROR);
// load config phase 1
Config config = (Config) Config.create(Constants.FILE_CONFIG, new Config());
GlobalData globalData = (GlobalData) GlobalData.create(Constants.FILE_GLOBAL_DATA, new GlobalData());
config = Config.check(config);
// getting bot token
try {
token = FileHandler.readFromFile(Constants.FILE_TOKEN).get(0);
} catch (IndexOutOfBoundsException e) {
logger.error("!!!BOT TOKEN NOT VALID PLEASE CHECK \"Storage/Token.txt\" AND UPDATE THE TOKEN!!!");
System.exit(Constants.EXITCODE_STOP);
}
try {
List<String> pastebinToken = FileHandler.readFromFile(Constants.FILE_PASTEBIN_TOKEN);
Client.initPastebin(pastebinToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Pastebin Token found.");
}
// stuff that i cant getToggles to work because reasons, ignore completely
// try{
// List<String> richPresesnce = FileHandler.readFromFile(Constants.FILE_RPC_TOKEN);
// Client.initRichPresence(richPresesnce);
// }catch (IndexOutOfBoundsException e){
// logger.info("Rich presence information missing.");
// }
// try {
// List<String> imgurToken = FileHandler.readFromFile(Constants.FILE_IMGUR_TOKEN);
// Client.initImgur(imgurToken);
// } catch (IndexOutOfBoundsException e) {
// logger.info("No Patreon Token found.");
// }
IDiscordClient client = Client.createClient(token, false);
// load config phase 2
Globals.initConfig(client, config, globalData);
if (Globals.creatorID == 153159020528533505L) {
try {
List<String> patreonToken = FileHandler.readFromFile(Constants.FILE_PATREON_TOKEN);
Client.initPatreon(patreonToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Patreon Token found.");
}
}
Globals.validateConfig();
if (Globals.errorStack != null) {
logger.error(">\n> Begin Config Error Report <<\n" + "at " + Constants.DIRECTORY_STORAGE + Constants.FILE_CONFIG + "\n" + Globals.errorStack + ">> End Error Report <<");
System.exit(Constants.EXITCODE_STOP);
}
ThreadGroup group = new ThreadGroup("GuildCreateGroup");
final int[] count = new int[] { 0 };
// login + register listener.
client.login();
// initialize creatorID if it is completely unset:
if (config.creatorID == 0) {
IUser botOwner = client.getApplicationOwner();
config.creatorID = botOwner.getLongID();
Globals.creatorID = config.creatorID;
logger.info("Default creatorID set to user " + botOwner.getName() + "#" + botOwner.getDiscriminator());
// save it back out to file.
config.flushFile();
}
ExecutorService guildService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService commandService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService creatorService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
EventDispatcher dispatcher = client.getDispatcher();
dispatcher.registerListener(guildService, new GuildCreateListener());
dispatcher.registerListener(commandService, new AnnotationListener());
dispatcher.registerListener(creatorService, new CreatorHandler());
dispatcher.registerTemporaryListener(new InitEvent());
// validate config file
Globals.setVersion();
// Init Patch system.
// timed events getSlashCommands
new TimerHandler();
} catch (DiscordException ex) {
logger.error(ex.getErrorMessage());
} catch (RateLimitException e) {
Utility.sendStack(e);
}
}
use of com.github.vaerys.pogos.GlobalData in project DiscordSailv2 by Vaerys-Dawn.
the class BlockUser method execute.
@Override
public String execute(String args, CommandObject command) {
long userId = Globals.lastDmUserID;
if (args != null && !args.isEmpty()) {
userId = Utility.stringLong(args.split("")[0]);
}
GlobalData globalData = Globals.getGlobalData();
if (userId == Globals.creatorID) {
return "> What are you doing. Don't try to block yourself.";
}
if (command.client.get().fetchUser(userId) != null) {
globalData.blockUserFromDMS(userId);
return "> User was blocked";
}
return "> Could not find a valid userID";
}
use of com.github.vaerys.pogos.GlobalData in project DiscordSailv2 by Vaerys-Dawn.
the class UnBlockUser method execute.
@Override
public String execute(String args, CommandObject command) {
GlobalData globalData = Globals.getGlobalData();
ListIterator iterator = globalData.getBlockedFromDMS().listIterator();
long userID = Utility.stringLong(args.split(" ")[0]);
while (iterator.hasNext()) {
long id = (long) iterator.next();
if (id == userID) {
iterator.remove();
return "> User Unblocked";
}
}
return "> Could not find user or invalid ID.";
}
Aggregations