Skip to content

Commit

Permalink
attempt to switch playlist if songs fail to load
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Maguire committed Sep 26, 2024
1 parent 7d0a192 commit 0f5674a
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions commands/songguess.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ module.exports = {

let {playlists, isCustom} = await getPlaylistId(bot, context);

console.log(playlists, isCustom);

if(!playlists)
return context.sendLang({content: "SONGGUESS_UNKNOWN_INPUT"});

await context.defer();

playlist = bot.util.arrayRand(playlists.split(","));
playlists = playlists.split(",");
playlist = bot.util.arrayRand(playlists);
bot.logger.log(`Using spotify playlist: ${playlist}`);

if (bot.util.checkVoiceChannel(context)) return;
Expand All @@ -70,7 +69,7 @@ module.exports = {
return context.replyLang("SONGGUESS_ALREADY_RUNNING", {channel: module.exports.runningGames[context.guild.id].voiceChannel.name})
}

return startGame(bot, context, playlist, isCustom);
return startGame(bot, context, playlist, isCustom, playlists);
}

};
Expand Down Expand Up @@ -127,7 +126,7 @@ async function endGame(bot, id){
delete module.exports.runningGames[id];
}

async function startGame(bot, context, playlistId, custom){
async function startGame(bot, context, playlistId, custom, playlists){
if(!context.member.voice.channel) {
Sentry.captureMessage("Member has no voice channel when starting guess game");
return context.send("Couldn't start game, try again (voice channel does not exist)");
Expand All @@ -152,6 +151,7 @@ async function startGame(bot, context, playlistId, custom){
debug: context.getBool("songguess.debug"),
context,
playlistId,
playlists,
player,
custom,
failures: 0,
Expand Down Expand Up @@ -224,14 +224,10 @@ async function newGuess(bot, voiceChannel, retrying = false){
if (!retrying) {
counter = bot.util.intBetween(0, playlistLength);
return newGuess(bot, voiceChannel, true);
} else if(counter === 0){
Sentry.captureMessage("Failed to load song")
counter = 0;
endGame(bot, voiceChannel.guild.id);
return game.context.sendLang("SONGGUESS_TRACK_FAILED")
}else{
counter = 0;
song = playlist[0];
} else {
bot.logger.log("Switching playlists");
game.playlistId = bot.util.arrayRand(game.playlists);
return newGuess(bot, voiceChannel, false);
}
}

Expand Down

0 comments on commit 0f5674a

Please sign in to comment.