Skip to content

Commit

Permalink
Merge pull request jagrosh#1487 from MichailiK/fix/server-settings-lo…
Browse files Browse the repository at this point in the history
…gging

Don't warn about failing to load server settings when the file isn't found
  • Loading branch information
jagrosh authored Mar 1, 2024
2 parents c4502bb + ff1ede9 commit ac8661c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
GUI gui = new GUI(bot);
bot.setGUI(gui);
gui.init();
}
catch(Exception e)

LOG.info("Loaded config from " + config.getConfigLocation());
}
catch(Exception e)
{
LOG.error("Could not start GUI. If you are "
+ "running on a server or in a location where you cannot display a "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.util.HashMap;
import net.dv8tion.jda.api.entities.Guild;
import org.json.JSONException;
Expand Down Expand Up @@ -57,9 +58,20 @@ public SettingsManager()
o.has("prefix") ? o.getString("prefix") : null,
o.has("skip_ratio") ? o.getDouble("skip_ratio") : SKIP_RATIO));
});
} catch (NoSuchFileException e) {
// create an empty json file
try {
LoggerFactory.getLogger("Settings").info("serversettings.json will be created in " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
Files.write(OtherUtil.getPath("serversettings.json"), new JSONObject().toString(4).getBytes());
} catch(IOException ex) {
LoggerFactory.getLogger("Settings").warn("Failed to create new settings file: "+ex);
}
return;
} catch(IOException | JSONException e) {
LoggerFactory.getLogger("Settings").warn("Failed to load server settings (this is normal if no settings have been set yet): "+e);
LoggerFactory.getLogger("Settings").warn("Failed to load server settings: "+e);
}

LoggerFactory.getLogger("Settings").info("serversettings.json loaded from " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
}

/**
Expand Down

0 comments on commit ac8661c

Please sign in to comment.