From 74d6ac33697789fe2c0a95b361f6cef2b013ea1a Mon Sep 17 00:00:00 2001 From: John Grosh Date: Thu, 1 Aug 2024 09:36:40 -0400 Subject: [PATCH] switched stacktrace to log, changed some logs --- .../jagrosh/jmusicbot/commands/music/SeekCmd.java | 8 ++++++-- .../jagrosh/jmusicbot/settings/SettingsManager.java | 12 +++++++----- .../java/com/jagrosh/jmusicbot/utils/OtherUtil.java | 4 +++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java index b882b6e29..6cf0f7958 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java @@ -23,6 +23,8 @@ import com.jagrosh.jmusicbot.commands.MusicCommand; import com.jagrosh.jmusicbot.utils.TimeUtil; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -30,6 +32,8 @@ */ public class SeekCmd extends MusicCommand { + private final static Logger LOG = LoggerFactory.getLogger("Seeking"); + public SeekCmd(Bot bot) { super(bot); @@ -83,8 +87,8 @@ public void doCommand(CommandEvent event) } catch (Exception e) { - event.replyError("An error occurred while trying to seek!"); - e.printStackTrace(); // TODO: remove this + event.replyError("An error occurred while trying to seek: " + e.getMessage()); + LOG.warn("Failed to seek track " + playingTrack.getIdentifier(), e); return; } event.replySuccess("Successfully seeked to `" + TimeUtil.formatTime(playingTrack.getPosition()) + "/" + TimeUtil.formatTime(playingTrack.getDuration()) + "`!"); diff --git a/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java b/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java index 72f744c0e..5971df08c 100644 --- a/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java +++ b/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java @@ -24,6 +24,7 @@ import net.dv8tion.jda.api.entities.Guild; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @@ -32,6 +33,7 @@ */ public class SettingsManager implements GuildSettingsManager { + private final static Logger LOG = LoggerFactory.getLogger("Settings"); private final static String SETTINGS_FILE = "serversettings.json"; private final HashMap settings; @@ -63,17 +65,17 @@ public SettingsManager() } catch (NoSuchFileException e) { // create an empty json file try { - LoggerFactory.getLogger("Settings").info("serversettings.json will be created in " + OtherUtil.getPath("serversettings.json").toAbsolutePath()); + LOG.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); + LOG.warn("Failed to create new settings file: "+ex); } return; } catch(IOException | JSONException e) { - LoggerFactory.getLogger("Settings").warn("Failed to load server settings: "+e); + LOG.warn("Failed to load server settings: "+e); } - LoggerFactory.getLogger("Settings").info("serversettings.json loaded from " + OtherUtil.getPath("serversettings.json").toAbsolutePath()); + LOG.info("serversettings.json loaded from " + OtherUtil.getPath("serversettings.json").toAbsolutePath()); } /** @@ -127,7 +129,7 @@ protected void writeSettings() try { Files.write(OtherUtil.getPath(SETTINGS_FILE), obj.toString(4).getBytes()); } catch(IOException ex){ - LoggerFactory.getLogger("Settings").warn("Failed to write to file: "+ex); + LOG.warn("Failed to write to file: "+ex); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java b/src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java index a22175d02..c0dd5b357 100644 --- a/src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java +++ b/src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java @@ -224,7 +224,9 @@ public static String getUnsupportedBotReason(JDA jda) ApplicationInfo info = jda.retrieveApplicationInfo().complete(); if (info.isBotPublic()) return "\"Public Bot\" is enabled. Using JMusicBot as a public bot is not supported. Please disable it in the " - + "Developer Dashboard at https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot."; + + "Developer Dashboard at https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot ." + + "You may also need to disable all Installation Contexts at https://discord.com/developers/applications/" + + jda.getSelfUser().getId() + "/installation ."; return null; }