Skip to content

Commit

Permalink
Add track exception message throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
casko1 committed Dec 16, 2024
1 parent 44d9930 commit 6f24373
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TrackScheduler extends AudioEventAdapter {
public BlockingQueue<AudioTrack> queue;
private final Guild guild;
private boolean loop = false;
private long lastExceptionTimestamp = 0L;

public TrackScheduler(AudioPlayer player, Guild guild) {
this.player = player;
Expand Down Expand Up @@ -98,9 +99,14 @@ public boolean isLoop() {
@Override
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
logger.error("An error occurred while playing the track: {}", exception.toString());
PlayerManager playerManager = PlayerManager.getInstance();
TextChannel textChannel = playerManager.getTextChannel(guild);
textChannel.sendMessage("There was an error playing that track").queue();
long currentTime = System.currentTimeMillis();
// Throttle to 1 track exception message per 10 seconds in case of a broken playlist
if (currentTime - lastExceptionTimestamp > 10000L) {
lastExceptionTimestamp = currentTime;
PlayerManager playerManager = PlayerManager.getInstance();
TextChannel textChannel = playerManager.getTextChannel(guild);
textChannel.sendMessage("There was an error playing that track").queue();
}
}

public void nextTrack() {
Expand Down

0 comments on commit 6f24373

Please sign in to comment.