Skip to content

Commit eca2563

Browse files
authored
fix npe and an import (#1567)
* fix npe and an import * stop double posting * switched stacktrace to log, changed some logs
1 parent e6bfd18 commit eca2563

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.jagrosh.jmusicbot.settings.QueueType;
2121
import com.jagrosh.jmusicbot.utils.TimeUtil;
2222
import com.jagrosh.jmusicbot.settings.RepeatMode;
23-
import com.jagrosh.jmusicbot.utils.OtherUtil;
2423
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
2524
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
2625
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;

src/main/java/com/jagrosh/jmusicbot/commands/music/SeekCmd.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
1818
import com.jagrosh.jdautilities.command.CommandEvent;
1919
import com.jagrosh.jmusicbot.Bot;
2020
import com.jagrosh.jmusicbot.audio.AudioHandler;
21+
import com.jagrosh.jmusicbot.audio.RequestMetadata;
2122
import com.jagrosh.jmusicbot.commands.DJCommand;
2223
import com.jagrosh.jmusicbot.commands.MusicCommand;
2324
import com.jagrosh.jmusicbot.utils.TimeUtil;
2425
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2528

2629

2730
/**
2831
* @author Whew., Inc.
2932
*/
3033
public class SeekCmd extends MusicCommand
3134
{
35+
private final static Logger LOG = LoggerFactory.getLogger("Seeking");
36+
3237
public SeekCmd(Bot bot)
3338
{
3439
super(bot);
@@ -52,7 +57,7 @@ public void doCommand(CommandEvent event)
5257
}
5358

5459

55-
if (!DJCommand.checkDJPermission(event) && playingTrack.getUserData(Long.class) != event.getAuthor().getIdLong())
60+
if (!DJCommand.checkDJPermission(event) && playingTrack.getUserData(RequestMetadata.class).getOwner() != event.getAuthor().getIdLong())
5661
{
5762
event.replyError("You cannot seek **" + playingTrack.getInfo().title + "** because you didn't add it!");
5863
return;
@@ -73,19 +78,18 @@ public void doCommand(CommandEvent event)
7378
if (seekMilliseconds > trackDuration)
7479
{
7580
event.replyError("Cannot seek to `" + TimeUtil.formatTime(seekMilliseconds) + "` because the current track is `" + TimeUtil.formatTime(trackDuration) + "` long!");
81+
return;
82+
}
83+
84+
try
85+
{
86+
playingTrack.setPosition(seekMilliseconds);
7687
}
77-
else
88+
catch (Exception e)
7889
{
79-
try
80-
{
81-
playingTrack.setPosition(seekMilliseconds);
82-
}
83-
catch (Exception e)
84-
{
85-
event.replyError("An error occurred while trying to seek!");
86-
e.printStackTrace();
87-
return;
88-
}
90+
event.replyError("An error occurred while trying to seek: " + e.getMessage());
91+
LOG.warn("Failed to seek track " + playingTrack.getIdentifier(), e);
92+
return;
8993
}
9094
event.replySuccess("Successfully seeked to `" + TimeUtil.formatTime(playingTrack.getPosition()) + "/" + TimeUtil.formatTime(playingTrack.getDuration()) + "`!");
9195
}

src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.dv8tion.jda.api.entities.Guild;
2525
import org.json.JSONException;
2626
import org.json.JSONObject;
27+
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

2930
/**
@@ -32,6 +33,7 @@
3233
*/
3334
public class SettingsManager implements GuildSettingsManager<Settings>
3435
{
36+
private final static Logger LOG = LoggerFactory.getLogger("Settings");
3537
private final static String SETTINGS_FILE = "serversettings.json";
3638
private final HashMap<Long,Settings> settings;
3739

@@ -63,17 +65,17 @@ public SettingsManager()
6365
} catch (NoSuchFileException e) {
6466
// create an empty json file
6567
try {
66-
LoggerFactory.getLogger("Settings").info("serversettings.json will be created in " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
68+
LOG.info("serversettings.json will be created in " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
6769
Files.write(OtherUtil.getPath("serversettings.json"), new JSONObject().toString(4).getBytes());
6870
} catch(IOException ex) {
69-
LoggerFactory.getLogger("Settings").warn("Failed to create new settings file: "+ex);
71+
LOG.warn("Failed to create new settings file: "+ex);
7072
}
7173
return;
7274
} catch(IOException | JSONException e) {
73-
LoggerFactory.getLogger("Settings").warn("Failed to load server settings: "+e);
75+
LOG.warn("Failed to load server settings: "+e);
7476
}
7577

76-
LoggerFactory.getLogger("Settings").info("serversettings.json loaded from " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
78+
LOG.info("serversettings.json loaded from " + OtherUtil.getPath("serversettings.json").toAbsolutePath());
7779
}
7880

7981
/**
@@ -127,7 +129,7 @@ protected void writeSettings()
127129
try {
128130
Files.write(OtherUtil.getPath(SETTINGS_FILE), obj.toString(4).getBytes());
129131
} catch(IOException ex){
130-
LoggerFactory.getLogger("Settings").warn("Failed to write to file: "+ex);
132+
LOG.warn("Failed to write to file: "+ex);
131133
}
132134
}
133135
}

src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ public static String getUnsupportedBotReason(JDA jda)
224224
ApplicationInfo info = jda.retrieveApplicationInfo().complete();
225225
if (info.isBotPublic())
226226
return "\"Public Bot\" is enabled. Using JMusicBot as a public bot is not supported. Please disable it in the "
227-
+ "Developer Dashboard at https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot.";
227+
+ "Developer Dashboard at https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot ."
228+
+ "You may also need to disable all Installation Contexts at https://discord.com/developers/applications/"
229+
+ jda.getSelfUser().getId() + "/installation .";
228230

229231
return null;
230232
}

0 commit comments

Comments
 (0)