feat: three playback mode "one-shot", "loop", "random"

fix: bugs when you are on the last item and you want
remove it.

Some tips for testing:
Observe the behavior when you are playing the last
item and you remove the last item, for all three modes.
This commit is contained in:
Terry Geng
2020-02-26 22:09:53 +08:00
parent 388016a5af
commit 6a1320f8f9
5 changed files with 97 additions and 37 deletions

View File

@ -47,6 +47,7 @@ def register_all_commands(bot):
bot.register_command(constants.commands('list_file'), cmd_list_file)
bot.register_command(constants.commands('queue'), cmd_queue)
bot.register_command(constants.commands('random'), cmd_random)
bot.register_command(constants.commands('mode'), cmd_mode)
bot.register_command(constants.commands('drop_database'), cmd_drop_database)
def send_multi_lines(bot, lines, text):
@ -533,9 +534,17 @@ def cmd_remove(bot, user, text, command, parameter):
removed = None
if index == var.playlist.current_index:
removed = var.playlist.remove(index)
if bot.is_playing and not bot.is_pause:
bot.stop()
bot.launch_music(index)
if index < len(var.playlist):
if not bot.is_pause:
bot.kill_ffmpeg()
var.playlist.current_index -= 1
# then the bot will move to next item
else: # if item deleted is the last item of the queue
var.playlist.current_index -= 1
if not bot.is_pause:
bot.kill_ffmpeg()
else:
removed = var.playlist.remove(index)
@ -593,12 +602,25 @@ def cmd_queue(bot, user, text, command, parameter):
send_multi_lines(bot, msgs, text)
def cmd_random(bot, user, text, command, parameter):
bot.stop()
var.playlist.randomize()
bot.launch_music(0)
def cmd_mode(bot, user, text, command, parameter):
if not parameter:
bot.send_msg(constants.strings("current_mode", mode=var.playlist.mode), text)
return
if not parameter in ["one-shot", "loop", "random"]:
bot.send_msg(constants.strings('unknown_mode', mode=parameter), text)
else:
var.playlist.set_mode(parameter)
if parameter == "random":
bot.stop()
var.playlist.randomize()
bot.launch_music(0)
def cmd_drop_database(bot, user, text, command, parameter):
var.db.drop_table()
var.db = Database(var.dbfile)