Пример #1
0
 public static synchronized void launch(MinnBotUserInterface console)
     throws Exception { // DON'T LOOK
   MinnBot.console = console;
   try {
     config = new JSONObject(new String(Files.readAllBytes(Paths.get("BotConfig.json"))));
     String pre = config.getString("prefix").trim();
     String ownerId = config.getString("owner").trim();
     String giphy = config.getString("giphy").trim();
     MinnBot bot = new MinnBot(pre, ownerId, console.logger);
     MinnBot.giphy = giphy;
     MinnBotUserInterface.bot = bot;
     Thread.currentThread()
         .setUncaughtExceptionHandler((Thread.UncaughtExceptionHandler) bot.getLogger());
     if (ignoreListener == null) {
       ignoreListener = new IIgnoreListener();
       IgnoreUtil.addListener(ignoreListener);
     }
   } catch (IllegalArgumentException e) {
     if (e.getMessage().isEmpty())
       console.writeEvent("The config was not populated.\nPlease enter a bot token.");
     e.printStackTrace();
     throw e;
   } catch (LoginException e) {
     console.writeEvent(
         "The provided login information was invalid.\n"
             + "Please provide a valid token or email and password combination.");
     throw e;
   } catch (InterruptedException e) {
     e.printStackTrace();
     throw e;
   } catch (IOException e) {
     JSONObject obj = new JSONObject();
     obj.put("prefix", "");
     obj.put("owner", "");
     obj.put("token", "");
     obj.put("log", true);
     obj.put("audio", false);
     obj.put("giphy", "dc6zaTOxFJmzC");
     try {
       Files.write(Paths.get("BotConfig.json"), obj.toString(4).getBytes());
       console.writeEvent(
           "No config file was found. BotConfig.json has been generated.\nPlease fill the fields with correct information!");
     } catch (IOException e1) {
       console.writeEvent("No config file was found and we failed to generate one.");
       e1.printStackTrace();
     }
     throw e;
   }
 }
Пример #2
0
 private boolean waitForReady(JDA api) {
   if (api == null) throw new IllegalArgumentException("JDA instance can not be null.");
   try {
     api.getGuilds()
         .parallelStream()
         .forEach(
             (Guild t) -> {
               while (!t.isAvailable())
                 try {
                   Thread.sleep(100);
                 } catch (InterruptedException ignored) {
                 }
             });
   } catch (Exception e) {
     return false;
   }
   return true;
 }
Пример #3
0
 public void onReady(ReadyEvent event) {
   log("Setting up api related config...");
   Thread t =
       new Thread(
           () -> {
             TagCommand.initTags(event.getJDA(), logger);
             PublicLog.init(api, logger::logThrowable);
             this.api = event.getJDA();
             if (config.has("home")) home = api.getGuildById(config.getString("home"));
             new ModLogManager(api);
             User uOwner = api.getUserById(owner);
             try {
               log("Owner: " + uOwner.getUsername() + "#" + uOwner.getDiscriminator());
             } catch (NullPointerException e) {
               logger.logThrowable(
                   new NullPointerException(
                       "Owner could not be retrieved from the given id. Do you share a guild with this bot? - Caused by id: \""
                           + owner
                           + "\""));
             }
             this.handler.setApi(event.getJDA());
             try {
               initCommands(api);
             } catch (UnknownHostException | UnsupportedDataTypeException e) {
               logger.logThrowable(e);
             }
             AccountSettings as = new AccountSettings(console);
             console.setAccountSettings(as);
             as.setApi(api);
             if (audio) api.addEventListener(new MinnAudioManager());
             console.setTitle(
                 api.getSelfInfo().getUsername()
                     + "#"
                     + api.getSelfInfo()
                         .getDiscriminator()); // so you know which one is logged in!
             inviteurl = getInviteUrl();
             tmp.init(this);
             logger.logInfo("Setup completed.");
           });
   t.setDaemon(false);
   t.setPriority(Thread.MAX_PRIORITY);
   t.setName("onReady...");
   t.setUncaughtExceptionHandler((Thread.UncaughtExceptionHandler) logger);
   t.start();
 }