From 2a148dd8a3680c4056187dd119302508bda8bfdb Mon Sep 17 00:00:00 2001 From: Dexter Gaon-Shatford Date: Tue, 7 Apr 2020 19:06:45 -0400 Subject: [PATCH] Fix repeat command crashing when queue is empty If the repeat command is invoked without this change, the bot will crash due to the call to format_song_string() on music which is null. All I did is add a check and make the bot say that the playlist is empty if this scenario occurs. --- command.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/command.py b/command.py index a263903..85917da 100644 --- a/command.py +++ b/command.py @@ -828,14 +828,17 @@ def cmd_repeat(bot, user, text, command, parameter): repeat = int(parameter) music = var.playlist.current_item() - for _ in range(repeat): - var.playlist.insert( - var.playlist.current_index + 1, - music - ) - log.info("bot: add to playlist: " + music.format_debug_string()) + if music: + for _ in range(repeat): + var.playlist.insert( + var.playlist.current_index + 1, + music + ) + log.info("bot: add to playlist: " + music.format_debug_string()) - bot.send_channel_msg(constants.strings("repeat", song=music.format_song_string(), n=str(repeat))) + bot.send_channel_msg(constants.strings("repeat", song=music.format_song_string(), n=str(repeat))) + else: + bot.send_channel_msg(constants.strings("queue_empty")) def cmd_mode(bot, user, text, command, parameter):