Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- final static Logger logger = LoggerFactory.getLogger(Main.class);
- public static void main(String[] args) throws UnknownHostException {
- System.out.println("Starting Program...");
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- logger.info(">>> Running Shutdown Process <<<");
- Globals.saveFiles();
- }
- });
- String token;
- // 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);
- if (!Files.exists(Paths.get(Constants.FILE_CONFIG))) {
- FileHandler.writeToJson(Constants.FILE_CONFIG, new Config());
- }
- if (!Files.exists(Paths.get(Constants.FILE_GLOBAL_DATA))) {
- FileHandler.writeToJson(Constants.FILE_GLOBAL_DATA, new GlobalData());
- }
- //load config phase 1
- Config config = (Config) FileHandler.readFromJson(Constants.FILE_CONFIG, Config.class);
- GlobalData globalData = (GlobalData) FileHandler.readFromJson(Constants.FILE_GLOBAL_DATA, GlobalData.class);
- config.initObject();
- FileHandler.writeToJson(Constants.FILE_CONFIG, config);
- //getting bot token
- token = FileHandler.readFromFile(Constants.FILE_TOKEN).get(0);
- if (token == null) {
- logger.error("!!!BOT TOKEN NOT VALID PLEASE CHECK \"Storage/Token.txt\" AND UPDATE THE TOKEN!!!");
- }
- IDiscordClient client = Client.getClient(token, false);
- //load config phase 2
- Globals.initConfig(client, config, globalData);
- PatchHandler.globalPatches();
- //login + register listener.
- EventDispatcher dispatcher = client.getDispatcher();
- dispatcher.registerListener(new AnnotationListener());
- client.login();
- //Init Patch system.
- //timed events get
- new TimedEvents();
- while (!client.isReady()) ;
- //makes sure that nothing in the config file will cause an error
- Globals.validateConfig();
- Globals.setVersion();
- consoleInput();
- } catch (DiscordException ex) {
- logger.error(ex.getErrorMessage());
- } catch (RateLimitException e) {
- e.printStackTrace();
- }
- }
- private static void consoleInput() {
- Scanner scanner = new Scanner(System.in);
- while (!Globals.isReady) ;
- logger.info("Console input initiated.");
- while (scanner.hasNextLine()) {
- while (Globals.consoleMessageCID == null) ;
- IChannel channel = Globals.getClient().getChannelByID(Globals.consoleMessageCID);
- String message = scanner.nextLine();
- message = message.replace("#Dawn#", Globals.getClient().getUserByID("153159020528533505").getName());
- message = message.replace("teh", "the");
- message = message.replace("Teh", "The");
- System.out.println(message);
- if (!message.equals("")) {
- Utility.sendMessage(message, channel);
- }
- }
- }
- }
- Starting Program...
- 22:39:40.941 [main] INFO org.eclipse.jetty.util.log - Logging initialized @579ms to org.eclipse.jetty.util.log.Slf4jLog
- 22:39:40.947 [main] INFO sx.blah.discord.Discord4J - Discord4J v2.7.1-SNAPSHOT (c96db79af5703aed7377b2c9868b0bbe42a81408-c96db79) (https://github.com/austinv11/Discord4J)
- 22:39:40.947 [main] INFO sx.blah.discord.Discord4J - A Java binding for the official Discord API, forked from the inactive https://github.com/nerd/Discord4J. Copyright (c) 2017, Licensed under GNU GPLv2
- 22:39:40.947 [main] INFO sx.blah.discord.Discord4J - Disabled audio.
- 22:39:42.119 [main] INFO Main.Globals - 62 Commands Loaded. //ignore these, they are my command init checks.
- 22:39:42.120 [main] INFO Main.Globals - 6 DM Commands Loaded.
- 22:39:42.120 [main] INFO Main.Globals - 10 Command Types Loaded.
- 22:39:42.120 [main] INFO Main.Globals - 9 Channel Types Loaded.
- 22:39:42.120 [main] INFO Main.Globals - 27 Guild Toggles Loaded.
- 22:39:42.120 [main] INFO Main.Globals - 8 Slash Commands Loaded.
- 22:39:43.800 [HttpClient@3232228-16] INFO sx.blah.discord.Discord4J - Websocket Connected.
- 22:39:44.136 [HttpClient@3232228-18] INFO sx.blah.discord.Discord4J - Connected to Discord Gateway v5. Receiving 1 guilds.
- 22:39:44.299 [Event Dispatcher Handler] INFO Main.AnnotationListener - Starting Guild get process for Guild with ID: 254790152851816458
- 22:39:45.091 [Event Dispatcher Handler] INFO Main.AnnotationListener - Finished Initialising Guild With ID: 254790152851816458
- 22:39:45.105 [main] INFO Main.Globals - Bot version : 2.6.0
- 22:39:45.107 [main] INFO Main.Main - Console input initiated.
Advertisement
Add Comment
Please, Sign In to add comment